Skip to content

feat: add generation of classes #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2016
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
14 changes: 14 additions & 0 deletions addon/ng2/blueprints/class/files/__path__/__name__.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
describe,
ddescribe,
expect,
iit,
it
} from 'angular2/testing';
import {<%= classifiedModuleName %>} from './<%= fileName %>';

describe('<%= classifiedModuleName %>', () => {
it('should create an instance', () => {
expect(new <%= classifiedModuleName %>()).toBeTruthy();
})
});
2 changes: 2 additions & 0 deletions addon/ng2/blueprints/class/files/__path__/__name__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export class <%= classifiedModuleName %> {
}
51 changes: 51 additions & 0 deletions addon/ng2/blueprints/class/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const stringUtils = require('ember-cli-string-utils');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var addBarrelRegistration = require('../../utilities/barrel-management');

module.exports = {
description: '',

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

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

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

locals: function (options) {
var classType = options.args [2]
this.fileName = stringUtils.dasherize(options.entity.name);
if (classType) {
this.fileName += '.' + classType;
}
return {
dynamicPath: this.dynamicPath.dir,
flat: options.flat,
fileName: this.fileName
};
},

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);
}
};
1 change: 1 addition & 0 deletions addon/ng2/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function mapBlueprintName(name) {
}

const aliasMap = {
'cl': 'class',
'c': 'component',
'd': 'directive',
'p': 'pipe',
Expand Down
56 changes: 56 additions & 0 deletions tests/acceptance/generate-class.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

const ng = require('../helpers/ng');
const tmp = require('../helpers/tmp');

const conf = require('ember-cli/tests/helpers/conf');
const existsSync = require('exists-sync');
const expect = require('chai').expect;
const path = require('path');
const root = process.cwd();

const testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app');

describe('Acceptance: ng generate class', function () {
before(conf.setup);

after(conf.restore);

beforeEach(function () {
return tmp.setup('./tmp').then(function () {
process.chdir('./tmp');
}).then(function () {
return ng(['new', 'foo', '--skip-npm', '--skip-bower']);
});
});

afterEach(function () {
this.timeout(10000);

return tmp.teardown('./tmp');
});

it('ng generate class my-class', function () {
return ng(['generate', 'class', 'my-class']).then(() => {
expect(existsSync(path.join(testPath, 'my-class.ts'))).to.equal(true);
});
});

it('ng generate class my-class model', function () {
return ng(['generate', 'class', 'my-class', 'model']).then(() => {
expect(existsSync(path.join(testPath, 'my-class.model.ts'))).to.equal(true);
});
});

it(`ng generate class shared${path.sep}my-class`, function () {
return ng(['generate', 'class', 'shared/my-class']).then(() => {
expect(existsSync(path.join(testPath, 'shared', 'my-class.ts'))).to.equal(true);
});
});

it(`ng generate class shared${path.sep}my-class model`, function () {
return ng(['generate', 'class', 'shared/my-class', 'model']).then(() => {
expect(existsSync(path.join(testPath, 'shared', 'my-class.model.ts'))).to.equal(true);
});
});
});