Skip to content

Commit

Permalink
Merge pull request #14364 from mshima/skip_ci_blueprint_options
Browse files Browse the repository at this point in the history
Fix loading of blueprint options.
  • Loading branch information
DanielFran authored Mar 17, 2021
2 parents 85eadcd + 30b612a commit 9aa8bc3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const buildCommands = ({ program, commands = {}, envBuilder, env, loadCommand })
chalk.yellow(` (blueprint option: ${blueprintName})`)
);
} catch (error) {
logger.info(`Error parsing options for generator ${generatorNamespace}, unknown option will lead to error at jhipster 7`);
logger.info(`Error parsing options for generator ${generatorNamespace}, error: ${error}`);
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions generators/generator-base-blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ module.exports = class JHipsterBaseBlueprintGenerator extends BaseGenerator {
constructor(args, opts, features) {
super(args, opts, features);

if (this.options.help) {
return;
}

// Add base template folder.
this.jhipsterTemplatesFolders = [this.templatePath()];

Expand Down
21 changes: 20 additions & 1 deletion test/cli/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ describe('jhipster cli', () => {
});
});

describe('using blueprint with generator option', () => {
describe('using blueprint with custom generator option', () => {
let stdout;
beforeEach(done => {
const tmpdir = process.cwd();
Expand All @@ -452,6 +452,25 @@ describe('jhipster cli', () => {
expect(stdout.includes('foo description')).to.be.true;
});
});

describe('using blueprint with blueprinted generator option', () => {
let stdout;
beforeEach(done => {
const tmpdir = process.cwd();
copyFakeBlueprint(tmpdir, 'bar');
lnYeoman(tmpdir);
const forked = fork(jhipsterCli, ['app', '--blueprints', 'bar', '--help'], { stdio: 'pipe', cwd: tmpdir });
forked.on('exit', () => {
stdout = forked.stdout.read().toString();
done();
});
});

it('should print foo-bar option', () => {
expect(stdout).to.include('--foo-bar');
expect(stdout).to.include('Sample option (blueprint option: bar)');
});
});
});
});

Expand Down
49 changes: 49 additions & 0 deletions test/templates/fake-blueprint/generators/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const createGenerator = env => class extends env.requireGenerator('jhipster:app') {
constructor(args, opts) {
super(args, { fromBlueprint: true, ...opts }); // fromBlueprint variable is important

this.option('foo-bar', {
desc: 'Sample option',
type: Boolean,
});

if (this.options.help) {
return;
}

const jhContext = (this.jhipsterContext = this.options.jhipsterContext);
if (!jhContext) {
this.error("This is a JHipster blueprint and should be used only like 'jhipster --blueprints myblueprint')}");
}
}

get initializing() {
return super._initializing();
}

get prompting() {
return super._prompting();
}

get configuring() {
return super._configuring();
}

get default() {
return super._default();
}

get writing() {
return super._writing();
}

get install() {
return super._install();
}

get end() {
return super._end();
}
};

module.exports = { createGenerator };

0 comments on commit 9aa8bc3

Please sign in to comment.