refactor: new direction
This commit is contained in:
@@ -22,10 +22,12 @@ function endFeatureBranch(dp) {
|
|||||||
|
|
||||||
commander
|
commander
|
||||||
.start()
|
.start()
|
||||||
.then(git.setCurrentBranch)
|
.then(git.gather)
|
||||||
.then(git.parseCurrentBranch)
|
.then(commander.echo)
|
||||||
.then(validate.mustBeFeatureBranch)
|
// .then(git.setCurrentBranch)
|
||||||
.then(git.setStandardBranch)
|
// .then(git.parseCurrentBranch)
|
||||||
.then(git.isBranchRemote)
|
// .then(validate.mustBeFeatureBranch)
|
||||||
.then(endFeatureBranch)
|
// .then(git.setStandardBranch)
|
||||||
|
// .then(git.isBranchRemote)
|
||||||
|
// .then(endFeatureBranch)
|
||||||
.catch(err => console.error(err));
|
.catch(err => console.error(err));
|
||||||
|
|||||||
17
js/file.js
Normal file
17
js/file.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const util = require("util");
|
||||||
|
|
||||||
|
let lib;
|
||||||
|
|
||||||
|
function exists(path) {
|
||||||
|
const stat = util.promisify(fs.stat);
|
||||||
|
return stat(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
function read(path) {
|
||||||
|
const readFile = util.promisify(fs.readFile);
|
||||||
|
return readFile(path).then(buffer => buffer.toString("utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
lib = { exists, read };
|
||||||
|
module.exports = lib;
|
||||||
86
js/git.js
86
js/git.js
@@ -4,15 +4,84 @@ const path = x => require("../" + x);
|
|||||||
const commander = path("js/commander");
|
const commander = path("js/commander");
|
||||||
const immutable = path("js/immutable");
|
const immutable = path("js/immutable");
|
||||||
const shell = path("js/shell");
|
const shell = path("js/shell");
|
||||||
|
const file = path("js/file");
|
||||||
|
const branch = path("js/branch");
|
||||||
|
|
||||||
let lib;
|
let lib;
|
||||||
|
|
||||||
function setCurrentBranch(dp) {
|
function setBranch(dp, field, branch) {
|
||||||
const cmd = "git rev-parse --abbrev-ref HEAD";
|
return immutable.set(dp, `branch.${field}`, branch);
|
||||||
|
|
||||||
return shell.capture(cmd).then(x => immutable.set(dp, "branch.current", x));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setCurrentBranch(dp) {
|
||||||
|
return file
|
||||||
|
.read(".git/HEAD")
|
||||||
|
.then(contents => contents.split("/"))
|
||||||
|
.then(parts => _.last(parts))
|
||||||
|
.then(last => last.trim())
|
||||||
|
.then(branch => immutable.set(dp, "branch.current", branch));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setStandardAndFeature(dp) {
|
||||||
|
const current = _.get(dp, "branch.current");
|
||||||
|
if (branch.isStandard(current)) {
|
||||||
|
return immutable.set(
|
||||||
|
immutable.set(dp, "branch.standard", current),
|
||||||
|
"branch.feature",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const parts = current.split("-");
|
||||||
|
if (
|
||||||
|
parts.length > 2 &&
|
||||||
|
commander.prefix() === parts[0] &&
|
||||||
|
branch.isStandard(parts[1])
|
||||||
|
) {
|
||||||
|
return immutable.set(
|
||||||
|
immutable.set(dp, "branch.standard", parts[1]),
|
||||||
|
"branch.feature",
|
||||||
|
current
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return immutable.set(
|
||||||
|
immutable.set(dp, "branch.standard", false),
|
||||||
|
"branch.feature",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setRemote(dp) {
|
||||||
|
const current = _.get(dp, "branch.current");
|
||||||
|
if (branch.isStandard(current)) {
|
||||||
|
return immutable.set(dp, "branch.remote", false);
|
||||||
|
} else {
|
||||||
|
return file
|
||||||
|
.exists(`.git/refs/remotes/origin/${current}`)
|
||||||
|
.then(() => immutable.set(dp, "branch.remote", current))
|
||||||
|
.catch(() => immutable.set(dp, "branch.remote", false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function gather(dp) {
|
||||||
|
return file
|
||||||
|
.exists(".git")
|
||||||
|
.then(() => ({}))
|
||||||
|
.then(lib.setCurrentBranch)
|
||||||
|
.then(lib.setStandardAndFeature)
|
||||||
|
.then(lib.setRemote)
|
||||||
|
.catch(() => {
|
||||||
|
throw "not in GIT_ROOT";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// function setCurrentBranch(dp) {
|
||||||
|
// const cmd = "git rev-parse --abbrev-ref HEAD";
|
||||||
|
//
|
||||||
|
// return shell.capture(cmd).then(x => immutable.set(dp, "branch.current", x));
|
||||||
|
// }
|
||||||
|
|
||||||
function setFeatureBranch(dp) {
|
function setFeatureBranch(dp) {
|
||||||
const fb = [
|
const fb = [
|
||||||
commander.prefix(),
|
commander.prefix(),
|
||||||
@@ -46,11 +115,16 @@ function isBranchRemote(dp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lib = {
|
lib = {
|
||||||
setCurrentBranch,
|
//setCurrentBranch,
|
||||||
setFeatureBranch,
|
setFeatureBranch,
|
||||||
setStandardBranch,
|
setStandardBranch,
|
||||||
parseCurrentBranch,
|
parseCurrentBranch,
|
||||||
isBranchRemote
|
isBranchRemote,
|
||||||
|
gather,
|
||||||
|
setStandardAndFeature,
|
||||||
|
setCurrentBranch,
|
||||||
|
setRemote,
|
||||||
|
setBranch: _.curry(setBranch)
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = lib;
|
module.exports = lib;
|
||||||
|
|||||||
Reference in New Issue
Block a user