feat(core): add standalone api prompt to CNW (#14886)

This commit is contained in:
Colum Ferry 2023-02-10 20:06:41 +00:00 committed by GitHub
parent abece6a02d
commit 4f09949383
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 116 additions and 1 deletions

View File

@ -139,6 +139,12 @@ Default: `false`
Skip initializing a git repository. Skip initializing a git repository.
### standaloneApi
Type: `string`
Use Standalone Components if generating an Angular app
### style ### style
Type: `string` Type: `string`

View File

@ -139,6 +139,12 @@ Default: `false`
Skip initializing a git repository. Skip initializing a git repository.
### standaloneApi
Type: `string`
Use Standalone Components if generating an Angular app
### style ### style
Type: `string` Type: `string`

View File

@ -29,6 +29,11 @@
"type": "string", "type": "string",
"description": "Npm scope for importing libs." "description": "Npm scope for importing libs."
}, },
"standaloneApi": {
"description": "Use the Standalone APIs if generating an Angular application.",
"type": "boolean",
"default": false
},
"defaultBase": { "defaultBase": {
"type": "string", "type": "string",
"description": "Default base branch for affected." "description": "Default base branch for affected."

View File

@ -53,6 +53,11 @@
] ]
} }
}, },
"standaloneApi": {
"description": "Use the Standalone APIs if generating an Angular application.",
"type": "boolean",
"default": false
},
"standaloneConfig": { "standaloneConfig": {
"description": "Split the project configurations into `<projectRoot>/project.json` rather than including it inside `workspace.json`.", "description": "Split the project configurations into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean", "type": "boolean",

View File

@ -139,6 +139,7 @@ export function runCreateWorkspace(
cwd = e2eCwd, cwd = e2eCwd,
bundler, bundler,
routing, routing,
standaloneApi,
}: { }: {
preset: string; preset: string;
appName?: string; appName?: string;
@ -150,6 +151,7 @@ export function runCreateWorkspace(
useDetectedPm?: boolean; useDetectedPm?: boolean;
cwd?: string; cwd?: string;
bundler?: 'webpack' | 'vite'; bundler?: 'webpack' | 'vite';
standaloneApi?: boolean;
routing?: boolean; routing?: boolean;
} }
) { ) {
@ -172,6 +174,10 @@ export function runCreateWorkspace(
command += ` --bundler=${bundler}`; command += ` --bundler=${bundler}`;
} }
if (standaloneApi !== undefined) {
command += ` --standaloneApi=${standaloneApi}`;
}
if (routing !== undefined) { if (routing !== undefined) {
command += ` --routing=${routing}`; command += ` --routing=${routing}`;
} }

View File

@ -42,11 +42,29 @@ describe('create-nx-workspace', () => {
appName: wsName, appName: wsName,
style: 'css', style: 'css',
packageManager, packageManager,
standaloneApi: false,
routing: false, routing: false,
}); });
checkFilesExist('package.json'); checkFilesExist('package.json');
checkFilesExist('project.json'); checkFilesExist('project.json');
checkFilesExist('src/app/app.module.ts');
});
it('should create a workspace with a single angular app at the root using standalone APIs', () => {
const wsName = uniq('angular');
runCreateWorkspace(wsName, {
preset: 'angular-standalone',
appName: wsName,
style: 'css',
packageManager,
standaloneApi: true,
});
checkFilesExist('package.json');
checkFilesExist('project.json');
checkFilesDoNotExist('src/app/app.module.ts');
}); });
it('should create a workspace with a single react app with vite at the root', () => { it('should create a workspace with a single react app with vite at the root', () => {
@ -129,6 +147,7 @@ describe('create-nx-workspace', () => {
style: 'css', style: 'css',
appName, appName,
packageManager, packageManager,
standaloneApi: false,
routing: true, routing: true,
}); });
}); });
@ -145,6 +164,7 @@ describe('create-nx-workspace', () => {
style: 'css', style: 'css',
appName, appName,
packageManager, packageManager,
standaloneApi: false,
routing: true, routing: true,
}); });
} catch (e) { } catch (e) {
@ -313,6 +333,7 @@ describe('create-nx-workspace', () => {
style: 'css', style: 'css',
packageManager: 'npm', packageManager: 'npm',
routing: true, routing: true,
standaloneApi: false,
}); });
checkFilesDoNotExist('yarn.lock'); checkFilesDoNotExist('yarn.lock');

View File

