Skip to content

Commit

Permalink
feat(core): add standalone api prompt to CNW
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Feb 9, 2023
1 parent 4d21915 commit d30658a
Show file tree
Hide file tree
Showing 9 changed files with 80 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 @@ -141,6 +141,12 @@ Default: `false`

Skip initializing a git repository.

### standaloneApi

Type: `boolean`

Use Standalone APIs if generating an Angular app

### style

Type: `string`
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 @@ -141,6 +141,12 @@ Default: `false`

Skip initializing a git repository.

### standaloneApi

Type: `boolean`

Use Standalone APIs if generating an Angular app

### style

Type: `string`
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 @@ -49,6 +49,11 @@
]
}
},
"standaloneApi": {
"description": "Use the Standalone APIs if generating an Angular application.",
"type": "boolean",
"default": "false"
},
"standaloneConfig": {
"description": "Split the project configurations into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean",
Expand Down
6 changes: 6 additions & 0 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function runCreateWorkspace(
useDetectedPm = false,
cwd = e2eCwd,
bundler,
standaloneApi,
}: {
preset: string;
appName?: string;
Expand All @@ -155,6 +156,7 @@ export function runCreateWorkspace(
useDetectedPm?: boolean;
cwd?: string;
bundler?: 'webpack' | 'vite';
standaloneApi?: boolean;
}
) {
projName = name;
Expand All @@ -178,6 +180,10 @@ export function runCreateWorkspace(
command += ` --bundler=${bundler}`;
}

if (standaloneApi !== undefined) {
command += ` --standaloneApi=${standaloneApi}`;
}

if (base) {
command += ` --defaultBase="${base}"`;
}
Expand Down
4 changes: 4 additions & 0 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('create-nx-workspace', () => {
appName: wsName,
style: 'css',
packageManager,
standaloneApi: false,
});

checkFilesExist('package.json');
Expand Down Expand Up @@ -112,6 +113,7 @@ describe('create-nx-workspace', () => {
style: 'css',
appName,
packageManager,
standaloneApi: false,
});
});

Expand All @@ -127,6 +129,7 @@ describe('create-nx-workspace', () => {
style: 'css',
appName,
packageManager,
standaloneApi: false,
});
} catch (e) {
expect(e).toBeTruthy();
Expand Down Expand Up @@ -294,6 +297,7 @@ describe('create-nx-workspace', () => {
style: 'css',
packageManager: 'npm',
cli: 'angular',
standaloneApi: false,
});

checkFilesDoNotExist('yarn.lock');
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 @@ -32,6 +32,7 @@ type Arguments = {
cli: string;
style: string;
framework: string;
standaloneApi: boolean;
docker: boolean;
nxCloud: boolean;
allPrompts: boolean;
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('standaloneApi', {
describe: chalk.dim`Use Standalone APIs if generating an Angular app`,
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,
standaloneApi,
nxCloud,
packageManager,
defaultBase,
Expand Down Expand Up @@ -265,6 +271,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset,
appName,
style,
standaloneApi,
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, standaloneApi;

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) {
standaloneApi = await determineStandaloneApi(argv);
}
} else {
name = await determineRepoName(argv);
appName = await determineAppName(preset, argv);
if (preset === Preset.ReactMonorepo) {
bundler = await determineBundler(argv);
}

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

async function determineStandaloneApi(
parsedArgs: yargs.Arguments<Arguments>
): Promise<boolean> {
if (parsedArgs.standaloneApi === undefined) {
return enquirer
.prompt([
{
name: 'standaloneApi',
message: 'Would you like to use Standalone APIs in your application?',
type: 'autocomplete',
choices: [
{
name: 'Yes',
},

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

return parsedArgs.standaloneApi;
}

async function determineDockerfile(
parsedArgs: yargs.Arguments<Arguments>
): Promise<boolean> {
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,
standalone: options.standaloneApi,
});
} else if (options.preset === Preset.AngularStandalone) {
const {
Expand All @@ -43,6 +44,7 @@ async function createPreset(tree: Tree, options: Schema) {
style: options.style,
linter: options.linter,
rootProject: true,
standalone: options.standaloneApi,
});
} else if (options.preset === Preset.ReactMonorepo) {
const {
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;
standaloneApi?: 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 @@ -55,6 +55,11 @@
]
}
},
"standaloneApi": {
"description": "Use the Standalone APIs if generating an Angular application.",
"type": "boolean",
"default": "false"
},
"standaloneConfig": {
"description": "Split the project configurations into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean",
Expand Down

0 comments on commit d30658a

Please sign in to comment.