diff --git a/packages/workspace/generators.json b/packages/workspace/generators.json index 28244b8f4e765..dfd129e3fe49a 100644 --- a/packages/workspace/generators.json +++ b/packages/workspace/generators.json @@ -55,9 +55,9 @@ "schema": "./src/generators/ci-workflow/schema.json", "description": "Generate a CI workflow." }, - "convert-to-inferred": { - "factory": "./src/generators/convert-to-inferred/generator", - "schema": "./src/generators/convert-to-inferred/schema.json", + "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" } } diff --git a/packages/workspace/src/generators/convert-to-inferred/generator.spec.ts b/packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.spec.ts similarity index 89% rename from packages/workspace/src/generators/convert-to-inferred/generator.spec.ts rename to packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.spec.ts index 3a5ebe3825e1c..857350f111529 100644 --- a/packages/workspace/src/generators/convert-to-inferred/generator.spec.ts +++ b/packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.spec.ts @@ -1,7 +1,7 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { Tree, readProjectConfiguration } from '@nx/devkit'; -import { convertToInferredGenerator } from './generator'; +import { convertToInferredGenerator } from './convert-many-to-inferred'; import { ConvertToInferredGeneratorSchema } from './schema'; describe('convert-to-inferred generator', () => { diff --git a/packages/workspace/src/generators/convert-to-inferred/generator.ts b/packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.ts similarity index 70% rename from packages/workspace/src/generators/convert-to-inferred/generator.ts rename to packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.ts index 98f903da40e1e..d3cfe1280beea 100644 --- a/packages/workspace/src/generators/convert-to-inferred/generator.ts +++ b/packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.ts @@ -2,13 +2,11 @@ import { createProjectGraphAsync, formatFiles, output, - readNxJson, readProjectsConfigurationFromProjectGraph, Tree, workspaceRoot, } from '@nx/devkit'; import { NoTargetsToMigrateError } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator'; -import { all } from 'cypress/types/bluebird'; import { prompt } from 'enquirer'; import { GeneratorInformation, @@ -18,37 +16,53 @@ import { findInstalledPlugins } from 'nx/src/utils/plugins/installed-plugins'; interface Schema { project?: string; + plugins?: string[]; skipFormat?: boolean; } export async function convertToInferredGenerator(tree: Tree, options: Schema) { const generatorChoices = await getPossibleConvertToInferredGenerators(); - const allChoices = Array.from(generatorChoices.keys()); + let generatorsToRun: string[]; - const result = ( - await prompt<{ generatorsToRun: string[] }>({ - type: 'multiselect', - name: 'generatorsToRun', - message: 'Which convert-to-inferred generators should be run?', - choices: allChoices, - initial: allChoices, - validate: (result: string[]) => { - if (result.length === 0) { - return 'Please select at least one convert-to-inferred generator to run'; - } - return true; - }, - } as any) - ).generatorsToRun; + if (process.argv.includes('--no-interactive')) { + generatorsToRun = Array.from(generatorChoices.keys()); + } else if (options.plugins && options.plugins.length > 0) { + generatorsToRun = Array.from(generatorChoices.values()) + .filter((generator) => + options.plugins.includes(generator.resolvedCollectionName) + ) + .map( + (generator) => + `${generator.resolvedCollectionName}:${generator.normalizedGeneratorName}` + ); + } else { + const allChoices = Array.from(generatorChoices.keys()); + + generatorsToRun = ( + await prompt<{ generatorsToRun: string[] }>({ + type: 'multiselect', + name: 'generatorsToRun', + message: 'Which convert-to-inferred generators should be run?', + choices: allChoices, + initial: allChoices, + validate: (result: string[]) => { + if (result.length === 0) { + return 'Please select at least one convert-to-inferred generator to run'; + } + return true; + }, + } as any) + ).generatorsToRun; + } - if (result.length === 0) { + if (generatorsToRun.length === 0) { output.error({ title: 'Please select at least one convert-to-inferred generator to run', }); return; } - for (const generatorName of result) { + for (const generatorName of generatorsToRun) { try { const generator = generatorChoices.get(generatorName); if (generator) { diff --git a/packages/workspace/src/generators/convert-to-inferred/schema.json b/packages/workspace/src/generators/convert-many-to-inferred/schema.json similarity index 60% rename from packages/workspace/src/generators/convert-to-inferred/schema.json rename to packages/workspace/src/generators/convert-many-to-inferred/schema.json index bf048bd0906bc..c2b7b5ae3c98d 100644 --- a/packages/workspace/src/generators/convert-to-inferred/schema.json +++ b/packages/workspace/src/generators/convert-many-to-inferred/schema.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/schema", - "$id": "ConvertToInferred", + "$id": "ConvertManyToInferred", "title": "", "type": "object", "properties": { @@ -9,6 +9,13 @@ "description": "The project to convert to use inferred targets.", "x-priority": "important" }, + "plugins": { + "type": "array", + "description": "Which plugins' convert-to-inferred generators to look for. For example @nx/eslint or @nx/jest", + "items": { + "type": "string" + } + }, "skipFormat": { "type": "boolean", "description": "Whether to format files.", diff --git a/packages/workspace/src/generators/convert-to-inferred/files/src/index.ts.template b/packages/workspace/src/generators/convert-to-inferred/files/src/index.ts.template deleted file mode 100644 index 877d430279d9e..0000000000000 --- a/packages/workspace/src/generators/convert-to-inferred/files/src/index.ts.template +++ /dev/null @@ -1 +0,0 @@ -const variable = "<%= name %>"; \ No newline at end of file