diff --git a/actions/generate.action.ts b/actions/generate.action.ts index 1e024a071..d9faf2d54 100644 --- a/actions/generate.action.ts +++ b/actions/generate.action.ts @@ -16,6 +16,7 @@ import { shouldAskForProject, shouldGenerateFlat, shouldGenerateSpec, + getSpecFileSuffix, } from '../lib/utils/project-utils'; import { AbstractAction } from './abstract.action'; @@ -36,6 +37,7 @@ const generateFiles = async (inputs: Input[]) => { .value as string; const spec = inputs.find((option) => option.name === 'spec'); const flat = inputs.find((option) => option.name === 'flat'); + const specFileSuffix = inputs.find((option) => option.name === 'specFileSuffix'); const collection: AbstractCollection = CollectionFactory.create( collectionOption || configuration.collection || Collection.NESTJS, @@ -52,6 +54,7 @@ const generateFiles = async (inputs: Input[]) => { const specValue = spec!.value as boolean; const flatValue = !!flat as boolean; + const specFileSuffixValue = specFileSuffix!.value as string; const specOptions = spec!.options as any; let generateSpec = shouldGenerateSpec( configuration, @@ -61,6 +64,7 @@ const generateFiles = async (inputs: Input[]) => { specOptions.passedAsInput, ); let generateFlat = shouldGenerateFlat(configuration, appName, flatValue); + let generateSpecFileSuffix = getSpecFileSuffix(configuration, appName, specFileSuffixValue) // If you only add a `lib` we actually don't have monorepo: true BUT we do have "projects" // Ensure we don't run for new app/libs schematics @@ -107,12 +111,14 @@ const generateFiles = async (inputs: Input[]) => { answers.appNames, flatValue, ); + generateSpecFileSuffix = getSpecFileSuffix(configuration, appName, specFileSuffixValue) } } schematicOptions.push(new SchematicOption('sourceRoot', sourceRoot)); schematicOptions.push(new SchematicOption('spec', generateSpec)); schematicOptions.push(new SchematicOption('flat', generateFlat)); + schematicOptions.push(new SchematicOption('specFileSuffix', generateSpecFileSuffix)); try { const schematicInput = inputs.find((input) => input.name === 'schematic'); if (!schematicInput) { @@ -127,7 +133,7 @@ const generateFiles = async (inputs: Input[]) => { }; const mapSchematicOptions = (inputs: Input[]): SchematicOption[] => { - const excludedInputNames = ['schematic', 'spec', 'flat']; + const excludedInputNames = ['schematic', 'spec', 'flat', 'specFileSuffix']; const options: SchematicOption[] = []; inputs.forEach((input) => { if (!excludedInputNames.includes(input.name) && input.value !== undefined) { diff --git a/commands/generate.command.ts b/commands/generate.command.ts index 732a9e0b5..c66544717 100644 --- a/commands/generate.command.ts +++ b/commands/generate.command.ts @@ -36,6 +36,10 @@ export class GenerateCommand extends AbstractCommand { }, true, ) + .option( + '--spec-file-suffix [suffix]', + 'Use a custom suffix for spec files.', + ) .option('--skip-import', 'Skip importing', () => true, false) .option('--no-spec', 'Disable spec files generation.', () => { return { value: false, passedAsInput: true }; @@ -71,6 +75,10 @@ export class GenerateCommand extends AbstractCommand { : command.spec.passedAsInput, }, }); + options.push({ + name: 'specFileSuffix', + value: command.specFileSuffix, + }); options.push({ name: 'collection', value: command.collection, diff --git a/lib/configuration/configuration.ts b/lib/configuration/configuration.ts index 150eacb1a..94fb170b4 100644 --- a/lib/configuration/configuration.ts +++ b/lib/configuration/configuration.ts @@ -33,6 +33,7 @@ interface PluginOptions { interface GenerateOptions { spec?: boolean | Record; flat?: boolean; + specFileSuffix?: string; } export interface ProjectConfiguration { diff --git a/lib/utils/project-utils.ts b/lib/utils/project-utils.ts index 60598d12a..c7b50fe0c 100644 --- a/lib/utils/project-utils.ts +++ b/lib/utils/project-utils.ts @@ -89,6 +89,31 @@ export function shouldGenerateFlat( return flatValue; } +export function getSpecFileSuffix( + configuration: Required, + appName: string, + specFileSuffixValue: string, +): string { + // CLI parameters have the highest priority + if (specFileSuffixValue) { + return specFileSuffixValue; + } + + const specFileSuffixConfiguration = getValueOrDefault( + configuration, + 'generateOptions.specFileSuffix', + appName || '', + undefined, + undefined, + 'spec', + ); + if (typeof specFileSuffixConfiguration === 'string') { + return specFileSuffixConfiguration; + } + return specFileSuffixValue; +} + + export async function askForProjectName( promptQuestion: string, projects: string[],