Skip to content

Commit

Permalink
feat(root): add alias handler/invoker
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Jun 27, 2019
1 parent 48267bf commit b4048e2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const git = require('./lib/git');
const github = require('./lib/github');
const program = require('commander');
const conf = new (require('configstore'))('gitflow');
const exec = require('util').promisify(require('child_process').exec);

program.version(
JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json')))['version'] || 'test-mode', '-v, --version'
Expand Down Expand Up @@ -143,4 +144,29 @@ program
}
});

program.on('command:*', async (args) => {
const alias = args.shift();
const cmd = conf.get(`alias:${alias}`);

try {
if (!cmd) {
throw new Error(`Unknown command or alias: ${alias}`);
}

console.log(`> ${cmd} ${args.join(' ')}`);
const proc = await exec(`${cmd} ${args.join(' ')}`).catch((err) => err);

if (proc.stdout !== '') {
console.log(proc.stdout);
}
if (proc.stderr !== '') {
console.error(proc.stderr);
}

process.exit(proc.exitCode || proc.code);
} catch (e) {
console.log(e.message);
}
});

program.parse(process.argv);

0 comments on commit b4048e2

Please sign in to comment.