Skip to content

Commit 048e62c

Browse files
committed
feat(cli): change generate --prefix option type from Boolean to string
use ``ng g c foo --prefix='bar'`` or ``ng g d foo --prefix='bar'`` in order to use another prefix than the one defined by default in angular-cli.json apps[0].prefix tslint rules "directive-selector" and "component-selector" can accept any array of prefix, and is therefore compatible with this approach this is a temporary solution pending angular#3452 closure
1 parent 5630be4 commit 048e62c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

packages/angular-cli/blueprints/component/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ module.exports = {
4444
defaultPrefix = this.project.ngConfig.apps[0].prefix;
4545
}
4646

47-
console.log('prefix option : ' + JSON.stringify(this.options.prefix));
48-
var prefix = this.options.prefix || this.options.prefix === '' ? '' : defaultPrefix;
47+
var prefix = (this.options.prefix === 'false' || this.options.prefix === '') ? '' : (this.options.prefix || defaultPrefix);
4948
prefix = prefix && `${prefix}-`;
50-
console.log('prefix after : ' + JSON.stringify(prefix));
5149

5250
this.selector = stringUtils.dasherize(prefix + parsedPath.name);
5351

packages/angular-cli/blueprints/directive/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
defaultPrefix = this.project.ngConfig.apps[0].prefix;
4040
}
4141

42-
var prefix = this.options.prefix || this.options.prefix === '' ? '' : defaultPrefix;
42+
var prefix = (this.options.prefix === 'false' || this.options.prefix === '') ? '' : (this.options.prefix || defaultPrefix);
4343
prefix = prefix && `${prefix}-`;
4444

4545

tests/acceptance/generate-component.spec.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ describe('Acceptance: ng generate component', function () {
140140
});
141141
});
142142

143-
it('mycomp --prefix=\'\' will not prefix selector', () => {
144-
return ng(['generate', 'component', 'mycomp', '--prefix=\'\''])
143+
it('mycomp --no-prefix will not prefix selector', () => {
144+
return ng(['generate', 'component', 'mycomp', '--no-prefix'])
145145
.then(() => {
146146
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'mycomp', 'mycomp.component.ts');
147147
expect(existsSync(testPath)).to.equal(true);
@@ -150,8 +150,18 @@ describe('Acceptance: ng generate component', function () {
150150
});
151151
});
152152

153-
it('mycomp --prefix=\'test\' will prefix selector with \'test-\'', () => {
154-
return ng(['generate', 'component', 'mycomp', '--prefix=\'test\''])
153+
it('mycomp --prefix= will not prefix selector', () => {
154+
return ng(['generate', 'component', 'mycomp', '--prefix='])
155+
.then(() => {
156+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'mycomp', 'mycomp.component.ts');
157+
expect(existsSync(testPath)).to.equal(true);
158+
var contents = fs.readFileSync(testPath, 'utf8');
159+
expect(contents.indexOf('selector: \'mycomp\'') === -1).to.equal(false);
160+
});
161+
});
162+
163+
it('mycomp --prefix=test will prefix selector with \'test-\'', () => {
164+
return ng(['generate', 'component', 'mycomp', '--prefix=test'])
155165
.then(() => {
156166
var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'mycomp', 'mycomp.component.ts');
157167
expect(existsSync(testPath)).to.equal(true);

0 commit comments

Comments
 (0)