refactor
This commit is contained in:
17
js/branch.js
Normal file
17
js/branch.js
Normal 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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
14
js/shell.js
14
js/shell.js
@@ -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
23
js/validate.js
Normal 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;
|
||||
Reference in New Issue
Block a user