Skip to content

Commit

Permalink
Get and run module generators (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoScabbiolo authored and SBoudrias committed May 31, 2018
1 parent bb3941a commit 98f2f87
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ class Environment extends EventEmitter {

const Generator = this.get(namespace);

if (typeof Generator !== 'undefined' && typeof Generator.default === 'function') {
return this.instantiate(Generator.default, options);
}

if (typeof Generator !== 'function') {
let generatorHint = '';
if (isScoped(namespace)) {
Expand Down
13 changes: 13 additions & 0 deletions test/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ describe('Environment', () => {
});
this.env.run('@dummyscope/package');
});

it('runs a module generator', function () {
this.env
.register(path.join(__dirname, './fixtures/generator-module/generators/app'), 'fixtures:generator-module');
this.env.run('fixtures:generator-module');
});
});

describe('#registerModulePath()', () => {
Expand Down Expand Up @@ -481,6 +487,13 @@ describe('Environment', () => {
assert.equal(this.env.get('not:there'), undefined);
assert.equal(this.env.get(), undefined);
});

it('works with modules', function () {
const generator = require('./fixtures/generator-module/generators/app');
this.env
.register(path.join(__dirname, './fixtures/generator-module/generators/app'), 'fixtures:generator-module');
assert.equal(this.env.get('fixtures:generator-module'), generator);
});
});

describe('#error()', () => {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/generator-module/generators/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var Generator = require('yeoman-generator');
exports.default = class extends Generator {
exec() {

}
};
11 changes: 11 additions & 0 deletions test/fixtures/generator-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"author": "",
"name": "generator-module",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {},
"optionalDependencies": {},
"engines": {
"node": "*"
}
}

0 comments on commit 98f2f87

Please sign in to comment.