Skip to content

Commit

Permalink
generator only ask yes/no if running from menu (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip authored Oct 6, 2017
1 parent 2baf9ce commit ef19d4f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/electrode-ignite/lib/menu-items/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

const { MenuItem, helpers, logger } = require("ignite-core");
const doYo = require("../do-yo");
const Promise = require("bluebird");

module.exports = function(name, itemOptions) {
function execute(options) {
return helpers.yesNoPrompt(itemOptions.menuText).then(yes => {
const promise = options.menu._clap
? Promise.resolve(true)
: helpers.yesNoPrompt(itemOptions.menuText);

return promise.then(yes => {
if (yes) {
options.menu.emit("done");
logger.log(`Loading generator ${name} ...`);
Expand Down
10 changes: 8 additions & 2 deletions packages/electrode-ignite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electrode-ignite",
"version": "0.1.25",
"version": "0.1.27",
"description": "The CLI tool for development with OSS Electrode React/NodeJS Platform.",
"main": "bin/ignite.js",
"scripts": {
Expand Down Expand Up @@ -61,6 +61,12 @@
"test",
"bin",
"cli"
]
],
"check-coverage": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100,
"cache": true
}
}
22 changes: 22 additions & 0 deletions packages/electrode-ignite/test/spec/menu-items/generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ describe("menu-item generator", function() {
});
});

it("should not prompt user and run generator in clap mode", () => {
const runStub = sinon.stub(doYo, "run");
const yesNoStub = sinon.stub(helpers, "yesNoPrompt").returns(Promise.resolve(true));
expect(generatorItem).to.exist;
const mi = generatorItem("test", {
menuText: "test item"
});
return mi
.execute({
menu: {
_clap: true,
emit: evt => expect(evt).to.equal("done")
}
})
.finally(() => {
runStub.restore();
yesNoStub.restore();
expect(yesNoStub.callCount).to.equal(0);
expect(runStub.calledOnce).to.be.true;
});
});

it("should not run generator if user answered no", () => {
const runStub = sinon.stub(doYo, "run");

Expand Down

0 comments on commit ef19d4f

Please sign in to comment.