Skip to content

Commit

Permalink
chore: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Apr 21, 2023
2 parents 994704e + e3702d9 commit 4feee80
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 175 deletions.
20 changes: 19 additions & 1 deletion actions/generate.action.ts
Expand Up @@ -12,6 +12,7 @@ import { MESSAGES } from '../lib/ui';
import { loadConfiguration } from '../lib/utils/load-configuration';
import {
askForProjectName,
getSpecFileSuffix,
moveDefaultProjectToStart,
shouldAskForProject,
shouldGenerateFlat,
Expand All @@ -36,6 +37,9 @@ 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,
Expand All @@ -52,6 +56,7 @@ const generateFiles = async (inputs: Input[]) => {

const specValue = spec!.value as boolean;
const flatValue = !!flat?.value;
const specFileSuffixValue = specFileSuffix!.value as string;
const specOptions = spec!.options as any;
let generateSpec = shouldGenerateSpec(
configuration,
Expand All @@ -61,6 +66,11 @@ 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
Expand Down Expand Up @@ -107,12 +117,20 @@ 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) {
Expand All @@ -127,7 +145,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) {
Expand Down
8 changes: 8 additions & 0 deletions commands/generate.command.ts
Expand Up @@ -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 };
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/configuration/configuration.ts
Expand Up @@ -33,6 +33,7 @@ interface PluginOptions {
interface GenerateOptions {
spec?: boolean | Record<string, boolean>;
flat?: boolean;
specFileSuffix?: string;
}

export interface ProjectConfiguration {
Expand Down
25 changes: 25 additions & 0 deletions lib/utils/project-utils.ts
Expand Up @@ -89,6 +89,31 @@ export function shouldGenerateFlat(
return flatValue;
}

export function getSpecFileSuffix(
configuration: Required<Configuration>,
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[],
Expand Down

0 comments on commit 4feee80

Please sign in to comment.