Skip to content

Commit

Permalink
feat(angular): add routing option to CNW
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Feb 7, 2023
1 parent 8d87654 commit 54c775a
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/generated/cli/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ Type: `string`

Customizes the initial content of your workspace. Default presets include: ["apps", "empty", "core", "npm", "ts", "web-components", "angular-monorepo", "angular-standalone", "react-monorepo", "react-standalone", "react-native", "expo", "next", "nest", "express", "react", "angular", "node-server"]. To build your own see https://nx.dev/packages/nx-plugin#preset

### routing

Type: `boolean`

Add a routing setup when a preset with pregenerated app is selected

### skipGit

Type: `boolean`
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/nx/documents/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ Type: `string`

Customizes the initial content of your workspace. Default presets include: ["apps", "empty", "core", "npm", "ts", "web-components", "angular-monorepo", "angular-standalone", "react-monorepo", "react-standalone", "react-native", "expo", "next", "nest", "express", "react", "angular", "node-server"]. To build your own see https://nx.dev/packages/nx-plugin#preset

### routing

Type: `boolean`

Add a routing setup when a preset with pregenerated app is selected

### skipGit

Type: `boolean`
Expand Down
5 changes: 5 additions & 0 deletions docs/generated/packages/workspace/generators/preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"enum": ["eslint"],
"default": "eslint"
},
"routing": {
"description": "Add routing to the generated application.",
"type": "boolean",
"default": true
},
"style": {
"description": "The file extension to be used for style files.",
"type": "string",
Expand Down
46 changes: 45 additions & 1 deletion packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Arguments = {
framework: string;
docker: boolean;
nxCloud: boolean;
routing: boolean;
allPrompts: boolean;
packageManager: PackageManager;
defaultBase: string;
Expand Down Expand Up @@ -149,6 +150,10 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
describe: chalk.dim`Style option to be used when a preset with pregenerated app is selected`,
type: 'string',
})
.option('routing', {
describe: chalk.dim`Add a routing setup when a preset with pregenerated app is selected`,
type: 'boolean',
})
.option('bundler', {
describe: chalk.dim`Bundler to be used to build the application`,
type: 'string',
Expand Down Expand Up @@ -234,6 +239,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset,
appName,
style,
routing,
nxCloud,
packageManager,
defaultBase,
Expand Down Expand Up @@ -265,6 +271,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset,
appName,
style,
routing,
nxCloud,
defaultBase,
framework,
Expand Down Expand Up @@ -322,7 +329,7 @@ async function getConfiguration(
argv: yargs.Arguments<Arguments>
): Promise<void> {
try {
let name, appName, style, preset, framework, bundler, docker;
let name, appName, style, preset, framework, bundler, docker, routing;

output.log({
title:
Expand Down Expand Up @@ -374,12 +381,20 @@ async function getConfiguration(
if (preset === Preset.ReactStandalone) {
bundler = await determineBundler(argv);
}

if (preset === Preset.AngularStandalone) {
routing = await determineRouting(argv);
}
} else {
name = await determineRepoName(argv);
appName = await determineAppName(preset, argv);
if (preset === Preset.ReactMonorepo) {
bundler = await determineBundler(argv);
}

if (preset === Preset.AngularMonorepo) {
routing = await determineRouting(argv);
}
}
style = await determineStyle(preset, argv);
}
Expand All @@ -395,6 +410,7 @@ async function getConfiguration(
preset,
appName,
style,
routing,
framework,
cli,
nxCloud,
Expand Down Expand Up @@ -894,6 +910,34 @@ async function determineStyle(
return Promise.resolve(parsedArgs.style);
}

async function determineRouting(
parsedArgs: yargs.Arguments<Arguments>
): Promise<boolean> {
if (!parsedArgs.routing) {
return enquirer
.prompt([
{
name: 'routing',
message: 'Would you like to add routing?',
type: 'autocomplete',
choices: [
{
name: 'Yes',
},

{
name: 'No',
},
],
initial: 'Yes' as any,
},
])
.then((a: { routing: 'Yes' | 'No' }) => a.routing === 'Yes');
}

return parsedArgs.routing;
}

async function determineBundler(
parsedArgs: yargs.Arguments<Arguments>
): Promise<'vite' | 'webpack'> {
Expand Down
2 changes: 2 additions & 0 deletions packages/workspace/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function createPreset(tree: Tree, options: Schema) {
name: options.name,
style: options.style,
linter: options.linter,
routing: options.routing,
});
} else if (options.preset === Preset.AngularStandalone) {
const {
Expand All @@ -42,6 +43,7 @@ async function createPreset(tree: Tree, options: Schema) {
name: options.name,
style: options.style,
linter: options.linter,
routing: options.routing,
rootProject: true,
});
} else if (options.preset === Preset.ReactMonorepo) {
Expand Down
1 change: 1 addition & 0 deletions packages/workspace/src/generators/preset/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface Schema {
packageManager?: PackageManager;
bundler?: 'vite' | 'webpack';
docker?: boolean;
routing?: boolean;
}
5 changes: 5 additions & 0 deletions packages/workspace/src/generators/preset/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"enum": ["eslint"],
"default": "eslint"
},
"routing": {
"description": "Add routing to the generated application.",
"type": "boolean",
"default": true
},
"style": {
"description": "The file extension to be used for style files.",
"type": "string",
Expand Down

0 comments on commit 54c775a

Please sign in to comment.