balm-git-flow
Advanced tools
Comparing version 0.9.3-legacy to 0.10.0-legacy
@@ -12,3 +12,4 @@ #!/usr/bin/env node | ||
const { main, release, releases, scripts } = getConfig(); | ||
const { main, release, releases, scripts, releaseScripts, useCustomMessage } = | ||
getConfig(); | ||
@@ -39,3 +40,6 @@ const prompt = inquirer.createPromptModule(); | ||
choices: devBranches, | ||
when: release.includes(releaseBranch) && currentBranch === main | ||
when: | ||
release.includes(releaseBranch) && | ||
currentBranch === main && | ||
devBranches.length > 1 | ||
}, | ||
@@ -46,33 +50,39 @@ { | ||
message: 'Please select the command of npm-run-script:', | ||
default: () => { | ||
const index = releases.indexOf(releaseBranch); | ||
return scripts[index]; | ||
}, | ||
choices: scripts | ||
choices: scripts, | ||
when: | ||
!releaseScripts && | ||
scripts.length > 1 && | ||
scripts.length !== releases.length | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'ok', | ||
message: ({ releaseScript }) => { | ||
let msg = `Determine the release '${releaseBranch}' branch`; | ||
if (releaseScript) { | ||
msg += ` using the '${releaseScript}' command`; | ||
} | ||
return `${msg}?`; | ||
} | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'logMessage', | ||
message: 'Please input the release log message:' | ||
message: '(Optional) Please input the release log message:', | ||
when: useCustomMessage | ||
} | ||
]).then( | ||
(answers) => | ||
answers.ok && | ||
deployProject({ | ||
currentBranch, | ||
releaseBranch, | ||
...answers | ||
}) | ||
); | ||
]).then((answers) => { | ||
switch (scripts.length) { | ||
case 1: | ||
answers.releaseScript = scripts[0]; | ||
break; | ||
case releases.length: | ||
const index = releases.indexOf(releaseBranch); | ||
answers.releaseScript = scripts[index]; | ||
break; | ||
default: | ||
for (let i = 0, len = scripts.length; i < len; i++) { | ||
const script = scripts[i]; | ||
if (releaseScripts[script].includes(releaseBranch)) { | ||
answers.releaseScript = script; | ||
break; | ||
} | ||
} | ||
} | ||
deployProject({ | ||
currentBranch, | ||
releaseBranch, | ||
...answers | ||
}); | ||
}); | ||
} else { | ||
@@ -79,0 +89,0 @@ fatal( |
@@ -22,10 +22,17 @@ "use strict"; | ||
scripts: ['build'], | ||
releaseScripts: false, | ||
buildDir: 'dist', | ||
ignoreUncommitted: false, | ||
useCustomMessage: false, | ||
repositories: [], | ||
site: '' | ||
}; | ||
var defaultContents = ["process.env.BALM_GIT_FLOW_MAIN = 'main';", "process.env.BALM_GIT_FLOW_RELEASE = 'release';", "process.env.BALM_GIT_FLOW_RELEASES = ['release'];", "process.env.BALM_GIT_FLOW_SCRIPTS = ['build'];", "process.env.BALM_GIT_FLOW_BUILD_DIR = 'dist';", "// process.env.BALM_GIT_FLOW_REPOSITORIES = [];", "// process.env.BALM_GIT_FLOW_SITE = '';"]; | ||
var defaultContents = ["process.env.BALM_GIT_FLOW_MAIN = 'main';", "process.env.BALM_GIT_FLOW_RELEASE = 'release';", "process.env.BALM_GIT_FLOW_RELEASES = ['release'];", "process.env.BALM_GIT_FLOW_SCRIPTS = ['build'];", "process.env.BALM_GIT_FLOW_BUILD_DIR = 'dist';"]; | ||
exports.defaultContents = defaultContents; | ||
var options = {}; | ||
function setConfig() { | ||
var boolRegex = /^true$/i; | ||
var releaseScripts = _nodeProcess.env.BALM_GIT_FLOW_RELEASE_SCRIPTS ? JSON.parse(_nodeProcess.env.BALM_GIT_FLOW_RELEASE_SCRIPTS) : {}; | ||
var releases = Object.values(releaseScripts).flat(); | ||
var scripts = Object.keys(releaseScripts); | ||
options = { | ||
@@ -35,5 +42,8 @@ debug: _nodeProcess.env.BALM_GIT_FLOW_DEBUG || false, | ||
release: _nodeProcess.env.BALM_GIT_FLOW_RELEASE ? _nodeProcess.env.BALM_GIT_FLOW_RELEASE.split(',') : [defaultOptions.release], | ||
releases: _nodeProcess.env.BALM_GIT_FLOW_RELEASES ? _nodeProcess.env.BALM_GIT_FLOW_RELEASES.split(',') : defaultOptions.releases, | ||
scripts: _nodeProcess.env.BALM_GIT_FLOW_SCRIPTS ? _nodeProcess.env.BALM_GIT_FLOW_SCRIPTS.split(',') : defaultOptions.scripts, | ||
releases: _nodeProcess.env.BALM_GIT_FLOW_RELEASES ? _nodeProcess.env.BALM_GIT_FLOW_RELEASES.split(',') : releases || defaultOptions.releases, | ||
scripts: _nodeProcess.env.BALM_GIT_FLOW_SCRIPTS ? _nodeProcess.env.BALM_GIT_FLOW_SCRIPTS.split(',') : scripts || defaultOptions.scripts, | ||
releaseScripts: releaseScripts, | ||
buildDir: _nodeProcess.env.BALM_GIT_FLOW_BUILD_DIR || defaultOptions.buildDir, | ||
ignoreUncommitted: boolRegex.test(_nodeProcess.env.BALM_GIT_FLOW_IGNORE_UNCOMMITTED) || defaultOptions.ignoreUncommitted, | ||
useCustomMessage: boolRegex.test(_nodeProcess.env.BALM_GIT_FLOW_USE_CUSTOM_MESSAGE) || defaultOptions.useCustomMessage, | ||
repositories: _nodeProcess.env.BALM_GIT_FLOW_REPOSITORIES ? _nodeProcess.env.BALM_GIT_FLOW_REPOSITORIES.split(',') : defaultOptions.repositories, | ||
@@ -40,0 +50,0 @@ site: _nodeProcess.env.BALM_GIT_FLOW_SITE || defaultOptions.site |
@@ -22,7 +22,7 @@ "use strict"; | ||
_checkReleaseBranch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(currentBranch, releaseBranch, devBranch) { | ||
var _getConfig, debug, main, release, hasUncommitted; | ||
var _getConfig, debug, main, release, ignoreUncommitted, hasUncommitted; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
_getConfig = (0, _config.getConfig)(), debug = _getConfig.debug, main = _getConfig.main, release = _getConfig.release; | ||
_getConfig = (0, _config.getConfig)(), debug = _getConfig.debug, main = _getConfig.main, release = _getConfig.release, ignoreUncommitted = _getConfig.ignoreUncommitted; | ||
_context.next = 3; | ||
@@ -33,12 +33,21 @@ return (0, _cmd.checkStatus)(); | ||
if (!hasUncommitted) { | ||
_context.next = 8; | ||
_context.next = 13; | ||
break; | ||
} | ||
_context.next = 7; | ||
if (!ignoreUncommitted) { | ||
_context.next = 11; | ||
break; | ||
} | ||
_context.next = 8; | ||
return (0, _cmd.runCommands)('git stash'); | ||
case 7: | ||
case 8: | ||
_logger["default"].log("You can use ".concat(_chalk["default"].yellow('git stash pop'), " to restore the latest status after release completed")); | ||
case 8: | ||
_context.next = 13; | ||
break; | ||
case 11: | ||
_logger["default"].log(_chalk["default"].yellow('Local changes were not restored')); | ||
return _context.abrupt("return", false); | ||
case 13: | ||
if (!(release.includes(releaseBranch) && currentBranch === main)) { | ||
_context.next = 24; | ||
_context.next = 29; | ||
break; | ||
@@ -48,7 +57,7 @@ } | ||
if (!devBranch) { | ||
_context.next = 24; | ||
_context.next = 29; | ||
break; | ||
} | ||
_context.prev = 11; | ||
_context.next = 14; | ||
_context.prev = 16; | ||
_context.next = 19; | ||
return (0, _cmd.runCommands)("git merge --no-ff origin/".concat(devBranch), { | ||
@@ -58,25 +67,27 @@ debug: debug, | ||
}); | ||
case 14: | ||
_context.next = 20; | ||
case 19: | ||
_context.next = 25; | ||
break; | ||
case 16: | ||
_context.prev = 16; | ||
_context.t0 = _context["catch"](11); | ||
_context.next = 20; | ||
case 21: | ||
_context.prev = 21; | ||
_context.t0 = _context["catch"](16); | ||
_context.next = 25; | ||
return (0, _cmd.runCommands)("git merge --no-ff ".concat(devBranch), { | ||
debug: debug | ||
}); | ||
case 20: | ||
_context.prev = 20; | ||
_context.next = 23; | ||
case 25: | ||
_context.prev = 25; | ||
_context.next = 28; | ||
return (0, _cmd.runCommands)("git push origin ".concat(main), { | ||
debug: debug | ||
}); | ||
case 23: | ||
return _context.finish(20); | ||
case 24: | ||
case 28: | ||
return _context.finish(25); | ||
case 29: | ||
return _context.abrupt("return", true); | ||
case 30: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, null, [[11, 16, 20, 24]]); | ||
}, _callee, null, [[16, 21, 25, 29]]); | ||
})); | ||
@@ -171,4 +182,4 @@ return _checkReleaseBranch.apply(this, arguments); | ||
commitId = _context3.sent; | ||
LOG_MESSAGE = logMessage || "build: ".concat(releaseBranch, " from ").concat(currentBranch, " as of ").concat(commitId); | ||
releaseCommand = ['git status', 'git add -A', "git commit -m \"".concat(LOG_MESSAGE, "\""), "git push -f origin ".concat(releaseBranch)]; | ||
LOG_MESSAGE = logMessage || "".concat(releaseBranch, " from ").concat(currentBranch, " as of ").concat(commitId); | ||
releaseCommand = ['git status', 'git add -A', "git commit -m \"build: ".concat(LOG_MESSAGE, "\""), "git push -f origin ".concat(releaseBranch)]; | ||
_context3.next = 23; | ||
@@ -214,5 +225,9 @@ return (0, _cmd.runCommands)(releaseCommand, { | ||
case 3: | ||
_context4.next = 5; | ||
if (!_context4.sent) { | ||
_context4.next = 6; | ||
break; | ||
} | ||
_context4.next = 6; | ||
return buildReleaseBranch(currentBranch, releaseBranch, releaseScript, logMessage); | ||
case 5: | ||
case 6: | ||
case "end": | ||
@@ -219,0 +234,0 @@ return _context4.stop(); |
{ | ||
"name": "balm-git-flow", | ||
"version": "0.9.3-legacy", | ||
"version": "0.10.0-legacy", | ||
"description": "The best practices for front-end git flow", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -34,12 +34,33 @@ # Balm Git Flow | ||
| Variable Name | Type | Description | | ||
| -------------------------- | ----------------- | -------------------------------------------------------------------------------------------------- | | ||
| BALM_GIT_FLOW_MAIN | `string` | main branch (source code) | | ||
| BALM_GIT_FLOW_RELEASE | `string`, `array` | production release branch(es) | | ||
| BALM_GIT_FLOW_RELEASES | `array` | all release branches | | ||
| BALM_GIT_FLOW_SCRIPTS | `array` | all build scripts corresponding to the release branches ( the keys of `scripts` in `package.json`) | | ||
| BALM_GIT_FLOW_BUILD_DIR | `string` | build out dir (by `npm-run-script`) | | ||
| BALM_GIT_FLOW_REPOSITORIES | `array` | independent repositories | | ||
| BALM_GIT_FLOW_SITE | `string` | production release branch for independent repositories | | ||
| Variable Name | Type | Default | Description | | ||
| -------------------------------- | ----------------- | -------------------- | -------------------------------------------------------------------------------------------------- | | ||
| BALM_GIT_FLOW_MAIN | `string` | `'main'` | main branch (source code) | | ||
| BALM_GIT_FLOW_RELEASE | `string`, `array` | `'release'` | production release branch(es) | | ||
| BALM_GIT_FLOW_RELEASES | `array` | `['release']` | all release branches | | ||
| BALM_GIT_FLOW_SCRIPTS | `array` | `['build']` | all build scripts corresponding to the release branches ( the keys of `scripts` in `package.json`) | | ||
| BALM_GIT_FLOW_RELEASE_SCRIPTS | `string` | `JSON.stringify({})` | associated scripts and release branches (`{ [script: string]: [releases: string[]] }`) | | ||
| BALM_GIT_FLOW_BUILD_DIR | `string` | `'dist'` | build out dir (by `npm-run-script`) | | ||
| BALM_GIT_FLOW_IGNORE_UNCOMMITTED | `boolean` | `false` | ignore uncommitted for workflow | | ||
| BALM_GIT_FLOW_USE_CUSTOM_MESSAGE | `boolean` | `false` | use custom log message | | ||
| BALM_GIT_FLOW_REPOSITORIES | `array` | | independent repositories | | ||
| BALM_GIT_FLOW_SITE | `string` | | production release branch for independent repositories | | ||
- release scripts settings | ||
- Method 1: | ||
```ini | ||
BALM_GIT_FLOW_RELEASES = ['test', 'release']; | ||
BALM_GIT_FLOW_SCRIPTS = ['build:test', 'build:release']; | ||
``` | ||
- Method 2: | ||
```js | ||
BALM_GIT_FLOW_RELEASE_SCRIPTS = JSON.stringify({ | ||
'build:test': ['test-a', 'test-b'], | ||
'build:release': ['release'] | ||
}); | ||
``` | ||
## Usage | ||
@@ -46,0 +67,0 @@ |
120701
1455
72