Skip to content

Commit

Permalink
feat(@angular/cli): Read config values from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocco authored and hansl committed Mar 23, 2018
1 parent d57ba45 commit 494b9f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../utilities/schematics';
import { SchematicAvailableOptions } from '../tasks/schematic-get-options';
import { oneLine } from 'common-tags';
import { getConfigValues } from '../tasks/schematic-get-config-values';

const { cyan } = chalk;

Expand Down Expand Up @@ -105,6 +106,8 @@ export default class GenerateCommand extends Command {
const pathOptions = this.getPathOptions(options, workingDir);
options = { ...options, ...pathOptions };

options = getConfigValues(this.name, options.schematic, this.options, options);

const SchematicRunTask = require('../tasks/schematic-run').default;
const schematicRunTask = new SchematicRunTask({
ui: this.ui,
Expand Down
22 changes: 22 additions & 0 deletions packages/@angular/cli/tasks/schematic-get-config-values.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Option } from '../models/command';
import { JsonObject } from '@angular-devkit/core';
import { CliConfig } from '../models/config';

export function getConfigValues(
commandName: 'new' | 'generate',
schematicName: string,
definedOptions: Option[],
options: JsonObject): JsonObject {

const baseJsonPath = `defaults.${commandName}.${schematicName}.`;
return definedOptions
.map(o => o.name)
.filter(name => options[name] === undefined)
.reduce((opts, name) => {
const value = CliConfig.getValue(`${baseJsonPath}.${name}`);
if (value !== undefined) {
opts[name] = value;
}
return opts;
}, {...options});
}

0 comments on commit 494b9f4

Please sign in to comment.