Skip to content

Commit

Permalink
feat(add options): ✨add push option
Browse files Browse the repository at this point in the history
  • Loading branch information
maguowei committed Jun 13, 2019
1 parent 4af3ab4 commit f94fc07
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 9 additions & 5 deletions commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,29 @@ const prepare = async () => {
return { needGitAddOrCommit };
};

const runTasks = async () => {
const execGitPush = async (push) => {
return push ? await gitPush : true;
};

const runTasks = async ({ push }) => {
const { needGitAddOrCommit } = await prepare();

if (!needGitAddOrCommit) {
logger.info('Nothing to add, working tree clean.');
logger.info('Nothing to commit, working tree clean.');
return await gitPush();
return await execGitPush(push);
}

const commitMessage = await prompt();
await gitAdd();
await gitCommit(commitMessage);
return await gitPush();
return await execGitPush(push);
};

module.exports = async () => {
module.exports = async (options) => {
try {
const startTime = getNow();
await runTasks();
await runTasks(options);
const endTime = getNow();
logger.success(`Done in ${(endTime - startTime) / 1000}s`);
process.exit(0);
Expand Down
14 changes: 12 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ const pkg = require('../package.json');
const index = require('../commands/index.js');

const configureYargs = () => {
return yargs.help().version().argv._;
return yargs
.options({
push: {
alias: 'p',
describe: 'exec git push',
default: true,
},
})
.help()
.version().argv._;
};

configureYargs();
const argv = yargs.argv;
updateNotifier({ pkg }).notify();
index().catch((ex) => {
index(argv).catch((ex) => {
throw ex;
});

0 comments on commit f94fc07

Please sign in to comment.