Skip to content

Commit

Permalink
Merge pull request #2072 from rwjblue/in-repo-addon-generator
Browse files Browse the repository at this point in the history
Add `in-repo-addon` generator.
  • Loading branch information
rwjblue committed Sep 22, 2014
2 parents e600755 + af45281 commit 0394a68
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions blueprints/in-repo-addon/files/lib/__name__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
name: "<%= dasherizedModuleName %>"
};
6 changes: 6 additions & 0 deletions blueprints/in-repo-addon/files/lib/__name__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "<%= dasherizedModuleName %>",
"keywords": [
"ember-addon"
]
}
24 changes: 24 additions & 0 deletions blueprints/in-repo-addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var fs = require('fs-extra');
var path = require('path');
var stringUtil = require('../../lib/utilities/string');

module.exports = {
description: 'The blueprint for addon in repo ember-cli addons.',

afterInstall: function(options) {
var packagePath = path.join(this.project.root, 'package.json');
var contents = JSON.parse(fs.readFileSync(packagePath, { encoding: 'utf8' }));
var name = stringUtil.dasherize(options.entity.name);
var newPath = path.join('lib', name);
var paths;

contents['ember-addon'] = contents['ember-addon'] || {};
paths = contents['ember-addon']['paths'] = contents['ember-addon']['paths'] || [];

if (paths.indexOf(newPath) === -1) {
paths.push(newPath);
}

fs.writeFileSync(packagePath, JSON.stringify(contents, null, 2));
}
};
29 changes: 29 additions & 0 deletions tests/acceptance/generate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,4 +1068,33 @@ describe('Acceptance: ember generate', function() {
});
});
});

it('in-repo-addon foo-bar', function() {
return generate(['in-repo-addon', 'foo-bar']).then(function() {
assertFile('lib/foo-bar/index.js', {
contains: [
'module.exports = {',
'name: "foo-bar"',
'}'
]
});

assertFile('lib/foo-bar/package.json', {
contains: [
'{',
' "name": "foo-bar"',
' "keywords": [',
' "ember-addon"',
' ]',
'}'
]
});

assertFile('package.json', {
contains: [
'"lib/foo-bar"'
]
});
});
});
});

0 comments on commit 0394a68

Please sign in to comment.