Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ddcb326

Browse files
Broccofilipesilva
authored andcommittedSep 6, 2017
fix(@angular/cli): Use the app default prefix when generating
fixes #7522
1 parent 53074b2 commit ddcb326

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
 

‎packages/@angular/cli/commands/generate.ts

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ export default Command.extend({
145145
const cwd = this.project.root;
146146
const schematicName = rawArgs[0];
147147

148+
if (schematicName === 'component' || schematicName === 'directive') {
149+
if (commandOptions.prefix === undefined) {
150+
commandOptions.prefix = appConfig.prefix;
151+
}
152+
}
153+
148154
const SchematicRunTask = require('../tasks/schematic-run').default;
149155
const schematicRunTask = new SchematicRunTask({
150156
ui: this.ui,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {join} from 'path';
2+
import {ng} from '../../../utils/process';
3+
import {expectFileToMatch} from '../../../utils/fs';
4+
import { updateJsonFile } from '../../../utils/project';
5+
6+
7+
export default function() {
8+
const componentDir = join('src', 'app', 'test-component');
9+
10+
return Promise.resolve()
11+
.then(() => updateJsonFile('.angular-cli.json', configJson => {
12+
const app = configJson['apps'][0];
13+
app['prefix'] = 'pre';
14+
}))
15+
.then(() => ng('generate', 'component', 'test-component'))
16+
.then(() => expectFileToMatch(join(componentDir, 'test-component.component.ts'),
17+
/selector: 'pre-/))
18+
19+
// Try to run the unit tests.
20+
.then(() => ng('test', '--single-run'));
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {join} from 'path';
2+
import {ng} from '../../../utils/process';
3+
import {expectFileToMatch} from '../../../utils/fs';
4+
import { updateJsonFile } from '../../../utils/project';
5+
6+
7+
export default function() {
8+
const directiveDir = join('src', 'app');
9+
10+
return Promise.resolve()
11+
.then(() => updateJsonFile('.angular-cli.json', configJson => {
12+
const app = configJson['apps'][0];
13+
app['prefix'] = 'pre';
14+
}))
15+
.then(() => ng('generate', 'directive', 'test-directive'))
16+
.then(() => expectFileToMatch(join(directiveDir, 'test-directive.directive.ts'),
17+
/selector: '\[pre/))
18+
19+
// Try to run the unit tests.
20+
.then(() => ng('test', '--single-run'));
21+
}

0 commit comments

Comments
 (0)
Please sign in to comment.