Skip to content

Commit

Permalink
adding -a and --activate flags to stencil push
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaPuza committed May 3, 2018
1 parent c5ebee8 commit 5f2ceb8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
2 changes: 2 additions & 0 deletions bin/stencil-push
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Program
.option('--host [hostname]', 'specify the api host', apiHost)
.option('-f, --file [filename]', 'specify the filename of the bundle to upload')
.option('-s, --save [filename]', 'specify the filename to save the bundle as')
.option('-a, --activate [variationname]', 'specify the variation of the theme to activate')
.parse(process.argv);

if (!versionCheck()) {
Expand All @@ -23,6 +24,7 @@ if (!versionCheck()) {
stencilPush(Object.assign({}, options, {
apiHost: Program.host || apiHost,
bundleZipPath: Program.file,
activate: Program.activate,
saveBundleName: Program.save
}), (err, result) => {
if (err) {
Expand Down
62 changes: 38 additions & 24 deletions lib/stencil-push.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,20 @@ utils.checkIfJobIsComplete = (options, callback) => {
};

utils.promptUserWhetherToApplyTheme = (options, callback) => {
const questions = [{
type: 'confirm',
name: 'applyTheme',
message: `Would you like to apply your theme to your store at ${options.config.normalStoreUrl}?`,
default: false,
}];

Inquirer.prompt(questions, answers => {
callback(null, Object.assign({}, options, { applyTheme: answers.applyTheme }));
});
if (options.activate) {
callback(null, Object.assign({}, options, { applyTheme: true }));
} else {
const questions = [{
type: 'confirm',
name: 'applyTheme',
message: `Would you like to apply your theme to your store at ${options.config.normalStoreUrl}?`,
default: false,
}];

Inquirer.prompt(questions, answers => {
callback(null, Object.assign({}, options, { applyTheme: answers.applyTheme }));
});
};
};

utils.getVariations = (options, callback) => {
Expand All @@ -287,9 +291,15 @@ utils.getVariations = (options, callback) => {
}, (error, result) => {
if (error) {
return callback(error);
}

callback(null, Object.assign({}, options, result));
};
if (options.activate !== true && options.activate !== undefined) {
const findVariation = result.variations.find(item => item.name === options.activate);
callback(null, Object.assign({}, options, { variationId: findVariation.uuid }));
} else if (options.activate === true) {
callback(null, Object.assign({}, options, { variationId: result.variations[0].uuid }));
} else {
callback(null, Object.assign({}, options, result));
};
});
};

Expand All @@ -298,16 +308,20 @@ utils.promptUserForVariation = (options, callback) => {
return async.nextTick(callback.bind(null, null, options))
}

const questions = [{
type: 'list',
name: 'variationId',
message: 'Which variation would you like to apply?',
choices: options.variations.map(variation => ({ name: variation.name, value: variation.uuid })),
}];

Inquirer.prompt(questions, answers => {
callback(null, Object.assign({}, options, answers));
});
if (options.variationId) {
callback(null, options);
} else {
const questions = [{
type: 'list',
name: 'variationId',
message: 'Which variation would you like to apply?',
choices: options.variations.map(variation => ({ name: variation.name, value: variation.uuid })),
}];

Inquirer.prompt(questions, answers => {
callback(null, Object.assign({}, options, answers));
});
};
};

utils.requestToApplyVariationWithRetrys = () => {
Expand Down Expand Up @@ -347,4 +361,4 @@ utils.requestToApplyVariation = (options, callback) => {

utils.notifyUserOfCompletion = (options, callback) => {
callback(null, 'Stencil Push Finished');
};
};

0 comments on commit 5f2ceb8

Please sign in to comment.