Skip to content

Commit

Permalink
fix: minor changes to met the current behavior
Browse files Browse the repository at this point in the history
- emit error on retrieve inputs with 'undefined' value
- leave 'project' option optional as before
- leave 'collection' optional as before
- allow 'specFileSuffix' to be undefined
- allow 'config' option to be undefined on build command
  • Loading branch information
micalevisk committed Jul 22, 2023
1 parent 7c44a62 commit 4507fbb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions actions/build.action.ts
Expand Up @@ -69,7 +69,7 @@ export class BuildAction extends AbstractAction {
isDebugEnabled = false,
onSuccess?: () => void,
) {
const configFileName = commandOptions.get<string>('config', true).value;
const configFileName = commandOptions.get<string>('config')?.value;
const configuration = await this.loader.load(configFileName);
const appName = commandInputs.get<string>('app', true).value;

Expand Down Expand Up @@ -178,7 +178,9 @@ export class BuildAction extends AbstractAction {
watchMode: boolean,
onSuccess: (() => void) | undefined,
) {
const { WebpackCompiler } = await import('../lib/compiler/webpack-compiler')
const { WebpackCompiler } = await import(
'../lib/compiler/webpack-compiler'
);
const webpackCompiler = new WebpackCompiler(this.pluginsLoader);

const webpackPath =
Expand Down
10 changes: 5 additions & 5 deletions actions/generate.action.ts
Expand Up @@ -29,12 +29,12 @@ export class GenerateAction extends AbstractAction {
const generateFiles = async (storage: CommandStorage) => {
const configuration = await loadConfiguration();

const collectionOption = storage.get<string>('collection', true).value;
const collectionOption = storage.get<Collection>('collection')?.value;
const schematic = storage.get<string>('schematic', true).value;
const appName = storage.get<string>('project', true).value;
const appName = storage.get<string>('project')?.value;
const spec = storage.get<boolean>('spec', true);
const flat = storage.get<boolean>('flat', true);
const specFileSuffix = storage.get<string>('specFileSuffix', true);
const flat = storage.get<boolean>('flat');
const specFileSuffix = storage.get<string>('specFileSuffix');

const collection: AbstractCollection = CollectionFactory.create(
collectionOption || configuration.collection || Collection.NESTJS,
Expand All @@ -51,7 +51,7 @@ const generateFiles = async (storage: CommandStorage) => {

const specValue = spec.value;
const flatValue = !!flat?.value;
const specFileSuffixValue = specFileSuffix.value;
const specFileSuffixValue = specFileSuffix?.value;
const specOptions = spec.options;
let generateSpec = shouldGenerateSpec(
configuration,
Expand Down
2 changes: 1 addition & 1 deletion commands/command-storage.ts
Expand Up @@ -52,7 +52,7 @@ export class CommandStorage {
| CommandStorageEntry<TValue>
| undefined;
if (errorOnMissing) {
if (!input) {
if (!input || input.value === undefined) {
throw new Error(`The input ${inputName} is missing!`);
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/utils/project-utils.ts
Expand Up @@ -21,7 +21,7 @@ export function shouldAskForProject(
export function shouldGenerateSpec(
configuration: Required<Configuration>,
schematic: string,
appName: string,
appName: string | undefined,
specValue: boolean,
specPassedAsInput?: boolean,
) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export function shouldGenerateSpec(

export function shouldGenerateFlat(
configuration: Required<Configuration>,
appName: string,
appName: string | undefined,
flatValue: boolean,
): boolean {
// CLI parameters have the highest priority
Expand All @@ -91,8 +91,8 @@ export function shouldGenerateFlat(

export function getSpecFileSuffix(
configuration: Required<Configuration>,
appName: string,
specFileSuffixValue: string,
appName: string | undefined,
specFileSuffixValue: string | undefined,
): string {
// CLI parameters have the highest priority
if (specFileSuffixValue) {
Expand All @@ -110,7 +110,7 @@ export function getSpecFileSuffix(
if (typeof specFileSuffixConfiguration === 'string') {
return specFileSuffixConfiguration;
}
return specFileSuffixValue;
throw new Error('No spec file suffix was defined!');
}

export async function askForProjectName(
Expand Down

0 comments on commit 4507fbb

Please sign in to comment.