From fe909bf44f89f8af18fa0929252b41ae8a286e68 Mon Sep 17 00:00:00 2001 From: rkiel Date: Sat, 13 Jul 2019 15:31:43 -0400 Subject: [PATCH] node: started --- .gitignore | 1 + bin/creature | 8 ++++++ bin/creature-start | 61 ++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 13 ++++++++++ package.json | 26 ++++++++++++++++++++ 5 files changed, 109 insertions(+) create mode 100644 .gitignore create mode 100755 bin/creature create mode 100755 bin/creature-start create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/bin/creature b/bin/creature new file mode 100755 index 0000000..11e6229 --- /dev/null +++ b/bin/creature @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +const commander = require("commander"); +const program = new commander.Command(); + +program + .command("start feature-words", "start a new feature") + .parse(process.argv); diff --git a/bin/creature-start b/bin/creature-start new file mode 100755 index 0000000..cc106a8 --- /dev/null +++ b/bin/creature-start @@ -0,0 +1,61 @@ +#!/usr/bin/env node + +const commander = require("commander"); +const program = new commander.Command(); + +const util = require("util"); +const exec = util.promisify(require("child_process").exec); + +program.parse(process.argv); + +function setCurrentBranch(dp) { + return exec(`git branch|grep '\*'|sed 's/\*\s*//'`) + .then(x => x.stdout.trim()) + .then(x => Object.assign({}, dp, { currentBranch: x })); +} + +function setStandardBranches(dp) { + return Object.assign({}, dp, { standardBranches: ["master", "release"] }); +} + +function validateCurrentBranch(dp) { + if (!dp.standardBranches.includes(dp.currentBranch)) { + throw `invalid base branch: ${dp.currentBranch}`; + } else { + return dp; + } +} + +function validateFeatureBranch(dp) { + if (dp.standardBranches.includes(dp.featureName)) { + throw `invalid feature branch: ${dp.featureName}`; + } else { + return dp; + } +} + +function setFeatureName(dp) { + const fn = program.args.join("-"); + return Object.assign({}, dp, { featureName: fn }); +} + +function setPrefix(dp) { + const p = process.env.FEATURE_USER || process.env.USER; + return Object.assign({}, dp, { prefix: p }); +} + +function setFeatureBranch(dp) { + const fb = `${dp.prefix}-${dp.currentBranch}-${dp.featureName}`; + return Object.assign({}, dp, { featureBranch: fb }); +} + +const x = Promise.resolve({ program }) + .then(setStandardBranches) + .then(setFeatureName) + .then(setPrefix) + .then(setCurrentBranch) + .then(validateCurrentBranch) + .then(setFeatureBranch) + .then(validateFeatureBranch) + .then(x => console.log("x", x)) + .catch(err => console.error(err)); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e736f45 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "git-utilities", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "commander": { + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", + "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..2770ec4 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "git-utilities", + "version": "1.0.0", + "description": "This is a collection of simple command-line scripts, bash aliases, and bash utilities that make using `git` even easier.", + "main": "index.js", + "directories": { + "lib": "lib" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/rkiel/git-utilities.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/rkiel/git-utilities/issues" + }, + "homepage": "https://github.com/rkiel/git-utilities#readme", + "dependencies": { + "commander": "^2.20.0" + } +}