Skip to content

Commit

Permalink
create subgenerator for config/default.json file, resolve electrodejs#28
Browse files Browse the repository at this point in the history
  • Loading branch information
kbariotis committed Oct 25, 2016
1 parent 526331e commit 7182ba6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ module.exports = generators.Base.extend({
});
}

if (!this.fs.exists(this.destinationPath('config/default.json'))) {
this.composeWith('electrode:config', {
options: {
name: this.props.name
}
}, {
local: require.resolve('../config')
});
}

if (!this.fs.exists(this.destinationPath('server/plugins/webapp'))) {
this.composeWith('electrode:webapp', {
options: {
Expand Down
32 changes: 32 additions & 0 deletions generators/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
var _ = require('lodash');
var generators = require('yeoman-generator');

module.exports = generators.Base.extend({
constructor: function () {
generators.Base.apply(this, arguments);

this.option('generateInto', {
type: String,
required: false,
defaults: '',
desc: 'Relocate the location of the generated files.'
});

this.option('name', {
type: String,
required: true,
desc: 'Project name'
});
},

writing: function () {
this.fs.copyTpl(
this.templatePath('default.json'),
this.destinationPath(this.options.generateInto, 'config/default.json'),
{
projectName: this.options.name
}
);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"webapp": {
"module": "./server/plugins/webapp",
"options": {
"pageTitle": "<%= projectName %>",
"paths": {
"/{args*}": {
"content": {
Expand Down
5 changes: 5 additions & 0 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,10 @@ describe('electrode:app', function () {
assert.fileContent('README.md', '© [Electrode](http://electrode.io)');
assert.fileContent('README.md', '[travis-image]: https://travis-ci.org/electrode-io/generator-electrode.svg?branch=master');
});

it('creates and fills the pageTitle field in config/default.json', function () {
assert.file('./config/default.json');
assert.fileContent('./config/default.json', '"pageTitle": "generator-electrode"');
});
});
});

0 comments on commit 7182ba6

Please sign in to comment.