Skip to content

Commit f23bf22

Browse files
Broccohansl
authored andcommitted
feat: add generation of classes (#563)
1 parent ba4efc1 commit f23bf22

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {
2+
describe,
3+
ddescribe,
4+
expect,
5+
iit,
6+
it
7+
} from 'angular2/testing';
8+
import {<%= classifiedModuleName %>} from './<%= fileName %>';
9+
10+
describe('<%= classifiedModuleName %>', () => {
11+
it('should create an instance', () => {
12+
expect(new <%= classifiedModuleName %>()).toBeTruthy();
13+
})
14+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export class <%= classifiedModuleName %> {
2+
}

addon/ng2/blueprints/class/index.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
'<class-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 classType = options.args [2]
21+
this.fileName = stringUtils.dasherize(options.entity.name);
22+
if (classType) {
23+
this.fileName += '.' + classType;
24+
}
25+
return {
26+
dynamicPath: this.dynamicPath.dir,
27+
flat: options.flat,
28+
fileName: this.fileName
29+
};
30+
},
31+
32+
fileMapTokens: function () {
33+
// Return custom template variables here.
34+
return {
35+
__path__: () => {
36+
this.generatePath = this.dynamicPath.dir;
37+
return this.generatePath;
38+
},
39+
__name__: () => {
40+
return this.fileName;
41+
}
42+
};
43+
},
44+
45+
afterInstall: function() {
46+
return addBarrelRegistration(
47+
this,
48+
this.generatePath,
49+
this.fileName);
50+
}
51+
};

addon/ng2/commands/generate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function mapBlueprintName(name) {
2929
}
3030

3131
const aliasMap = {
32+
'cl': 'class',
3233
'c': 'component',
3334
'd': 'directive',
3435
'p': 'pipe',
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
3+
const ng = require('../helpers/ng');
4+
const tmp = require('../helpers/tmp');
5+
6+
const conf = require('ember-cli/tests/helpers/conf');
7+
const existsSync = require('exists-sync');
8+
const expect = require('chai').expect;
9+
const path = require('path');
10+
const root = process.cwd();
11+
12+
const testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app');
13+
14+
describe('Acceptance: ng generate class', function () {
15+
before(conf.setup);
16+
17+
after(conf.restore);
18+
19+
beforeEach(function () {
20+
return tmp.setup('./tmp').then(function () {
21+
process.chdir('./tmp');
22+
}).then(function () {
23+
return ng(['new', 'foo', '--skip-npm', '--skip-bower']);
24+
});
25+
});
26+
27+
afterEach(function () {
28+
this.timeout(10000);
29+
30+
return tmp.teardown('./tmp');
31+
});
32+
33+
it('ng generate class my-class', function () {
34+
return ng(['generate', 'class', 'my-class']).then(() => {
35+
expect(existsSync(path.join(testPath, 'my-class.ts'))).to.equal(true);
36+
});
37+
});
38+
39+
it('ng generate class my-class model', function () {
40+
return ng(['generate', 'class', 'my-class', 'model']).then(() => {
41+
expect(existsSync(path.join(testPath, 'my-class.model.ts'))).to.equal(true);
42+
});
43+
});
44+
45+
it(`ng generate class shared${path.sep}my-class`, function () {
46+
return ng(['generate', 'class', 'shared/my-class']).then(() => {
47+
expect(existsSync(path.join(testPath, 'shared', 'my-class.ts'))).to.equal(true);
48+
});
49+
});
50+
51+
it(`ng generate class shared${path.sep}my-class model`, function () {
52+
return ng(['generate', 'class', 'shared/my-class', 'model']).then(() => {
53+
expect(existsSync(path.join(testPath, 'shared', 'my-class.model.ts'))).to.equal(true);
54+
});
55+
});
56+
});

0 commit comments

Comments
 (0)