Skip to content

Commit

Permalink
fix(core): rename generator
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Aug 28, 2024
1 parent 40ad570 commit e7431fc
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 52 deletions.
6 changes: 3 additions & 3 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -10241,9 +10241,9 @@
"disableCollapsible": false
},
{
"id": "convert-to-inferred",
"path": "/nx-api/workspace/generators/convert-to-inferred",
"name": "convert-to-inferred",
"id": "infer-targets",
"path": "/nx-api/workspace/generators/infer-targets",
"name": "infer-targets",
"children": [],
"isExternal": false,
"disableCollapsible": false
Expand Down
12 changes: 6 additions & 6 deletions docs/generated/manifests/nx-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3424,13 +3424,13 @@
"path": "/nx-api/workspace/generators/ci-workflow",
"type": "generator"
},
"/nx-api/workspace/generators/convert-to-inferred": {
"description": "convert-to-inferred generator",
"file": "generated/packages/workspace/generators/convert-to-inferred.json",
"/nx-api/workspace/generators/infer-targets": {
"description": "Convert Nx projects to use inferred targets.",
"file": "generated/packages/workspace/generators/infer-targets.json",
"hidden": false,
"name": "convert-to-inferred",
"originalFilePath": "/packages/workspace/src/generators/convert-to-inferred/schema.json",
"path": "/nx-api/workspace/generators/convert-to-inferred",
"name": "infer-targets",
"originalFilePath": "/packages/workspace/src/generators/infer-targets/schema.json",
"path": "/nx-api/workspace/generators/infer-targets",
"type": "generator"
}
},
Expand Down
10 changes: 5 additions & 5 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3389,12 +3389,12 @@
"type": "generator"
},
{
"description": "convert-to-inferred generator",
"file": "generated/packages/workspace/generators/convert-to-inferred.json",
"description": "Convert Nx projects to use inferred targets.",
"file": "generated/packages/workspace/generators/infer-targets.json",
"hidden": false,
"name": "convert-to-inferred",
"originalFilePath": "/packages/workspace/src/generators/convert-to-inferred/schema.json",
"path": "workspace/generators/convert-to-inferred",
"name": "infer-targets",
"originalFilePath": "/packages/workspace/src/generators/infer-targets/schema.json",
"path": "workspace/generators/infer-targets",
"type": "generator"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "convert-to-inferred",
"factory": "./src/generators/convert-to-inferred/generator",
"name": "infer-targets",
"factory": "./src/generators/infer-targets/infer-targets",
"schema": {
"$schema": "https://json-schema.org/schema",
"$id": "ConvertToInferred",
"$id": "InferTargets",
"title": "",
"type": "object",
"properties": {
Expand All @@ -12,9 +12,9 @@
"description": "The project to convert to use inferred targets.",
"x-priority": "important"
},
"exclude": {
"plugins": {
"type": "array",
"description": "List of plugins whose convert-to-inferred generators should not be run.",
"description": "Which plugins' convert-to-inferred generators to look for. For example @nx/eslint or @nx/jest",
"items": { "type": "string" }
},
"skipFormat": {
Expand All @@ -25,10 +25,10 @@
},
"presets": []
},
"description": "convert-to-inferred generator",
"implementation": "/packages/workspace/src/generators/convert-to-inferred/generator.ts",
"description": "Convert Nx projects to use inferred targets.",
"implementation": "/packages/workspace/src/generators/infer-targets/infer-targets.ts",
"aliases": [],
"hidden": false,
"path": "/packages/workspace/src/generators/convert-to-inferred/schema.json",
"path": "/packages/workspace/src/generators/infer-targets/schema.json",
"type": "generator"
}
2 changes: 1 addition & 1 deletion docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,4 @@
- [fix-configuration](/nx-api/workspace/generators/fix-configuration)
- [npm-package](/nx-api/workspace/generators/npm-package)
- [ci-workflow](/nx-api/workspace/generators/ci-workflow)
- [convert-to-inferred](/nx-api/workspace/generators/convert-to-inferred)
- [infer-targets](/nx-api/workspace/generators/infer-targets)
4 changes: 2 additions & 2 deletions packages/devkit/src/generators/project-name-and-root-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async function determineFormat(
}

const result = await prompt<{ format: ProjectNameAndRootFormat }>({
type: 'array',
type: 'select',
name: 'format',
message:
'What should be the project name and where should it be generated?',
Expand All @@ -171,7 +171,7 @@ async function determineFormat(
},
],
initial: 0,
} as any).then(({ format }) =>
}).then(({ format }) =>
format === asProvidedSelectedValue ? 'as-provided' : 'derived'
);

