Skip to content

Commit

Permalink
fix(@angular/cli): Use the app default prefix when generating
Browse files Browse the repository at this point in the history
fixes #7522
  • Loading branch information
Brocco authored and filipesilva committed Sep 6, 2017
1 parent 53074b2 commit ddcb326
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ export default Command.extend({
const cwd = this.project.root;
const schematicName = rawArgs[0];

if (schematicName === 'component' || schematicName === 'directive') {
if (commandOptions.prefix === undefined) {
commandOptions.prefix = appConfig.prefix;
}
}

const SchematicRunTask = require('../tasks/schematic-run').default;
const schematicRunTask = new SchematicRunTask({
ui: this.ui,
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/tests/generate/component/component-prefix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {join} from 'path';
import {ng} from '../../../utils/process';
import {expectFileToMatch} from '../../../utils/fs';
import { updateJsonFile } from '../../../utils/project';


export default function() {
const componentDir = join('src', 'app', 'test-component');

return Promise.resolve()
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['prefix'] = 'pre';
}))
.then(() => ng('generate', 'component', 'test-component'))
.then(() => expectFileToMatch(join(componentDir, 'test-component.component.ts'),
/selector: 'pre-/))

// Try to run the unit tests.
.then(() => ng('test', '--single-run'));
}
21 changes: 21 additions & 0 deletions tests/e2e/tests/generate/directive/directive-prefix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {join} from 'path';
import {ng} from '../../../utils/process';
import {expectFileToMatch} from '../../../utils/fs';
import { updateJsonFile } from '../../../utils/project';


export default function() {
const directiveDir = join('src', 'app');

return Promise.resolve()
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['prefix'] = 'pre';
}))
.then(() => ng('generate', 'directive', 'test-directive'))
.then(() => expectFileToMatch(join(directiveDir, 'test-directive.directive.ts'),
/selector: '\[pre/))

// Try to run the unit tests.
.then(() => ng('test', '--single-run'));
}

0 comments on commit ddcb326

Please sign in to comment.