Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ export default Command.extend({
const cwd = this.project.root;
const schematicName = rawArgs[0];

if (schematicName === 'component' || schematicName === 'directive') {
if (['component', 'c', 'directive', 'd'].indexOf(schematicName) !== -1) {
if (commandOptions.prefix === undefined) {
commandOptions.prefix = appConfig.prefix;
}

if (schematicName === 'component' || schematicName === 'c') {
if (commandOptions.styleext === undefined) {
commandOptions.styleext = CliConfig.getValue('defaults.styleExt');
}
}
}

const SchematicRunTask = require('../tasks/schematic-run').default;
Expand Down
3 changes: 1 addition & 2 deletions packages/@angular/cli/tasks/schematic-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ function prepOptions(schematic: Schematic<{}, {}>, options: SchematicOptions): S

const properties = (<any>schematic.description).schemaJson.properties;
const keys = Object.keys(properties);

if (schematic.description.name === 'component') {
if (['component', 'c', 'directive', 'd'].indexOf(schematic.description.name) !== -1) {
options.prefix = (options.prefix === 'false' || options.prefix === '')
? '' : options.prefix;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/acceptance/generate-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ describe('Acceptance: ng generate component', () => {
.then(done, done.fail);
});

it('mycomp should use styleExt from the angular-cli.json for style file', (done) => {
return ng(['generate', 'component', 'mycomp']).then(() => {
const cliJson = JSON.parse(readFileSync('.angular-cli.json', 'utf8'));
const styleExt = cliJson.defaults.styleExt;
expect(styleExt).toBe('css');
const scssFilePath =
path.join(root, 'tmp', 'foo', 'src', 'app', 'mycomp', `mycomp.component.${styleExt}`);
const compPath =
path.join(root, 'tmp', 'foo', 'src', 'app', 'mycomp', 'mycomp.component.ts');
expect(pathExistsSync(scssFilePath)).toBe(true);
const contents = readFileSync(compPath, 'utf8');
expect(contents.indexOf(`styleUrls: [\'./mycomp.component.${styleExt}\']`) === -1).toBe(false);
})
.then(done, done.fail);
});

it('child-dir' + path.sep + 'my-comp from a child dir', (done) => {
mkdirsSync(path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir'));
return new Promise(function (resolve) {
Expand Down