Files
git-utilities/bin/creature-start
2019-07-18 15:40:37 -04:00

58 lines
1.3 KiB
JavaScript
Executable File

#!/usr/bin/env node
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);
}
function createFeatureBranch(dp) {
return shell.pipeline([
"git fetch --prune --prune-tags --tags origin",
`git merge origin/${dp.branch.current}`,
"git push",
`git checkout -b ${dp.branch.feature}`,
`git push -u origin ${dp.branch.feature}`
]);
}
function toPromise(dp) {
return Promise.resolve(dp);
}
const x = toPromise(commander.parse())
.then(validateFeatureName)
.then(git.setCurrentBranch)
.then(validateCurrentBranch)
.then(setFeatureBranch)
.then(createFeatureBranch)
.catch(err => console.error(err));