refactor
This commit is contained in:
@@ -3,36 +3,10 @@
|
||||
const _ = require("lodash");
|
||||
|
||||
const path = x => require("../" + x);
|
||||
const immutable = path("js/immutable");
|
||||
const git = path("js/git");
|
||||
const shell = path("js/shell");
|
||||
const commander = path("js/commander");
|
||||
const branch = path("js/branch");
|
||||
|
||||
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);
|
||||
}
|
||||
const validate = path("js/validate");
|
||||
|
||||
function createFeatureBranch(dp) {
|
||||
return shell.pipeline([
|
||||
@@ -44,14 +18,11 @@ function createFeatureBranch(dp) {
|
||||
]);
|
||||
}
|
||||
|
||||
function toPromise(dp) {
|
||||
return Promise.resolve(dp);
|
||||
}
|
||||
|
||||
const x = toPromise(commander.parse())
|
||||
.then(validateFeatureName)
|
||||
commander
|
||||
.start()
|
||||
.then(git.setCurrentBranch)
|
||||
.then(validateCurrentBranch)
|
||||
.then(setFeatureBranch)
|
||||
.then(validate.currentIsStandardBranch)
|
||||
.then(git.setFeatureBranch)
|
||||
.then(validate.featureIsNotStandardBranch)
|
||||
.then(createFeatureBranch)
|
||||
.catch(err => console.error(err));
|
||||
|
||||
@@ -20,11 +20,25 @@ function prefix() {
|
||||
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 = {
|
||||
args,
|
||||
parse,
|
||||
featureName,
|
||||
prefix
|
||||
prefix,
|
||||
start
|
||||
};
|
||||
|
||||
module.exports = lib;
|
||||
|
||||
13
js/git.js
13
js/git.js
@@ -1,6 +1,7 @@
|
||||
const _ = require("lodash");
|
||||
|
||||
const path = x => require("../" + x);
|
||||
const commander = path("js/commander");
|
||||
const immutable = path("js/immutable");
|
||||
const shell = path("js/shell");
|
||||
|
||||
@@ -12,8 +13,18 @@ function setCurrentBranch(dp) {
|
||||
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 = {
|
||||
setCurrentBranch
|
||||
setCurrentBranch,
|
||||
setFeatureBranch
|
||||
};
|
||||
|
||||
module.exports = lib;
|
||||
|
||||
@@ -1,23 +1,33 @@
|
||||
const path = x => require("../" + x);
|
||||
const branch = path("js/branch");
|
||||
const commander = path("js/commander");
|
||||
|
||||
let lib;
|
||||
|
||||
function validateCurrentBranch(dp) {
|
||||
function currentIsStandardBranch(dp) {
|
||||
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 {
|
||||
return dp;
|
||||
}
|
||||
}
|
||||
|
||||
function validateFeatureName(dp) {
|
||||
function featureIsNotStandardBranch(dp) {
|
||||
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 {
|
||||
return dp;
|
||||
}
|
||||
}
|
||||
|
||||
lib = { validateCurrentBranch, validateFeatureName };
|
||||
lib = { currentIsStandardBranch, featureIsNotStandardBranch };
|
||||
|
||||
module.exports = lib;
|
||||
|
||||
Reference in New Issue
Block a user