Skip to content

Commit c302be8

Browse files
Broccohansl
authored andcommitted
chore: add ability to set default style file extensions (angular#763)
1 parent eddb354 commit c302be8

File tree

8 files changed

+20
-10
lines changed

8 files changed

+20
-10
lines changed

addon/ng2/blueprints/component/files/__path__/__name__.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Component, OnInit } from '@angular/core';
1010
`,<% } else { %>
1111
templateUrl: '<%= dasherizedModuleName %>.component.html',<% } if(inlineStyle) { %>
1212
styles: []<% } else { %>
13-
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']<% } %>
13+
styleUrls: ['<%= dasherizedModuleName %>.component.css']<% } %>
1414
})
1515
export class <%= classifiedModuleName %>Component implements OnInit {
1616

addon/ng2/blueprints/component/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,19 @@ module.exports = {
3939
},
4040

4141
locals: function (options) {
42-
//TODO: pull value from config
4342
this.styleExt = 'css';
43+
if (this.project.ngConfig &&
44+
this.project.ngConfig.defaults &&
45+
this.project.ngConfig.defaults.styleExt) {
46+
this.styleExt = this.project.ngConfig.defaults.styleExt;
47+
}
4448

4549
return {
4650
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
4751
flat: options.flat,
4852
inlineTemplate: options.inlineTemplate,
4953
inlineStyle: options.inlineStyle,
5054
route: options.route,
51-
styleExt: this.styleExt,
5255
isLazyRoute: !!options.isLazyRoute,
5356
isAppComponent: !!options.isAppComponent,
5457
selector: this.selector
@@ -94,7 +97,7 @@ module.exports = {
9497
return dir;
9598
},
9699
__styleext__: () => {
97-
return options.locals.styleExt;
100+
return this.styleExt;
98101
}
99102
};
100103
},

addon/ng2/blueprints/ng2/files/__path__/app/__name__.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Component } from '@angular/core';
99
</h1>
1010
`,
1111
styles: []<% } else { %>templateUrl: '<%= htmlComponentName %>.component.html',
12-
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']<% } %>
12+
styleUrls: ['<%= dasherizedModuleName %>.component.css']<% } %>
1313
})
1414
export class <%= jsComponentName %>AppComponent {
1515
title = '<%= htmlComponentName %> works!';

addon/ng2/blueprints/ng2/files/angular-cli.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525
"defaults": {
2626
"prefix": "<%= prefix %>",
27-
"sourceDir": "<%= sourceDir %>"
27+
"sourceDir": "<%= sourceDir %>",
28+
"styleExt": "css"
2829
}
2930
}

addon/ng2/blueprints/ng2/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
availableOptions: [
99
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
1010
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
11+
{ name: 'style', type: String, default: 'css' },
1112
{ name: 'mobile', type: Boolean, default: false }
1213
],
1314

@@ -18,8 +19,7 @@ module.exports = {
1819
},
1920

2021
locals: function(options) {
21-
//TODO: pull value from config
22-
this.styleExt = 'css';
22+
this.styleExt = options.style;
2323
this.version = require(path.resolve(__dirname, '..', '..', '..', '..', 'package.json')).version;
2424

2525
// Join with / not path.sep as reference to typings require forward slashes.
@@ -32,10 +32,10 @@ module.exports = {
3232
htmlComponentName: stringUtils.dasherize(options.entity.name),
3333
jsComponentName: stringUtils.classify(options.entity.name),
3434
fullAppName: fullAppName,
35-
styleExt: this.styleExt,
3635
version: this.version,
3736
sourceDir: options.sourceDir,
3837
prefix: options.prefix,
38+
styleExt: this.styleExt,
3939
refToTypings: refToTypings,
4040
isMobile: options.mobile
4141
};
@@ -48,7 +48,7 @@ module.exports = {
4848
return options.locals.sourceDir;
4949
},
5050
__styleext__: () => {
51-
return options.locals.styleExt;
51+
return this.styleExt;
5252
}
5353
};
5454
}

addon/ng2/commands/init.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = Command.extend({
2121
{ name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] },
2222
{ name: 'name', type: String, default: '', aliases: ['n'] },
2323
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
24+
{ name: 'style', type: String, default: 'css' },
2425
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
2526
{ name: 'mobile', type: Boolean, default: false }
2627
],
@@ -90,6 +91,7 @@ module.exports = Command.extend({
9091
targetFiles: rawArgs || '',
9192
rawArgs: rawArgs.toString(),
9293
sourceDir: commandOptions.sourceDir,
94+
style: commandOptions.style,
9395
prefix: commandOptions.prefix,
9496
mobile: commandOptions.mobile
9597
};

addon/ng2/commands/new.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const NewCommand = Command.extend({
2121
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
2222
{ name: 'directory', type: String, aliases: ['dir'] },
2323
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
24+
{ name: 'style', type: String, default: 'css' },
2425
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
2526
{ name: 'mobile', type: Boolean, default: false }
2627
],

lib/config/schema.json

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
},
8787
"sourceDir": {
8888
"type": "string"
89+
},
90+
"styleExt": {
91+
"type": "string"
8992
}
9093
},
9194
"additionalProperties": false

0 commit comments

Comments
 (0)