refactor
This commit is contained in:
20
js/commander.js
Normal file
20
js/commander.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const commander = require("commander");
|
||||
const program = new commander.Command();
|
||||
const something = program.parse(process.argv);
|
||||
|
||||
let lib;
|
||||
|
||||
function parse() {
|
||||
return something;
|
||||
}
|
||||
|
||||
function args() {
|
||||
return something.args;
|
||||
}
|
||||
|
||||
lib = {
|
||||
args,
|
||||
parse
|
||||
};
|
||||
|
||||
module.exports = lib;
|
||||
19
js/git.js
Normal file
19
js/git.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const _ = require("lodash");
|
||||
|
||||
const path = x => require("../" + x);
|
||||
const immutable = path("js/immutable");
|
||||
const shell = path("js/shell");
|
||||
|
||||
let lib;
|
||||
|
||||
function setCurrentBranch(dp) {
|
||||
const cmd = "git rev-parse --abbrev-ref HEAD";
|
||||
|
||||
return shell.capture(cmd).then(x => immutable.set(dp, "currentBranch", x));
|
||||
}
|
||||
|
||||
lib = {
|
||||
setCurrentBranch
|
||||
};
|
||||
|
||||
module.exports = lib;
|
||||
33
js/shell.js
Normal file
33
js/shell.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const _ = require("lodash");
|
||||
const util = require("util");
|
||||
const child_process = require("child_process");
|
||||
const exec = util.promisify(child_process.exec);
|
||||
|
||||
let lib;
|
||||
|
||||
function run(cmd) {
|
||||
return exec(cmd);
|
||||
}
|
||||
|
||||
function capture(cmd) {
|
||||
return lib.run(cmd).then(x => x.stdout.trim());
|
||||
}
|
||||
|
||||
function _something(dp) {
|
||||
return function() {
|
||||
return dp;
|
||||
};
|
||||
}
|
||||
|
||||
function something(cmd, dp) {
|
||||
return lib.run(cmd).then(lib._something(dp));
|
||||
}
|
||||
|
||||
lib = {
|
||||
_something,
|
||||
run,
|
||||
capture,
|
||||
something: _.curry(something)
|
||||
};
|
||||
|
||||
module.exports = lib;
|
||||
Reference in New Issue
Block a user