This commit is contained in:
rkiel
2019-07-14 22:04:17 -04:00
parent 4c4a16af04
commit 604d3d84c4
4 changed files with 85 additions and 24 deletions

View File

@@ -1,23 +1,12 @@
#!/usr/bin/env node #!/usr/bin/env node
const _ = require("lodash"); const _ = require("lodash");
const path = x => require("../" + x); const path = x => require("../" + x);
const immutable = path("js/immutable"); const immutable = path("js/immutable");
const git = path("js/git");
const commander = require("commander"); const shell = path("js/shell");
const program = new commander.Command(); const commander = path("js/commander");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
program.parse(process.argv);
function setCurrentBranch(dp) {
const cmd = "git rev-parse --abbrev-ref HEAD";
return exec(cmd)
.then(x => x.stdout.trim())
.then(x => Object.assign({}, dp, { currentBranch: x }));
}
function setStandardBranches(dp) { function setStandardBranches(dp) {
return immutable.set(dp, "standardBranches", ["master", "release"]); return immutable.set(dp, "standardBranches", ["master", "release"]);
@@ -40,7 +29,7 @@ function validateFeatureName(dp) {
} }
function setFeatureName(dp) { function setFeatureName(dp) {
const fn = program.args.join("-"); const fn = commander.args().join("-");
return Object.assign({}, dp, { featureName: fn }); return Object.assign({}, dp, { featureName: fn });
} }
@@ -57,7 +46,7 @@ function setFeatureBranch(dp) {
function gitFetch(dp) { function gitFetch(dp) {
const cmd = "git fetch origin -p && git fetch origin --tags"; const cmd = "git fetch origin -p && git fetch origin --tags";
console.log(cmd); console.log(cmd);
return exec(cmd).then(x => dp); return shell.something(cmd, dp);
} }
function setMergeBranch(dp) { function setMergeBranch(dp) {
@@ -71,25 +60,25 @@ function setMergeBranch(dp) {
function gitMerge(dp) { function gitMerge(dp) {
const cmd = `git merge ${dp.mergeBranch}`; const cmd = `git merge ${dp.mergeBranch}`;
console.log(cmd); console.log(cmd);
return exec(cmd).then(x => dp); return shell.something(cmd, dp);
} }
function gitBranch(dp) { function gitBranch(dp) {
const cmd = `git branch ${dp.featureBranch}`; const cmd = `git branch ${dp.featureBranch}`;
console.log(cmd); console.log(cmd);
return exec(cmd).then(x => dp); return shell.something(cmd, dp);
} }
function gitCheckout(dp) { function gitCheckout(dp) {
const cmd = `git checkout ${dp.featureBranch}`; const cmd = `git checkout ${dp.featureBranch}`;
console.log(cmd); console.log(cmd);
return exec(cmd).then(x => dp); return shell.something(cmd, dp);
} }
function gitPush(dp) { function gitPush(dp) {
const cmd = `git push -u origin ${dp.featureBranch}`; const cmd = `git push -u origin ${dp.featureBranch}`;
console.log(cmd); console.log(cmd);
return exec(cmd).then(x => dp); return shell.something(cmd, dp);
} }
function createFeatureBranch(dp) { function createFeatureBranch(dp) {
@@ -106,7 +95,7 @@ function createFeatureBranch(dp) {
return accum return accum
.then(() => console.log(elem)) .then(() => console.log(elem))
.then(() => console.log()) .then(() => console.log())
.then(() => exec(elem)); .then(() => shell.run(elem));
}, },
Promise.resolve({}) Promise.resolve({})
); );
@@ -116,12 +105,12 @@ function toPromise(dp) {
return Promise.resolve(dp); return Promise.resolve(dp);
} }
const x = toPromise({ program }) const x = toPromise({ program: commander.parse() })
.then(setStandardBranches) .then(setStandardBranches)
.then(setFeatureName) .then(setFeatureName)
.then(validateFeatureName) .then(validateFeatureName)
.then(setPrefix) .then(setPrefix)
.then(setCurrentBranch) .then(git.setCurrentBranch)
.then(validateCurrentBranch) .then(validateCurrentBranch)
.then(setFeatureBranch) .then(setFeatureBranch)
.then(createFeatureBranch) .then(createFeatureBranch)

20
js/commander.js Normal file
View 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
View 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
View 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;