Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): allow for flat generate option configuration #1805

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion actions/generate.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
askForProjectName,
moveDefaultProjectToStart,
shouldAskForProject,
shouldGenerateFlat,
shouldGenerateSpec,
} from '../lib/utils/project-utils';
import { AbstractAction } from './abstract.action';
Expand All @@ -34,6 +35,7 @@ const generateFiles = async (inputs: Input[]) => {
const appName = inputs.find((option) => option.name === 'project')!
.value as string;
const spec = inputs.find((option) => option.name === 'spec');
const flat = inputs.find((option) => option.name === 'flat');

const collection: AbstractCollection = CollectionFactory.create(
collectionOption || configuration.collection || Collection.NESTJS,
Expand All @@ -49,6 +51,7 @@ const generateFiles = async (inputs: Input[]) => {
: configuration.sourceRoot;

const specValue = spec!.value as boolean;
const flatValue = !!flat as boolean;
const specOptions = spec!.options as any;
let generateSpec = shouldGenerateSpec(
configuration,
Expand All @@ -57,6 +60,7 @@ const generateFiles = async (inputs: Input[]) => {
specValue,
specOptions.passedAsInput,
);
let generateFlat = shouldGenerateFlat(configuration, appName, flatValue);

// 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 @@ -98,11 +102,13 @@ const generateFiles = async (inputs: Input[]) => {
specValue,
specOptions.passedAsInput,
);
generateFlat = shouldGenerateFlat(configuration, answers.appNames, flatValue);
}
}

schematicOptions.push(new SchematicOption('sourceRoot', sourceRoot));
schematicOptions.push(new SchematicOption('spec', generateSpec));
schematicOptions.push(new SchematicOption('flat', generateFlat));
try {
const schematicInput = inputs.find((input) => input.name === 'schematic');
if (!schematicInput) {
Expand All @@ -117,7 +123,7 @@ const generateFiles = async (inputs: Input[]) => {
};

const mapSchematicOptions = (inputs: Input[]): SchematicOption[] => {
const excludedInputNames = ['schematic', 'spec'];
const excludedInputNames = ['schematic', 'spec', 'flat'];
const options: SchematicOption[] = [];
inputs.forEach((input) => {
if (!excludedInputNames.includes(input.name) && input.value !== undefined) {
Expand Down
1 change: 1 addition & 0 deletions lib/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface PluginOptions {

interface GenerateOptions {
spec?: boolean | Record<string, boolean>;
flat?: boolean;
}

export interface ProjectConfiguration {
Expand Down
21 changes: 21 additions & 0 deletions lib/utils/project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ export function shouldGenerateSpec(
return specValue;
}

export function shouldGenerateFlat(
configuration: Required<Configuration>,
appName: string,
flatValue: boolean,
): boolean {
// CLI parameters have the highest priority
if (flatValue === true) {
return flatValue;
}

const flatConfiguration = getValueOrDefault(
configuration,
'generateOptions.flat',
appName || '',
);
if (typeof flatConfiguration === 'boolean') {
return flatConfiguration;
}
return flatValue;
}

export async function askForProjectName(
promptQuestion: string,
projects: string[],
Expand Down