Skip to content

Commit

Permalink
Fix generating the generator
Browse files Browse the repository at this point in the history
Using `namespace` leads to `this.options.namespace ===  'generator:subgenerator'` instead of `this.options.namespace ===  'app'`
  • Loading branch information
mischah committed Dec 3, 2016
1 parent f66b24b commit a9fc6c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/index.js
Expand Up @@ -56,7 +56,7 @@ module.exports = class extends Generator {
});

this.composeWith(require.resolve('../subgenerator'), {
namespace: 'app'
name: 'app'
});
}

Expand Down
17 changes: 11 additions & 6 deletions subgenerator/index.js
Expand Up @@ -7,10 +7,15 @@ module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);

this.option('namespace', {
this.log('arguments', arguments);
this.log('args', args);
this.log('opts', opts);
this.log(' this.options.name', this.options.name);

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

Expand All @@ -19,7 +24,7 @@ module.exports = class extends Generator {

this.fs.copyTpl(
this.templatePath('index.js'),
this.destinationPath(path.join('generators', this.options.namespace, 'index.js')),
this.destinationPath(path.join('generators', this.options.name, 'index.js')),
{
// Escape apostrophes from superb to not conflict with JS strings
superb: superb().replace('\'', '\\\''),
Expand All @@ -29,14 +34,14 @@ module.exports = class extends Generator {

this.fs.copy(
this.templatePath('templates/**'),
this.destinationPath(path.join('generators', this.options.namespace, 'templates'))
this.destinationPath(path.join('generators', this.options.name, 'templates'))
);

this.fs.copyTpl(
this.templatePath('test.js'),
this.destinationPath('test/' + this.options.namespace + '.js'),
this.destinationPath('test/' + this.options.name + '.js'),
{
namespace: this.options.namespace,
name: this.options.name,
generatorName: generatorName
}
);
Expand Down
4 changes: 2 additions & 2 deletions subgenerator/templates/test.js
Expand Up @@ -3,9 +3,9 @@ var path = require('path');
var assert = require('yeoman-assert');
var helpers = require('yeoman-test');

describe('<%- generatorName %>:<%- namespace %>', function () {
describe('<%- generatorName %>:<%- name %>', function () {
before(function () {
return helpers.run(path.join(__dirname, '../generators/<%- namespace %>'))
return helpers.run(path.join(__dirname, '../generators/<%- name %>'))
.withPrompts({someAnswer: true})
.toPromise();
});
Expand Down
6 changes: 4 additions & 2 deletions test/subgenerator.js
Expand Up @@ -17,8 +17,10 @@ describe('generator:subgenerator', function () {
});

return helpers.run(path.join(__dirname, '../subgenerator'))
.withArguments(['foo'])
.withOptions({force: true})
.withOptions({
name: 'foo',
force: true
})
.inTmpDir(function (tmpDir) {
fs.writeFileSync(
path.join(tmpDir, 'package.json'),
Expand Down

0 comments on commit a9fc6c5

Please sign in to comment.