feat(angular): add routing option to CNW (#14845)

This commit is contained in:
Colum Ferry 2023-02-10 18:24:48 +00:00 committed by GitHub
parent 005eb5687b
commit abece6a02d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 111 additions and 2 deletions

View File

@ -125,6 +125,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 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: `string`
Add a routing setup when a preset with pregenerated app is selected
### skipGit ### skipGit
Type: `boolean` Type: `boolean`

View File

@ -125,6 +125,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 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: `string`
Add a routing setup when a preset with pregenerated app is selected
### skipGit ### skipGit
Type: `boolean` Type: `boolean`

View File

@ -20,6 +20,11 @@
"type": "string", "type": "string",
"default": "css" "default": "css"
}, },
"routing": {
"description": "Add routing to the generated application.",
"type": "boolean",
"default": true
},
"npmScope": { "npmScope": {
"type": "string", "type": "string",
"description": "Npm scope for importing libs." "description": "Npm scope for importing libs."

View File

@ -24,6 +24,11 @@
"enum": ["eslint"], "enum": ["eslint"],
"default": "eslint" "default": "eslint"
}, },
"routing": {
"description": "Add routing to the generated application.",
"type": "boolean",
"default": true
},
"style": { "style": {
"description": "The file extension to be used for style files.", "description": "The file extension to be used for style files.",
"type": "string", "type": "string",

View File

@ -138,6 +138,7 @@ export function runCreateWorkspace(
useDetectedPm = false, useDetectedPm = false,
cwd = e2eCwd, cwd = e2eCwd,
bundler, bundler,
routing,
}: { }: {
preset: string; preset: string;
appName?: string; appName?: string;
@ -149,6 +150,7 @@ export function runCreateWorkspace(
useDetectedPm?: boolean; useDetectedPm?: boolean;
cwd?: string; cwd?: string;
bundler?: 'webpack' | 'vite'; bundler?: 'webpack' | 'vite';
routing?: boolean;
} }
) { ) {
projName = name; projName = name;
@ -170,6 +172,10 @@ export function runCreateWorkspace(
command += ` --bundler=${bundler}`; command += ` --bundler=${bundler}`;
} }
if (routing !== undefined) {
command += ` --routing=${routing}`;
}
if (base) { if (base) {
command += ` --defaultBase="${base}"`; command += ` --defaultBase="${base}"`;
} }

View File

@ -18,7 +18,7 @@ describe('create-nx-workspace', () => {
afterEach(() => cleanupProject()); afterEach(() => cleanupProject());
it('should create a workspace with a single angular app at the root', () => { it('should create a workspace with a single angular app at the root with routing', () => {
const wsName = uniq('angular'); const wsName = uniq('angular');
runCreateWorkspace(wsName, { runCreateWorkspace(wsName, {
@ -26,6 +26,23 @@ describe('create-nx-workspace', () => {
appName: wsName, appName: wsName,
style: 'css', style: 'css',
packageManager, packageManager,
routing: true,
});
checkFilesExist('package.json');
checkFilesExist('src/app/app.routes.ts');
checkFilesExist('project.json');
});
it('should create a workspace with a single angular app at the root without routing', () => {
const wsName = uniq('angular');
runCreateWorkspace(wsName, {
preset: 'angular-standalone',
appName: wsName,
style: 'css',
packageManager,
routing: false,
}); });
checkFilesExist('package.json'); checkFilesExist('package.json');
@ -112,6 +129,7 @@ describe('create-nx-workspace', () => {
style: 'css', style: 'css',
appName, appName,
packageManager, packageManager,
routing: true,
}); });
}); });
@ -127,6 +145,7 @@ describe('create-nx-workspace', () => {
style: 'css', style: 'css',
appName, appName,
packageManager, packageManager,
routing: true,
}); });
} catch (e) { } catch (e) {
expect(e).toBeTruthy(); expect(e).toBeTruthy();
@ -293,6 +312,7 @@ describe('create-nx-workspace', () => {
appName, appName,
style: 'css', style: 'css',
packageManager: 'npm', packageManager: 'npm',
routing: true,
}); });
checkFilesDoNotExist('yarn.lock'); checkFilesDoNotExist('yarn.lock');

View File

