Skip to content

Commit

Permalink
fix(core): further meta generator improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Aug 28, 2024
1 parent 91b43a8 commit 40ad570
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 26 deletions.
6 changes: 3 additions & 3 deletions packages/workspace/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/schema",
"$id": "ConvertToInferred",
"$id": "ConvertManyToInferred",
"title": "",
"type": "object",
"properties": {
Expand All @@ -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.",
Expand Down

This file was deleted.

0 comments on commit 40ad570

Please sign in to comment.