Skip to content

Commit c27749b

Browse files
committed
feat(blueprint): add blueprint for generating interfaces
Fixes angular#729
1 parent eddb354 commit c27749b

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export interface <%= prefix %><%= classifiedModuleName %> {
2+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const stringUtils = require('ember-cli-string-utils');
2+
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
3+
var addBarrelRegistration = require('../../utilities/barrel-management');
4+
5+
module.exports = {
6+
description: '',
7+
8+
anonymousOptions: [
9+
'<interface-type>'
10+
],
11+
12+
normalizeEntityName: function (entityName) {
13+
var parsedPath = dynamicPathParser(this.project, entityName);
14+
15+
this.dynamicPath = parsedPath;
16+
return parsedPath.name;
17+
},
18+
19+
locals: function (options) {
20+
var interfaceType = options.args [2]
21+
this.fileName = stringUtils.dasherize(options.entity.name);
22+
if (interfaceType) {
23+
this.fileName += '.' + interfaceType;
24+
}
25+
var prefix = '';
26+
if (this.project.ngConfig &&
27+
this.project.ngConfig.defaults &&
28+
this.project.ngConfig.defaults.prefixInterfaces) {
29+
prefix = 'I';
30+
}
31+
return {
32+
dynamicPath: this.dynamicPath.dir,
33+
flat: options.flat,
34+
fileName: this.fileName,
35+
prefix: prefix
36+
};
37+
},
38+
39+
fileMapTokens: function () {
40+
// Return custom template variables here.
41+
return {
42+
__path__: () => {
43+
this.generatePath = this.dynamicPath.dir;
44+
return this.generatePath;
45+
},
46+
__name__: () => {
47+
return this.fileName;
48+
}
49+
};
50+
},
51+
52+
afterInstall: function() {
53+
return addBarrelRegistration(
54+
this,
55+
this.generatePath,
56+
this.fileName);
57+
}
58+
};

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

Lines changed: 2 additions & 1 deletion
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+
"prefixInterfaces": false
2829
}
2930
}

lib/config/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
},
8787
"sourceDir": {
8888
"type": "string"
89+
},
90+
"prefixInterfaces": {
91+
"type": "boolean"
8992
}
9093
},
9194
"additionalProperties": false

0 commit comments

Comments
 (0)