From 7182ba6144481cf7d03db9e7f5fb7d262b4d52b2 Mon Sep 17 00:00:00 2001 From: Kostas Bariotis Date: Wed, 26 Oct 2016 00:03:52 +0300 Subject: [PATCH] create subgenerator for config/default.json file, resolve #28 --- generators/app/index.js | 10 ++++++ generators/config/index.js | 32 +++++++++++++++++++ .../config => config/templates}/default.json | 1 + test/app.js | 5 +++ 4 files changed, 48 insertions(+) create mode 100644 generators/config/index.js rename generators/{app/templates/config => config/templates}/default.json (90%) diff --git a/generators/app/index.js b/generators/app/index.js index 80c1712..84bbb2e 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -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: { diff --git a/generators/config/index.js b/generators/config/index.js new file mode 100644 index 0000000..09e2e4a --- /dev/null +++ b/generators/config/index.js @@ -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 + } + ); + } +}); diff --git a/generators/app/templates/config/default.json b/generators/config/templates/default.json similarity index 90% rename from generators/app/templates/config/default.json rename to generators/config/templates/default.json index c8556e8..683ad87 100644 --- a/generators/app/templates/config/default.json +++ b/generators/config/templates/default.json @@ -12,6 +12,7 @@ "webapp": { "module": "./server/plugins/webapp", "options": { + "pageTitle": "<%= projectName %>", "paths": { "/{args*}": { "content": { diff --git a/test/app.js b/test/app.js index 63c4a8f..1967f53 100644 --- a/test/app.js +++ b/test/app.js @@ -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"'); + }); }); });