@ -31,6 +31,7 @@ type Arguments = {
appName: string; appName: string;
style: string; style: string;
framework: string; framework: string;
standaloneApi: string;
docker: boolean; docker: boolean;
nxCloud: boolean; nxCloud: boolean;
routing: string; routing: string;
@ -144,6 +145,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('standaloneApi', {
describe: chalk.dim`Use Standalone Components if generating an Angular app`,
type: 'string',
})
.option('routing', { .option('routing', {
describe: chalk.dim`Add a routing setup when a preset with pregenerated app is selected`, describe: chalk.dim`Add a routing setup when a preset with pregenerated app is selected`,
type: 'string', type: 'string',
@ -232,6 +237,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset, preset,
appName, appName,
style, style,
standaloneApi,
routing, routing,
nxCloud, nxCloud,
packageManager, packageManager,
@ -264,6 +270,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
appName, appName,
style, style,
routing, routing,
standaloneApi,
nxCloud, nxCloud,
defaultBase, defaultBase,
framework, framework,
@ -321,7 +328,15 @@ 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, routing; let name,
appName,
style,
preset,
framework,
bundler,
docker,
routing,
standaloneApi;
output.log({ output.log({
title: title:
@ -375,6 +390,7 @@ async function getConfiguration(
} }
if (preset === Preset.AngularStandalone) { if (preset === Preset.AngularStandalone) {
standaloneApi = await determineStandaloneApi(argv);
routing = await determineRouting(argv); routing = await determineRouting(argv);
} }
} else { } else {
@ -385,6 +401,7 @@ async function getConfiguration(
} }
if (preset === Preset.AngularMonorepo) { if (preset === Preset.AngularMonorepo) {
standaloneApi = await determineStandaloneApi(argv);
routing = await determineRouting(argv); routing = await determineRouting(argv);
} }
} }
@ -401,6 +418,7 @@ async function getConfiguration(
preset, preset,
appName, appName,
style, style,
standaloneApi,
routing, routing,
framework, framework,
nxCloud, nxCloud,
@ -745,6 +763,37 @@ async function determineFramework(
return Promise.resolve(parsedArgs.framework); return Promise.resolve(parsedArgs.framework);
} }
async function determineStandaloneApi(
parsedArgs: yargs.Arguments<Arguments>
): Promise<string> {
if (parsedArgs.standaloneApi === undefined) {
return enquirer
.prompt([
{
name: 'standaloneApi',
message:
'Would you like to use Standalone Components in your application?',
type: 'autocomplete',
choices: [
{
name: 'Yes',
},
{
name: 'No',
},
],
initial: 'No' as any,
},
])
.then((a: { standaloneApi: 'Yes' | 'No' }) =>
a.standaloneApi === 'Yes' ? 'true' : 'false'
);
}
return parsedArgs.standaloneApi;
}
async function determineDockerfile( async function determineDockerfile(
parsedArgs: yargs.Arguments<Arguments> parsedArgs: yargs.Arguments<Arguments>
): Promise<boolean> { ): Promise<boolean> {

View File

@ -77,6 +77,9 @@ export function generatePreset(host: Tree, opts: NormalizedSchema) {
opts.framework ? `--framework=${opts.framework}` : null, opts.framework ? `--framework=${opts.framework}` : null,
opts.docker ? `--docker=${opts.docker}` : null, opts.docker ? `--docker=${opts.docker}` : null,
opts.packageManager ? `--packageManager=${opts.packageManager}` : null, opts.packageManager ? `--packageManager=${opts.packageManager}` : null,
opts.standaloneApi !== undefined
? `--standaloneApi=${opts.standaloneApi}`
: null,
parsedArgs.interactive ? '--interactive=true' : '--interactive=false', parsedArgs.interactive ? '--interactive=true' : '--interactive=false',
opts.routing !== undefined ? `--routing=${opts.routing}` : null, 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';
standaloneApi?: boolean;
routing?: boolean; routing?: boolean;
packageManager?: PackageManager; packageManager?: PackageManager;
} }

View File

@ -29,6 +29,11 @@
"type": "string", "type": "string",
"description": "Npm scope for importing libs." "description": "Npm scope for importing libs."
}, },
"standaloneApi": {
"description": "Use the Standalone APIs if generating an Angular application.",
"type": "boolean",
"default": false
},
"defaultBase": { "defaultBase": {
"type": "string", "type": "string",
"description": "Default base branch for affected." "description": "Default base branch for affected."

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,
standalone: options.standaloneApi,
routing: options.routing, routing: options.routing,
}); });
} else if (options.preset === Preset.AngularStandalone) { } else if (options.preset === Preset.AngularStandalone) {
@ -45,6 +46,7 @@ async function createPreset(tree: Tree, options: Schema) {
linter: options.linter, linter: options.linter,
routing: options.routing, routing: options.routing,
rootProject: true, rootProject: true,
standalone: options.standaloneApi,
}); });
} else if (options.preset === Preset.ReactMonorepo) { } else if (options.preset === Preset.ReactMonorepo) {
const { const {

View File

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

View File

@ -56,6 +56,11 @@
] ]
} }
}, },
"standaloneApi": {
"description": "Use the Standalone APIs if generating an Angular application.",
"type": "boolean",
"default": false
},
"standaloneConfig": { "standaloneConfig": {
"description": "Split the project configurations into `<projectRoot>/project.json` rather than including it inside `workspace.json`.", "description": "Split the project configurations into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean", "type": "boolean",