This commit is contained in:
rkiel
2019-07-18 15:40:37 -04:00
parent 48d64da20b
commit 308d62fc86
7 changed files with 90 additions and 86 deletions

17
js/branch.js Normal file
View File

@@ -0,0 +1,17 @@
let lib;
function standard() {
return ["master", "release"];
}
function isStandard(b) {
return lib.standard().includes(b);
}
function isNonStandard(b) {
return !lib.isStandard(b);
}
lib = { standard, isStandard, isNonStandard };
module.exports = lib;

View File

@@ -4,17 +4,27 @@ const something = program.parse(process.argv);
let lib;
function parse() {
return something;
}
function args() {
return something.args;
}
function featureName() {
return args().join("-");
}
function parse() {
return { program: something };
}
function prefix() {
return process.env.FEATURE_USER || process.env.USER;
}
lib = {
args,
parse
parse,
featureName,
prefix
};
module.exports = lib;

View File

@@ -9,7 +9,7 @@ let lib;
function setCurrentBranch(dp) {
const cmd = "git rev-parse --abbrev-ref HEAD";
return shell.capture(cmd).then(x => immutable.set(dp, "currentBranch", x));
return shell.capture(cmd).then(x => immutable.set(dp, "branch.current", x));
}
lib = {

View File

@@ -3,7 +3,7 @@ const _ = require("lodash");
let lib;
function set(dp, path, value) {
return _.assign({}, dp, _.set({}, path, value));
return _.set(_.assign({}, dp), path, value);
}
lib = {

View File

@@ -23,10 +23,24 @@ function something(cmd, dp) {
return lib.run(cmd).then(lib._something(dp));
}
function pipeline(cmds) {
return _.reduce(
cmds,
(accum, elem) => {
return accum
.then(() => console.log())
.then(() => console.log(elem))
.then(() => exec(elem));
},
Promise.resolve({})
).then(() => console.log());
}
lib = {
_something,
run,
capture,
pipeline,
something: _.curry(something)
};

23
js/validate.js Normal file
View File

@@ -0,0 +1,23 @@
const branch = path("js/branch");
let lib;
function validateCurrentBranch(dp) {
if (branch.isNonStandard(dp.branch.current)) {
throw `invalid base branch: ${dp.branch.current}`;
} else {
return dp;
}
}
function validateFeatureName(dp) {
if (branch.isStandard(commander.featureName())) {
throw `invalid feature branch: ${commander.featureName()}`;
} else {
return dp;
}
}
lib = { validateCurrentBranch, validateFeatureName };
module.exports = lib;