Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): workspace-generator errors should be propagated to nx #12955

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 32 additions & 17 deletions packages/nx/src/command-line/nx-commands.ts
Expand Up @@ -771,13 +771,22 @@ function withRunOneOptions(yargs: yargs.Argv) {
}
}

type OptionArgumentDefinition = {
type: yargs.Options['type'];
describe?: string;
default?: any;
choices?: yargs.Options['type'][];
demandOption?: boolean;
};

type WorkspaceGeneratorProperties = {
[name: string]:
| {
type: yargs.Options['type'];
description?: string;
default?: any;
enum?: yargs.Options['type'][];
demandOption?: boolean;
}
| {
type: yargs.PositionalOptionsType;
Expand Down Expand Up @@ -839,15 +848,19 @@ async function withCustomGeneratorOptions(

Object.entries(schema.properties as WorkspaceGeneratorProperties).forEach(
([name, prop]) => {
options.push({
const option: { name: string; definition: OptionArgumentDefinition } = {
name,
definition: {
describe: prop.description,
type: prop.type,
default: prop.default,
choices: prop.enum,
},
});
};
if (schema.required && schema.required.includes(name)) {
option.definition.demandOption = true;
}
options.push(option);
if (isPositionalProperty(prop)) {
positionals.push({
name,
Expand All @@ -869,21 +882,23 @@ async function withCustomGeneratorOptions(
command += ' (options)';
}

yargs.command({
// this is the default and only command
command,
describe: schema.description || '',
builder: (y) => {
options.forEach(({ name, definition }) => {
y.option(name, definition);
});
positionals.forEach(({ name, definition }) => {
y.positional(name, definition);
});
return linkToNxDevAndExamples(y, 'workspace-generator');
},
handler: workspaceGeneratorHandler,
});
yargs
.command({
// this is the default and only command
command,
describe: schema.description || '',
builder: (y) => {
options.forEach(({ name, definition }) => {
y.option(name, definition);
});
positionals.forEach(({ name, definition }) => {
y.positional(name, definition);
});
return linkToNxDevAndExamples(y, 'workspace-generator');
},
handler: workspaceGeneratorHandler,
})
.fail(() => void 0); // no action is needed on failure as Nx will handle it based on schema validation

return yargs;
}
Expand Down