Skip to content

Commit e6ff5bc

Browse files
authored
fix(core): workspace-generator errors should be propagated to nx (#12955)
1 parent bc28a16 commit e6ff5bc

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

packages/nx/src/command-line/nx-commands.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,22 @@ function withRunOneOptions(yargs: yargs.Argv) {
718718
}
719719
}
720720

721+
type OptionArgumentDefinition = {
722+
type: yargs.Options['type'];
723+
describe?: string;
724+
default?: any;
725+
choices?: yargs.Options['type'][];
726+
demandOption?: boolean;
727+
};
728+
721729
type WorkspaceGeneratorProperties = {
722730
[name: string]:
723731
| {
724732
type: yargs.Options['type'];
725733
description?: string;
726734
default?: any;
727735
enum?: yargs.Options['type'][];
736+
demandOption?: boolean;
728737
}
729738
| {
730739
type: yargs.PositionalOptionsType;
@@ -786,15 +795,19 @@ async function withCustomGeneratorOptions(
786795

787796
Object.entries(schema.properties as WorkspaceGeneratorProperties).forEach(
788797
([name, prop]) => {
789-
options.push({
798+
const option: { name: string; definition: OptionArgumentDefinition } = {
790799
name,
791800
definition: {
792801
describe: prop.description,
793802
type: prop.type,
794803
default: prop.default,
795804
choices: prop.enum,
796805
},
797-
});
806+
};
807+
if (schema.required && schema.required.includes(name)) {
808+
option.definition.demandOption = true;
809+
}
810+
options.push(option);
798811
if (isPositionalProperty(prop)) {
799812
positionals.push({
800813
name,
@@ -816,21 +829,23 @@ async function withCustomGeneratorOptions(
816829
command += ' (options)';
817830
}
818831

819-
yargs.command({
820-
// this is the default and only command
821-
command,
822-
describe: schema.description || '',
823-
builder: (y) => {
824-
options.forEach(({ name, definition }) => {
825-
y.option(name, definition);
826-
});
827-
positionals.forEach(({ name, definition }) => {
828-
y.positional(name, definition);
829-
});
830-
return linkToNxDevAndExamples(y, 'workspace-generator');
831-
},
832-
handler: workspaceGeneratorHandler,
833-
});
832+
yargs
833+
.command({
834+
// this is the default and only command
835+
command,
836+
describe: schema.description || '',
837+
builder: (y) => {
838+
options.forEach(({ name, definition }) => {
839+
y.option(name, definition);
840+
});
841+
positionals.forEach(({ name, definition }) => {
842+
y.positional(name, definition);
843+
});
844+
return linkToNxDevAndExamples(y, 'workspace-generator');
845+
},
846+
handler: workspaceGeneratorHandler,
847+
})
848+
.fail(() => void 0); // no action is needed on failure as Nx will handle it based on schema validation
834849

835850
return yargs;
836851
}

0 commit comments

Comments
 (0)