Skip to content

Commit 482aa74

Browse files
Broccohansl
authored andcommitted
feat(blueprint): add blueprint for generating interfaces (#757)
Fixes #729
1 parent ad6ab2f commit 482aa74

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export interface <%= prefix %><%= classifiedModuleName %> {
2+
}
+58
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"defaults": {
2626
"prefix": "<%= prefix %>",
2727
"sourceDir": "<%= sourceDir %>",
28-
"styleExt": "css"
28+
"styleExt": "css",
29+
"prefixInterfaces": false
2930
}
3031
}

lib/config/schema.json

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
},
9090
"styleExt": {
9191
"type": "string"
92+
},
93+
"prefixInterfaces": {
94+
"type": "boolean"
9295
}
9396
},
9497
"additionalProperties": false

tests/e2e/e2e_workflow.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,23 @@ describe('Basic end-to-end Workflow', function () {
188188
});
189189
});
190190

191+
it('Can create a test interface using `ng generate interface test-interface model`', function () {
192+
return ng(['generate', 'interface', 'test-interface', 'model']).then(function () {
193+
var interfaceDir = path.join(process.cwd(), 'src', 'app');
194+
expect(existsSync(interfaceDir)).to.be.equal(true);
195+
expect(existsSync(path.join(interfaceDir, 'test-interface.model.ts'))).to.be.equal(true);
196+
});
197+
});
198+
199+
it('Perform `ng test` after adding a interface', function () {
200+
this.timeout(420000);
201+
202+
return ng(testArgs).then(function (result) {
203+
const exitCode = typeof result === 'object' ? result.exitCode : result;
204+
expect(exitCode).to.be.equal(0);
205+
});
206+
});
207+
191208
it('moves all files that live inside `public` into `dist`', function () {
192209
this.timeout(420000);
193210

0 commit comments

Comments
 (0)