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

View File

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

View File

@ -24,6 +24,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",

View File

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

View File

@ -18,7 +18,7 @@ describe('create-nx-workspace', () => {
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');
runCreateWorkspace(wsName, {
@ -26,6 +26,23 @@ describe('create-nx-workspace', () => {
appName: wsName,
style: 'css',
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');
@ -112,6 +129,7 @@ describe('create-nx-workspace', () => {
style: 'css',
appName,
packageManager,
routing: true,
});
});
@ -127,6 +145,7 @@ describe('create-nx-workspace', () => {
style: 'css',
appName,
packageManager,
routing: true,
});
} catch (e) {
expect(e).toBeTruthy();
@ -293,6 +312,7 @@ describe('create-nx-workspace', () => {
appName,
style: 'css',
packageManager: 'npm',
routing: true,
});
checkFilesDoNotExist('yarn.lock');

View File

@ -33,6 +33,7 @@ type Arguments = {
framework: string;
docker: boolean;
nxCloud: boolean;
routing: string;
allPrompts: boolean;
packageManager: PackageManager;
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`,
type: 'string',
})
.option('routing', {
describe: chalk.dim`Add a routing setup when a preset with pregenerated app is selected`,
type: 'string',
})
.option('bundler', {
describe: chalk.dim`Bundler to be used to build the application`,
type: 'string',
@ -227,6 +232,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset,
appName,
style,
routing,
nxCloud,
packageManager,
defaultBase,
@ -257,6 +263,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset,
appName,
style,
routing,
nxCloud,
defaultBase,
framework,
@ -314,7 +321,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:
@ -366,12 +373,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);
}
@ -386,6 +401,7 @@ async function getConfiguration(
preset,
appName,
style,
routing,
framework,
nxCloud,
packageManager,
@ -855,6 +871,36 @@ async function determineStyle(
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(
parsedArgs: yargs.Arguments<Arguments>
): Promise<'vite' | 'webpack'> {

View File

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

View File

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

View File

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

View File

@ -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 {
@ -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) {

View File

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

View File

@ -24,6 +24,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",