Skip to content

Commit

Permalink
fix(core): workspace-generator errors should be propagated to nx (#12955
Browse files Browse the repository at this point in the history
)
  • Loading branch information
meeroslav committed Nov 2, 2022
1 parent bc28a16 commit e6ff5bc
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions packages/nx/src/command-line/nx-commands.ts
Expand Up @@ -718,13 +718,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 @@ -786,15 +795,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 @@ -816,21 +829,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

1 comment on commit e6ff5bc

@vercel
Copy link

@vercel vercel bot commented on e6ff5bc Nov 2, 2022

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-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.