Skip to content

Commit

Permalink
feat: Add skip import option to generate command
Browse files Browse the repository at this point in the history
  • Loading branch information
StringKe committed Mar 22, 2022
1 parent e043359 commit 1a0213e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion actions/generate.action.ts
Expand Up @@ -121,7 +121,10 @@ const mapSchematicOptions = (inputs: Input[]): SchematicOption[] => {
const options: SchematicOption[] = [];
inputs.forEach((input) => {
if (!excludedInputNames.includes(input.name) && input.value !== undefined) {
options.push(new SchematicOption(input.name, input.value));
const keepInputName = input.options
? 'keepInputNameFormat' in input.options
: false;
options.push(new SchematicOption(input.name, input.value, keepInputName));
}
});
return options;
Expand Down
9 changes: 9 additions & 0 deletions commands/generate.command.ts
Expand Up @@ -34,6 +34,7 @@ export class GenerateCommand extends AbstractCommand {
},
true,
)
.option('--skip-import', 'Skip importing', () => true, false)
.option('--no-spec', 'Disable spec files generation.', () => {
return { value: false, passedAsInput: true };
})
Expand Down Expand Up @@ -77,6 +78,14 @@ export class GenerateCommand extends AbstractCommand {
value: command.project,
});

options.push({
name: 'skipImport',
value: command.skipImport,
options: {
keepInputNameFormat: true,
},
});

const inputs: Input[] = [];
inputs.push({ name: 'schematic', value: schematic });
inputs.push({ name: 'name', value: name });
Expand Down
10 changes: 8 additions & 2 deletions lib/schematics/schematic.option.ts
@@ -1,7 +1,11 @@
import { normalizeToKebabOrSnakeCase } from '../utils/formatting';

export class SchematicOption {
constructor(private name: string, private value: boolean | string) {}
constructor(
private name: string,
private value: boolean | string,
private keepInputNameFormat: boolean = false,
) {}

public toCommandString(): string {
if (typeof this.value === 'string') {
Expand All @@ -13,7 +17,9 @@ export class SchematicOption {
return `--${this.name}="${this.value}"`;
}
} else if (typeof this.value === 'boolean') {
const str = normalizeToKebabOrSnakeCase(this.name);
const str = this.keepInputNameFormat
? this.name
: normalizeToKebabOrSnakeCase(this.name);
return this.value ? `--${str}` : `--no-${str}`;
} else {
return `--${normalizeToKebabOrSnakeCase(this.name)}=${this.value}`;
Expand Down
8 changes: 8 additions & 0 deletions test/lib/schematics/schematic.option.spec.ts
Expand Up @@ -120,4 +120,12 @@ describe('Schematic Option', () => {
const option = new SchematicOption('dry-run', false);
expect(option.toCommandString()).toEqual('--no-dry-run');
});

it('should keep input name boolean option', () => {
const keepNameOption = new SchematicOption('noDryRunABcdEfg', true, true);
expect(keepNameOption.toCommandString()).toEqual('--noDryRunABcdEfg');

const disableKeepNameOption = new SchematicOption('dry-run', true, false);
expect(disableKeepNameOption.toCommandString()).toEqual('--dry-run');
});
});

0 comments on commit 1a0213e

Please sign in to comment.