Skip to content

Commit

Permalink
removed adding providers when generating a new server
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Aug 10, 2016
1 parent d22250e commit 537bb82
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
18 changes: 4 additions & 14 deletions addon/ng2/blueprints/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var addBarrelRegistration = require('../../utilities/barrel-management');
var getFiles = Blueprint.prototype.files;
const stringUtils = require('ember-cli-string-utils');
const astUtils = require('../../utilities/ast-utils');

module.exports = {
description: '',

availableOptions: [
{ name: 'flat', type: Boolean, default: true }
],
Expand All @@ -26,10 +25,10 @@ module.exports = {
flat: options.flat
};
},

files: function() {
var fileList = getFiles.call(this);

if (this.options && this.options.flat) {
fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
}
Expand All @@ -50,26 +49,17 @@ module.exports = {
}
};
},

afterInstall: function(options) {
const returns = [];
const fileName = stringUtils.dasherize(`${options.entity.name}.service`);
const modulePath = path.join(this.project.root, this.dynamicPath.appRoot, 'app.module.ts');
const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath);
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;
const className = stringUtils.classify(`${options.entity.name}Service`);

if (!options.flat) {
returns.push(addBarrelRegistration(this, this.generatePath));
} else {
returns.push(addBarrelRegistration(this, this.generatePath, fileName));
}

returns.push(
astUtils.addProviderToModule(modulePath, className, importPath)
.then(change => change.apply()));


return Promise.all(returns);
}
};
4 changes: 2 additions & 2 deletions tests/acceptance/generate-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ describe('Acceptance: ng generate service', function () {
.then(() => expect(existsSync(testPath)).to.equal(true))
.then(() => readFile(appModulePath, 'utf-8'))
.then(content => {
expect(content).matches(/import.*\MySvcService\b.*from '.\/my-svc.service';/);
expect(content).matches(/providers:\s*\[MySvcService\]/m);
expect(content).not.to.matches(/import.*\MySvcService\b.*from '.\/my-svc.service';/);
expect(content).not.to.matches(/providers:\s*\[MySvcService\]/m);
});
});

Expand Down

0 comments on commit 537bb82

Please sign in to comment.