Expand Down
8 changes: 4 additions & 4 deletions packages/workspace/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
"schema": "./src/generators/ci-workflow/schema.json",
"description": "Generate a CI workflow."
},
"convert-many-to-inferred": {
"factory": "./src/generators/convert-many-to-inferred/convert-many-to-inferred",
"schema": "./src/generators/convert-many-to-inferred/schema.json",
"description": "convert-to-inferred generator"
"infer-targets": {
"factory": "./src/generators/infer-targets/infer-targets",
"schema": "./src/generators/infer-targets/schema.json",
"description": "Convert Nx projects to use inferred targets."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@ interface Schema {
}

export async function convertToInferredGenerator(tree: Tree, options: Schema) {
const generatorChoices = await getPossibleConvertToInferredGenerators();
const generatorCollectionChoices =
await getPossibleConvertToInferredGenerators();
let generatorsToRun: string[];

if (process.argv.includes('--no-interactive')) {
generatorsToRun = Array.from(generatorChoices.keys());
} else if (options.plugins && options.plugins.length > 0) {
generatorsToRun = Array.from(generatorChoices.values())
if (options.plugins && options.plugins.filter((p) => !!p).length > 0) {
generatorsToRun = Array.from(generatorCollectionChoices.values())
.filter((generator) =>
options.plugins.includes(generator.resolvedCollectionName)
)
.map(
(generator) =>
`${generator.resolvedCollectionName}:${generator.normalizedGeneratorName}`
);
.map((generator) => generator.resolvedCollectionName);
} else if (process.argv.includes('--no-interactive')) {
generatorsToRun = Array.from(generatorCollectionChoices.keys());
} else {
const allChoices = Array.from(generatorChoices.keys());
const allChoices = Array.from(generatorCollectionChoices.keys());

generatorsToRun = (
await prompt<{ generatorsToRun: string[] }>({
Expand All @@ -47,7 +45,7 @@ export async function convertToInferredGenerator(tree: Tree, options: Schema) {
initial: allChoices,
validate: (result: string[]) => {
if (result.length === 0) {
return 'Please select at least one convert-to-inferred generator to run';
return 'Please select at least one plugin.';
}
return true;
},
Expand All @@ -57,14 +55,14 @@ export async function convertToInferredGenerator(tree: Tree, options: Schema) {

if (generatorsToRun.length === 0) {
output.error({
title: 'Please select at least one convert-to-inferred generator to run',
title: 'Please select at least one plugin.',
});
return;
}

for (const generatorName of generatorsToRun) {
for (const generatorCollection of generatorsToRun) {
try {
const generator = generatorChoices.get(generatorName);
const generator = generatorCollectionChoices.get(generatorCollection);
if (generator) {
const generatorFactory = generator.implementationFactory();
const callback = await generatorFactory(tree, {
Expand All @@ -75,17 +73,17 @@ export async function convertToInferredGenerator(tree: Tree, options: Schema) {
await callback();
}
output.success({
title: `${generatorName} - Success`,
title: `${generatorCollection}:convert-to-inferred - Success`,
});
}
} catch (e) {
if (e instanceof NoTargetsToMigrateError) {
output.note({
title: `${generatorName} - Skipped (No targets to migrate)`,
title: `${generatorCollection}:convert-to-inferred - Skipped (No targets to migrate)`,
});
} else {
output.error({
title: `${generatorName} - Failed`,
title: `${generatorCollection}:convert-to-inferred - Failed`,
});
throw e;
}
Expand Down Expand Up @@ -122,11 +120,8 @@ async function getPossibleConvertToInferredGenerators() {
) {
continue;
}
const generatorName = `${generator.resolvedCollectionName}:${generator.normalizedGeneratorName}`;
if (generatorName === '@nx/workspace:convert-to-inferred') {
continue;
}
choices.set(generatorName, generator);

choices.set(generator.resolvedCollectionName, generator);
} catch {
// this just means that no convert-to-inferred generator exists for a given collection, ignore
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/schema",
"$id": "ConvertManyToInferred",
"$id": "InferTargets",
"title": "",
"type": "object",
"properties": {
Expand Down

0 comments on commit e7431fc

Please sign in to comment.