This commit is contained in:
rkiel
2019-07-18 16:09:29 -04:00
parent 308d62fc86
commit 2443a88ad7
4 changed files with 48 additions and 42 deletions

View File

@@ -3,36 +3,10 @@
const _ = require("lodash"); const _ = require("lodash");
const path = x => require("../" + x); const path = x => require("../" + x);
const immutable = path("js/immutable");
const git = path("js/git"); const git = path("js/git");
const shell = path("js/shell"); const shell = path("js/shell");
const commander = path("js/commander"); const commander = path("js/commander");
const branch = path("js/branch"); const validate = path("js/validate");
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;
}
}
function setFeatureBranch(dp) {
const fb = [
commander.prefix(),
dp.branch.current,
commander.featureName()
].join("-");
return immutable.set(dp, "branch.feature", fb);
}
function createFeatureBranch(dp) { function createFeatureBranch(dp) {
return shell.pipeline([ return shell.pipeline([
@@ -44,14 +18,11 @@ function createFeatureBranch(dp) {
]); ]);
} }
function toPromise(dp) { commander
return Promise.resolve(dp); .start()
}
const x = toPromise(commander.parse())
.then(validateFeatureName)
.then(git.setCurrentBranch) .then(git.setCurrentBranch)
.then(validateCurrentBranch) .then(validate.currentIsStandardBranch)
.then(setFeatureBranch) .then(git.setFeatureBranch)
.then(validate.featureIsNotStandardBranch)
.then(createFeatureBranch) .then(createFeatureBranch)
.catch(err => console.error(err)); .catch(err => console.error(err));

View File

@@ -20,11 +20,25 @@ function prefix() {
return process.env.FEATURE_USER || process.env.USER; return process.env.FEATURE_USER || process.env.USER;
} }
function toPromise(dp) {
return Promise.resolve(dp);
}
function echo(dp) {
console.log(JSON.stringify(dp));
return dp;
}
function start() {
return toPromise(parse());
}
lib = { lib = {
args, args,
parse, parse,
featureName, featureName,
prefix prefix,
start
}; };
module.exports = lib; module.exports = lib;

View File

@@ -1,6 +1,7 @@
const _ = require("lodash"); const _ = require("lodash");
const path = x => require("../" + x); const path = x => require("../" + x);
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");
@@ -12,8 +13,18 @@ function setCurrentBranch(dp) {
return shell.capture(cmd).then(x => immutable.set(dp, "branch.current", x)); return shell.capture(cmd).then(x => immutable.set(dp, "branch.current", x));
} }
function setFeatureBranch(dp) {
const fb = [
commander.prefix(),
dp.branch.current,
commander.featureName()
].join("-");
return immutable.set(dp, "branch.feature", fb);
}
lib = { lib = {
setCurrentBranch setCurrentBranch,
setFeatureBranch
}; };
module.exports = lib; module.exports = lib;

View File

@@ -1,23 +1,33 @@
const path = x => require("../" + x);
const branch = path("js/branch"); const branch = path("js/branch");
const commander = path("js/commander");
let lib; let lib;
function validateCurrentBranch(dp) { function currentIsStandardBranch(dp) {
if (branch.isNonStandard(dp.branch.current)) { if (branch.isNonStandard(dp.branch.current)) {
throw `invalid base branch: ${dp.branch.current}`; const branches = branch
.standard()
.sort()
.join(", ");
throw `ERROR: starting branch must be one of: ${branches}`;
} else { } else {
return dp; return dp;
} }
} }
function validateFeatureName(dp) { function featureIsNotStandardBranch(dp) {
if (branch.isStandard(commander.featureName())) { if (branch.isStandard(commander.featureName())) {
throw `invalid feature branch: ${commander.featureName()}`; const branches = branch
.standard()
.sort()
.join(", ");
throw `ERROR: feature branch cannot be any of: ${branches}`;
} else { } else {
return dp; return dp;
} }
} }
lib = { validateCurrentBranch, validateFeatureName }; lib = { currentIsStandardBranch, featureIsNotStandardBranch };
module.exports = lib; module.exports = lib;