@ -33,6 +33,7 @@ type Arguments = {
framework: string; framework: string;
docker: boolean; docker: boolean;
nxCloud: boolean; nxCloud: boolean;
routing: string;
allPrompts: boolean; allPrompts: boolean;
packageManager: PackageManager; packageManager: PackageManager;
defaultBase: string; defaultBase: string;
@ -143,6 +144,10 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
describe: chalk.dim`Style option to be used when a preset with pregenerated app is selected`, describe: chalk.dim`Style option to be used when a preset with pregenerated app is selected`,
type: 'string', type: 'string',
}) })
.option('routing', {
describe: chalk.dim`Add a routing setup when a preset with pregenerated app is selected`,
type: 'string',
})
.option('bundler', { .option('bundler', {
describe: chalk.dim`Bundler to be used to build the application`, describe: chalk.dim`Bundler to be used to build the application`,
type: 'string', type: 'string',
@ -227,6 +232,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset, preset,
appName, appName,
style, style,
routing,
nxCloud, nxCloud,
packageManager, packageManager,
defaultBase, defaultBase,
@ -257,6 +263,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset, preset,
appName, appName,
style, style,
routing,
nxCloud, nxCloud,
defaultBase, defaultBase,
framework, framework,
@ -314,7 +321,7 @@ async function getConfiguration(
argv: yargs.Arguments<Arguments> argv: yargs.Arguments<Arguments>
): Promise<void> { ): Promise<void> {
try { try {
let name, appName, style, preset, framework, bundler, docker; let name, appName, style, preset, framework, bundler, docker, routing;
output.log({ output.log({
title: title:
@ -366,12 +373,20 @@ async function getConfiguration(
if (preset === Preset.ReactStandalone) { if (preset === Preset.ReactStandalone) {
bundler = await determineBundler(argv); bundler = await determineBundler(argv);
} }
if (preset === Preset.AngularStandalone) {
routing = await determineRouting(argv);
}
} else { } else {
name = await determineRepoName(argv); name = await determineRepoName(argv);
appName = await determineAppName(preset, argv); appName = await determineAppName(preset, argv);
if (preset === Preset.ReactMonorepo) { if (preset === Preset.ReactMonorepo) {
bundler = await determineBundler(argv); bundler = await determineBundler(argv);
} }
if (preset === Preset.AngularMonorepo) {
routing = await determineRouting(argv);
}
} }
style = await determineStyle(preset, argv); style = await determineStyle(preset, argv);
} }
@ -386,6 +401,7 @@ async function getConfiguration(
preset, preset,
appName, appName,
style, style,
routing,
framework, framework,
nxCloud, nxCloud,
packageManager, packageManager,
@ -855,6 +871,36 @@ async function determineStyle(
return Promise.resolve(parsedArgs.style); return Promise.resolve(parsedArgs.style);
} }
async function determineRouting(
parsedArgs: yargs.Arguments<Arguments>
): Promise<string> {
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' ? 'true' : 'false'
);
}
return parsedArgs.routing;
}
async function determineBundler( async function determineBundler(
parsedArgs: yargs.Arguments<Arguments> parsedArgs: yargs.Arguments<Arguments>
): Promise<'vite' | 'webpack'> { ): Promise<'vite' | 'webpack'> {

View File

@ -78,6 +78,7 @@ export function generatePreset(host: Tree, opts: NormalizedSchema) {
opts.docker ? `--docker=${opts.docker}` : null, opts.docker ? `--docker=${opts.docker}` : null,
opts.packageManager ? `--packageManager=${opts.packageManager}` : null, opts.packageManager ? `--packageManager=${opts.packageManager}` : null,
parsedArgs.interactive ? '--interactive=true' : '--interactive=false', parsedArgs.interactive ? '--interactive=true' : '--interactive=false',
opts.routing !== undefined ? `--routing=${opts.routing}` : null,
].filter((e) => !!e); ].filter((e) => !!e);
} }
} }

View File

@ -27,6 +27,7 @@ interface Schema {
docker?: boolean; docker?: boolean;
linter?: Linter; linter?: Linter;
bundler?: 'vite' | 'webpack'; bundler?: 'vite' | 'webpack';
routing?: boolean;
packageManager?: PackageManager; packageManager?: PackageManager;
} }

View File

@ -20,6 +20,11 @@
"type": "string", "type": "string",
"default": "css" "default": "css"
}, },
"routing": {
"description": "Add routing to the generated application.",
"type": "boolean",
"default": true
},
"npmScope": { "npmScope": {
"type": "string", "type": "string",
"description": "Npm scope for importing libs." "description": "Npm scope for importing libs."

View File

@ -32,6 +32,7 @@ async function createPreset(tree: Tree, options: Schema) {
name: options.name, name: options.name,
style: options.style, style: options.style,
linter: options.linter, linter: options.linter,
routing: options.routing,
}); });
} else if (options.preset === Preset.AngularStandalone) { } else if (options.preset === Preset.AngularStandalone) {
const { const {
@ -42,6 +43,7 @@ async function createPreset(tree: Tree, options: Schema) {
name: options.name, name: options.name,
style: options.style, style: options.style,
linter: options.linter, linter: options.linter,
routing: options.routing,
rootProject: true, rootProject: true,
}); });
} else if (options.preset === Preset.ReactMonorepo) { } else if (options.preset === Preset.ReactMonorepo) {

View File

@ -12,4 +12,5 @@ export interface Schema {
packageManager?: PackageManager; packageManager?: PackageManager;
bundler?: 'vite' | 'webpack'; bundler?: 'vite' | 'webpack';
docker?: boolean; docker?: boolean;
routing?: boolean;
} }

View File

@ -24,6 +24,11 @@
"enum": ["eslint"], "enum": ["eslint"],
"default": "eslint" "default": "eslint"
}, },
"routing": {
"description": "Add routing to the generated application.",
"type": "boolean",
"default": true
},
"style": { "style": {
"description": "The file extension to be used for style files.", "description": "The file extension to be used for style files.",
"type": "string", "type": "string",