Skip to content

Commit

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

Skip initializing a git repository.

### standaloneApi

Type: `string`

Use Standalone Components 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 @@ -139,6 +139,12 @@ Default: `false`

Skip initializing a git repository.

### standaloneApi

Type: `string`

Use Standalone Components if generating an Angular app

### style

Type: `string`
Expand Down
5 changes: 5 additions & 0 deletions docs/generated/packages/workspace/generators/new.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"type": "string",
"description": "Npm scope for importing libs."
},
"standaloneApi": {
"description": "Use the Standalone APIs if generating an Angular application.",
"type": "boolean",
"default": false
},
"defaultBase": {
"type": "string",
"description": "Default base branch for affected."
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 @@ -53,6 +53,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 @@ -139,6 +139,7 @@ export function runCreateWorkspace(
cwd = e2eCwd,
bundler,
routing,
standaloneApi,
}: {
preset: string;
appName?: string;
Expand All @@ -150,6 +151,7 @@ export function runCreateWorkspace(
useDetectedPm?: boolean;
cwd?: string;
bundler?: 'webpack' | 'vite';
standaloneApi?: boolean;
routing?: boolean;
}
) {
Expand All @@ -172,6 +174,10 @@ export function runCreateWorkspace(
command += ` --bundler=${bundler}`;
}

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

if (routing !== undefined) {
command += ` --routing=${routing}`;
}
Expand Down
21 changes: 21 additions & 0 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,29 @@ describe('create-nx-workspace', () => {
appName: wsName,
style: 'css',
packageManager,
standaloneApi: false,
routing: false,
});

checkFilesExist('package.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', () => {
Expand Down Expand Up @@ -129,6 +147,7 @@ describe('create-nx-workspace', () => {
style: 'css',
appName,
packageManager,
standaloneApi: false,
routing: true,
});
});
Expand All @@ -145,6 +164,7 @@ describe('create-nx-workspace', () => {
style: 'css',
appName,
packageManager,
standaloneApi: false,
routing: true,
});
} catch (e) {
Expand Down Expand Up @@ -313,6 +333,7 @@ describe('create-nx-workspace', () => {
style: 'css',
packageManager: 'npm',
routing: true,
standaloneApi: false,
});

checkFilesDoNotExist('yarn.lock');
Expand Down
51 changes: 50 additions & 1 deletion packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Arguments = {
appName: string;
style: string;
framework: string;
standaloneApi: string;
docker: boolean;
nxCloud: boolean;
routing: string;
Expand Down Expand Up @@ -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`,
type: 'string',
})
.option('standaloneApi', {
describe: chalk.dim`Use Standalone Components if generating an Angular app`,
type: 'string',
})
.option('routing', {
describe: chalk.dim`Add a routing setup when a preset with pregenerated app is selected`,
type: 'string',
Expand Down Expand Up @@ -232,6 +237,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
preset,
appName,
style,
standaloneApi,
routing,
nxCloud,
packageManager,
Expand Down Expand Up @@ -264,6 +270,7 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
appName,
style,
routing,
standaloneApi,
nxCloud,
defaultBase,
framework,
Expand Down Expand Up @@ -321,7 +328,15 @@ async function getConfiguration(
argv: yargs.Arguments<Arguments>
): Promise<void> {
try {
let name, appName, style, preset, framework, bundler, docker, routing;
let name,
appName,
style,
preset,
framework,
bundler,
docker,
routing,
standaloneApi;

output.log({
title:
Expand Down Expand Up @@ -375,6 +390,7 @@ async function getConfiguration(
}

if (preset === Preset.AngularStandalone) {
standaloneApi = await determineStandaloneApi(argv);
routing = await determineRouting(argv);
}
} else {
Expand All @@ -385,6 +401,7 @@ async function getConfiguration(
}

if (preset === Preset.AngularMonorepo) {
standaloneApi = await determineStandaloneApi(argv);
routing = await determineRouting(argv);
}
}
Expand All @@ -401,6 +418,7 @@ async function getConfiguration(
preset,
appName,
style,
standaloneApi,
routing,
framework,
nxCloud,
Expand Down Expand Up @@ -745,6 +763,37 @@ async function determineFramework(
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(
parsedArgs: yargs.Arguments<Arguments>
): Promise<boolean> {
Expand Down
3 changes: 3 additions & 0 deletions packages/workspace/src/generators/new/generate-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export function generatePreset(host: Tree, opts: NormalizedSchema) {
opts.framework ? `--framework=${opts.framework}` : null,
opts.docker ? `--docker=${opts.docker}` : null,
opts.packageManager ? `--packageManager=${opts.packageManager}` : null,
opts.standaloneApi !== undefined
? `--standaloneApi=${opts.standaloneApi}`
: null,
parsedArgs.interactive ? '--interactive=true' : '--interactive=false',
opts.routing !== undefined ? `--routing=${opts.routing}` : null,
].filter((e) => !!e);
Expand Down
1 change: 1 addition & 0 deletions packages/workspace/src/generators/new/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface Schema {
docker?: boolean;
linter?: Linter;
bundler?: 'vite' | 'webpack';
standaloneApi?: boolean;
routing?: boolean;
packageManager?: PackageManager;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/workspace/src/generators/new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"type": "string",
"description": "Npm scope for importing libs."
},
"standaloneApi": {
"description": "Use the Standalone APIs if generating an Angular application.",
"type": "boolean",
"default": false
},
"defaultBase": {
"type": "string",
"description": "Default base branch for affected."
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,
routing: options.routing,
});
} else if (options.preset === Preset.AngularStandalone) {
Expand All @@ -45,6 +46,7 @@ async function createPreset(tree: Tree, options: Schema) {
linter: options.linter,
routing: options.routing,
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 {
bundler?: 'vite' | 'webpack';
docker?: boolean;
routing?: 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 @@ -56,6 +56,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

1 comment on commit 4f09949

@vercel
Copy link

@vercel vercel bot commented on 4f09949 Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.