Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addon/ng2/blueprints/interface/files/__path__/__name__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export interface <%= prefix %><%= classifiedModuleName %> {
}
58 changes: 58 additions & 0 deletions addon/ng2/blueprints/interface/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const stringUtils = require('ember-cli-string-utils');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var addBarrelRegistration = require('../../utilities/barrel-management');

module.exports = {
description: '',

anonymousOptions: [
'<interface-type>'
],

normalizeEntityName: function (entityName) {
var parsedPath = dynamicPathParser(this.project, entityName);

this.dynamicPath = parsedPath;
return parsedPath.name;
},

locals: function (options) {
var interfaceType = options.args [2]
this.fileName = stringUtils.dasherize(options.entity.name);
if (interfaceType) {
this.fileName += '.' + interfaceType;
}
var prefix = '';
if (this.project.ngConfig &&
this.project.ngConfig.defaults &&
this.project.ngConfig.defaults.prefixInterfaces) {
prefix = 'I';
}
return {
dynamicPath: this.dynamicPath.dir,
flat: options.flat,
fileName: this.fileName,
prefix: prefix
};
},

fileMapTokens: function () {
// Return custom template variables here.
return {
__path__: () => {
this.generatePath = this.dynamicPath.dir;
return this.generatePath;
},
__name__: () => {
return this.fileName;
}
};
},

afterInstall: function() {
return addBarrelRegistration(
this,
this.generatePath,
this.fileName);
}
};
3 changes: 2 additions & 1 deletion addon/ng2/blueprints/ng2/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"defaults": {
"prefix": "<%= prefix %>",
"sourceDir": "<%= sourceDir %>",
"styleExt": "css"
"styleExt": "css",
"prefixInterfaces": false
}
}
3 changes: 3 additions & 0 deletions lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
},
"styleExt": {
"type": "string"
},
"prefixInterfaces": {
"type": "boolean"
}
},
"additionalProperties": false
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/e2e_workflow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ describe('Basic end-to-end Workflow', function () {
});
});

it('Can create a test interface using `ng generate interface test-interface model`', function () {
return ng(['generate', 'interface', 'test-interface', 'model']).then(function () {
var interfaceDir = path.join(process.cwd(), 'src', 'app');
expect(existsSync(interfaceDir)).to.be.equal(true);
expect(existsSync(path.join(interfaceDir, 'test-interface.model.ts'))).to.be.equal(true);
});
});

it('Perform `ng test` after adding a interface', function () {
this.timeout(420000);

return ng(testArgs).then(function (result) {
const exitCode = typeof result === 'object' ? result.exitCode : result;
expect(exitCode).to.be.equal(0);
});
});

it('moves all files that live inside `public` into `dist`', function () {
this.timeout(420000);

Expand Down