balm-git-flow
Advanced tools
Comparing version 0.3.2-legacy to 0.3.2
#!/usr/bin/env node | ||
const { Command } = require('commander'); | ||
const chalk = require('chalk'); | ||
const { setEnvironment } = require('../lib/env.js'); | ||
const { createDevBranch } = require('../lib/branch.js'); | ||
import { Command } from 'commander'; | ||
import chalk from 'chalk'; | ||
import setEnvironment from '../lib/env.js'; | ||
import { createDevBranch } from '../lib/branch.js'; | ||
@@ -7,0 +7,0 @@ const program = new Command(); |
#!/usr/bin/env node | ||
const { setEnvironment } = require('../lib/env.js'); | ||
import setEnvironment from '../lib/env.js'; | ||
@@ -4,0 +4,0 @@ async function doctor() { |
#!/usr/bin/env node | ||
const { Command } = require('commander'); | ||
const pkg = require('../package.json'); | ||
import { createRequire } from 'node:module'; | ||
import { Command } from 'commander'; | ||
const requireModule = createRequire(import.meta.url); | ||
const pkg = requireModule('../package.json'); | ||
const program = new Command(); | ||
@@ -6,0 +8,0 @@ |
#!/usr/bin/env node | ||
const inquirer = require('inquirer'); | ||
const { setEnvironment } = require('../lib/env.js'); | ||
const { getConfig } = require('../lib/config.js'); | ||
const { | ||
import inquirer from 'inquirer'; | ||
import setEnvironment from '../lib/env.js'; | ||
import { getConfig } from '../lib/config.js'; | ||
import { | ||
getCurrentBranch, | ||
getDevelopmentBranches, | ||
deployProject | ||
} = require('../lib/deploy.js'); | ||
} from '../lib/deploy.js'; | ||
@@ -11,0 +11,0 @@ async function production() { |
@@ -1,200 +0,57 @@ | ||
"use strict"; | ||
import util from 'node:util'; | ||
import { exec } from 'node:child_process'; | ||
import { getConfig } from './config.js'; | ||
import logger from './logger.js'; | ||
import { parseBranchLines, runCommand } from './utils.js'; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createDevBranch = createDevBranch; | ||
exports.init = init; | ||
var _nodeUtil = _interopRequireDefault(require("node:util")); | ||
var _nodeChild_process = require("node:child_process"); | ||
var _config = require("./config.js"); | ||
var _logger = _interopRequireDefault(require("./logger.js")); | ||
var _utils = require("./utils.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); } | ||
function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, "return": function _return(value) { var ret = this.s["return"]; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, "throw": function _throw(value) { var thr = this.s["return"]; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); } | ||
var asyncExec = _nodeUtil["default"].promisify(_nodeChild_process.exec); | ||
function createEmptyBranch(_x) { | ||
return _createEmptyBranch.apply(this, arguments); | ||
const asyncExec = util.promisify(exec); | ||
async function createEmptyBranch(newBranch) { | ||
const { stdout } = await asyncExec('git branch'); | ||
const [currentBranch] = parseBranchLines(stdout); | ||
const createCommand = [ | ||
`git checkout --orphan ${newBranch}`, | ||
'git rm -rf .', | ||
`git commit --allow-empty -m "Initial commit for ${newBranch}"`, | ||
`git push origin ${newBranch}` | ||
]; | ||
await runCommand(createCommand); | ||
await asyncExec(`git checkout ${currentBranch}`); | ||
} | ||
function _createEmptyBranch() { | ||
_createEmptyBranch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(newBranch) { | ||
var _yield$asyncExec, stdout, _parseBranchLines, _parseBranchLines2, currentBranch, createCommand; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return asyncExec('git branch'); | ||
case 2: | ||
_yield$asyncExec = _context.sent; | ||
stdout = _yield$asyncExec.stdout; | ||
_parseBranchLines = (0, _utils.parseBranchLines)(stdout), _parseBranchLines2 = _slicedToArray(_parseBranchLines, 1), currentBranch = _parseBranchLines2[0]; | ||
createCommand = ["git checkout --orphan ".concat(newBranch), 'git rm -rf .', "git commit --allow-empty -m \"Initial commit for ".concat(newBranch, "\""), "git push origin ".concat(newBranch)]; | ||
_context.next = 8; | ||
return (0, _utils.runCommand)(createCommand); | ||
case 8: | ||
_context.next = 10; | ||
return asyncExec("git checkout ".concat(currentBranch)); | ||
case 10: | ||
case "end": | ||
return _context.stop(); | ||
export async function init() { | ||
const releases = getConfig('releases'); | ||
const { error, stdout } = await asyncExec('git branch -r | grep -v HEAD'); | ||
if (error) { | ||
logger.fatal(error); | ||
} | ||
if (stdout) { | ||
const branches = parseBranchLines(stdout); | ||
let isOK = true; | ||
for await (const releaseBranch of releases) { | ||
if (!branches.includes(releaseBranch)) { | ||
isOK = false; | ||
logger.log(`Missing branch: '${releaseBranch}'`); | ||
await createEmptyBranch(releaseBranch); | ||
} | ||
}, _callee); | ||
})); | ||
return _createEmptyBranch.apply(this, arguments); | ||
} | ||
const message = isOK ? 'Everything is OK' : 'New branch has been created'; | ||
logger.success(message); | ||
} | ||
} | ||
function getRemoteBranches(_x2) { | ||
return _getRemoteBranches.apply(this, arguments); | ||
export async function createDevBranch(newBranch, startPoint) { | ||
const main = getConfig('main'); | ||
startPoint = startPoint || `origin/${main}`; | ||
const { error } = asyncExec(`git checkout -b ${newBranch} ${startPoint}`); | ||
if (error) { | ||
logger.fatal(error); | ||
} | ||
} | ||
function _getRemoteBranches() { | ||
_getRemoteBranches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(filterHeadCommand) { | ||
var _yield$asyncExec2, error, stdout; | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return asyncExec("git branch -r | ".concat(filterHeadCommand)); | ||
case 2: | ||
_yield$asyncExec2 = _context2.sent; | ||
error = _yield$asyncExec2.error; | ||
stdout = _yield$asyncExec2.stdout; | ||
if (error) { | ||
_logger["default"].fatal(error); | ||
} | ||
return _context2.abrupt("return", stdout); | ||
case 7: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2); | ||
})); | ||
return _getRemoteBranches.apply(this, arguments); | ||
} | ||
function init() { | ||
return _init.apply(this, arguments); | ||
} | ||
function _init() { | ||
_init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() { | ||
var releases, result, branches, isOK, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, releaseBranch, message; | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
releases = (0, _config.getConfig)('releases'); | ||
_context3.prev = 1; | ||
_context3.next = 4; | ||
return getRemoteBranches('grep -v HEAD'); | ||
case 4: | ||
result = _context3.sent; | ||
_context3.next = 12; | ||
break; | ||
case 7: | ||
_context3.prev = 7; | ||
_context3.t0 = _context3["catch"](1); | ||
_context3.next = 11; | ||
return getRemoteBranches('find /v "HEAD"'); | ||
case 11: | ||
result = _context3.sent; | ||
case 12: | ||
if (!result) { | ||
_context3.next = 49; | ||
break; | ||
} | ||
branches = (0, _utils.parseBranchLines)(result); | ||
isOK = true; | ||
_iteratorAbruptCompletion = false; | ||
_didIteratorError = false; | ||
_context3.prev = 17; | ||
_iterator = _asyncIterator(releases); | ||
case 19: | ||
_context3.next = 21; | ||
return _iterator.next(); | ||
case 21: | ||
if (!(_iteratorAbruptCompletion = !(_step = _context3.sent).done)) { | ||
_context3.next = 31; | ||
break; | ||
} | ||
releaseBranch = _step.value; | ||
if (branches.includes(releaseBranch)) { | ||
_context3.next = 28; | ||
break; | ||
} | ||
isOK = false; | ||
_logger["default"].log("Missing branch: '".concat(releaseBranch, "'")); | ||
_context3.next = 28; | ||
return createEmptyBranch(releaseBranch); | ||
case 28: | ||
_iteratorAbruptCompletion = false; | ||
_context3.next = 19; | ||
break; | ||
case 31: | ||
_context3.next = 37; | ||
break; | ||
case 33: | ||
_context3.prev = 33; | ||
_context3.t1 = _context3["catch"](17); | ||
_didIteratorError = true; | ||
_iteratorError = _context3.t1; | ||
case 37: | ||
_context3.prev = 37; | ||
_context3.prev = 38; | ||
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) { | ||
_context3.next = 42; | ||
break; | ||
} | ||
_context3.next = 42; | ||
return _iterator["return"](); | ||
case 42: | ||
_context3.prev = 42; | ||
if (!_didIteratorError) { | ||
_context3.next = 45; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 45: | ||
return _context3.finish(42); | ||
case 46: | ||
return _context3.finish(37); | ||
case 47: | ||
message = isOK ? 'Everything is OK' : 'New branch has been created'; | ||
_logger["default"].success(message); | ||
case 49: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3, null, [[1, 7], [17, 33, 37, 47], [38,, 42, 46]]); | ||
})); | ||
return _init.apply(this, arguments); | ||
} | ||
function createDevBranch(_x3, _x4) { | ||
return _createDevBranch.apply(this, arguments); | ||
} | ||
function _createDevBranch() { | ||
_createDevBranch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(newBranch, startPoint) { | ||
var main, _asyncExec, error; | ||
return _regeneratorRuntime().wrap(function _callee4$(_context4) { | ||
while (1) switch (_context4.prev = _context4.next) { | ||
case 0: | ||
main = (0, _config.getConfig)('main'); | ||
startPoint = startPoint || "origin/".concat(main); | ||
_asyncExec = asyncExec("git checkout -b ".concat(newBranch, " ").concat(startPoint)), error = _asyncExec.error; | ||
if (error) { | ||
_logger["default"].fatal(error); | ||
} | ||
case 4: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, _callee4); | ||
})); | ||
return _createDevBranch.apply(this, arguments); | ||
} |
@@ -1,15 +0,5 @@ | ||
"use strict"; | ||
export const WORKSPACE_DIR = '.balm-git-flow'; | ||
export const NO_NEED_TO_MERGE = '[No need to merge]'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.WORKSPACE_DIR = exports.NO_NEED_TO_MERGE = void 0; | ||
exports.getConfig = getConfig; | ||
exports.isWin = void 0; | ||
exports.setConfig = setConfig; | ||
var WORKSPACE_DIR = '.balm-git-flow'; | ||
exports.WORKSPACE_DIR = WORKSPACE_DIR; | ||
var NO_NEED_TO_MERGE = '[No need to merge]'; | ||
exports.NO_NEED_TO_MERGE = NO_NEED_TO_MERGE; | ||
var defaultOptions = { | ||
const defaultOptions = { | ||
main: 'main', | ||
@@ -21,4 +11,6 @@ release: 'release', | ||
}; | ||
var options = {}; | ||
function setConfig() { | ||
let options = {}; | ||
export function setConfig() { | ||
options = { | ||
@@ -29,11 +21,14 @@ debug: process.env.BALM_GIT_FLOW_DEBUG || false, | ||
release: process.env.BALM_GIT_FLOW_RELEASE || defaultOptions.release, | ||
releases: process.env.BALM_GIT_FLOW_RELEASES ? process.env.BALM_GIT_FLOW_RELEASES.split(',') : defaultOptions.releases, | ||
scripts: process.env.BALM_GIT_FLOW_SCRIPTS ? process.env.BALM_GIT_FLOW_SCRIPTS.split(',') : defaultOptions.scripts, | ||
releases: process.env.BALM_GIT_FLOW_RELEASES | ||
? process.env.BALM_GIT_FLOW_RELEASES.split(',') | ||
: defaultOptions.releases, | ||
scripts: process.env.BALM_GIT_FLOW_SCRIPTS | ||
? process.env.BALM_GIT_FLOW_SCRIPTS.split(',') | ||
: defaultOptions.scripts, | ||
buildDir: process.env.BALM_GIT_FLOW_BUILD_DIR || defaultOptions.buildDir | ||
}; | ||
} | ||
function getConfig(key) { | ||
export function getConfig(key) { | ||
return options[key] || options; | ||
} | ||
var isWin = process.platform === 'win32'; | ||
exports.isWin = isWin; |
@@ -1,234 +0,122 @@ | ||
"use strict"; | ||
import util from 'node:util'; | ||
import { exec } from 'node:child_process'; | ||
import path from 'node:path'; | ||
import { WORKSPACE_DIR, NO_NEED_TO_MERGE, getConfig } from './config.js'; | ||
import logger from './logger.js'; | ||
import { parseBranchLines, runCommand } from './utils.js'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.deployProject = deployProject; | ||
exports.getCurrentBranch = getCurrentBranch; | ||
exports.getDevelopmentBranches = getDevelopmentBranches; | ||
var _nodeUtil = _interopRequireDefault(require("node:util")); | ||
var _nodeChild_process = require("node:child_process"); | ||
var _nodePath = _interopRequireDefault(require("node:path")); | ||
var _config = require("./config.js"); | ||
var _logger = _interopRequireDefault(require("./logger.js")); | ||
var _utils = require("./utils.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var asyncExec = _nodeUtil["default"].promisify(_nodeChild_process.exec); | ||
function getCurrentBranch() { | ||
return _getCurrentBranch.apply(this, arguments); | ||
const asyncExec = util.promisify(exec); | ||
export async function getCurrentBranch() { | ||
const { stdout } = await asyncExec('git symbolic-ref --short -q HEAD'); | ||
const currentBranch = stdout.trim(); | ||
return currentBranch; | ||
} | ||
function _getCurrentBranch() { | ||
_getCurrentBranch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { | ||
var _yield$asyncExec, stdout, currentBranch; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return asyncExec('git symbolic-ref --short -q HEAD'); | ||
case 2: | ||
_yield$asyncExec = _context.sent; | ||
stdout = _yield$asyncExec.stdout; | ||
currentBranch = stdout.trim(); | ||
return _context.abrupt("return", currentBranch); | ||
case 6: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return _getCurrentBranch.apply(this, arguments); | ||
} | ||
function checkReleaseBranch(_x, _x2, _x3) { | ||
return _checkReleaseBranch.apply(this, arguments); | ||
} | ||
function _checkReleaseBranch() { | ||
_checkReleaseBranch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(currentBranch, releaseBranch, devBranch) { | ||
var _getConfig, debug, main, release; | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_getConfig = (0, _config.getConfig)(), debug = _getConfig.debug, main = _getConfig.main, release = _getConfig.release; | ||
if (!(releaseBranch === release)) { | ||
_context2.next = 21; | ||
break; | ||
} | ||
if (!(currentBranch === main)) { | ||
_context2.next = 20; | ||
break; | ||
} | ||
devBranch = devBranch === _config.NO_NEED_TO_MERGE ? '' : devBranch; | ||
if (!devBranch) { | ||
_context2.next = 18; | ||
break; | ||
} | ||
_context2.prev = 5; | ||
_context2.next = 8; | ||
return (0, _utils.runCommand)("git merge --no-ff origin/".concat(devBranch), { | ||
debug: debug | ||
async function checkReleaseBranch(currentBranch, releaseBranch, devBranch) { | ||
const { debug, main, release } = getConfig(); | ||
if (releaseBranch === release) { | ||
if (currentBranch === main) { | ||
devBranch = devBranch === NO_NEED_TO_MERGE ? '' : devBranch; | ||
if (devBranch) { | ||
try { | ||
await runCommand(`git merge --no-ff origin/${devBranch}`, { | ||
debug | ||
}); | ||
case 8: | ||
_context2.next = 14; | ||
break; | ||
case 10: | ||
_context2.prev = 10; | ||
_context2.t0 = _context2["catch"](5); | ||
_context2.next = 14; | ||
return (0, _utils.runCommand)("git merge --no-ff ".concat(devBranch), { | ||
debug: debug | ||
}); | ||
case 14: | ||
_context2.prev = 14; | ||
_context2.next = 17; | ||
return (0, _utils.runCommand)("git push origin ".concat(main), { | ||
debug: debug | ||
}); | ||
case 17: | ||
return _context2.finish(14); | ||
case 18: | ||
_context2.next = 21; | ||
break; | ||
case 20: | ||
_logger["default"].fatal("If you want to release '".concat(release, "', switch to the '").concat(main, "' branch first!")); | ||
case 21: | ||
case "end": | ||
return _context2.stop(); | ||
} catch (e) { | ||
await runCommand(`git merge --no-ff ${devBranch}`, { debug }); | ||
} finally { | ||
await runCommand(`git push origin ${main}`, { debug }); | ||
} | ||
} | ||
}, _callee2, null, [[5, 10, 14, 18]]); | ||
})); | ||
return _checkReleaseBranch.apply(this, arguments); | ||
} else { | ||
logger.fatal( | ||
`If you want to release '${release}', switch to the '${main}' branch first!` | ||
); | ||
} | ||
} | ||
} | ||
function clean(_x4) { | ||
return _clean.apply(this, arguments); | ||
async function clean(releaseDir) { | ||
const cleanCommand = [`rm -rf ${releaseDir}`, 'git worktree prune']; | ||
await runCommand(cleanCommand); | ||
} | ||
function _clean() { | ||
_clean = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(releaseDir) { | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return (0, _utils.rm)(releaseDir); | ||
case 2: | ||
_context3.next = 4; | ||
return asyncExec('git worktree prune'); | ||
case 4: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3); | ||
})); | ||
return _clean.apply(this, arguments); | ||
async function buildReleaseBranch( | ||
currentBranch, | ||
releaseBranch, | ||
releaseScript, | ||
logMessage | ||
) { | ||
if (releaseScript) { | ||
const { debug, projectName, buildDir } = getConfig(); | ||
const releaseDir = path.join(process.cwd(), WORKSPACE_DIR); | ||
// Clean up | ||
clean(releaseDir); | ||
// New worktree | ||
const createCommand = [ | ||
'git remote prune origin', | ||
'git pull --ff-only', | ||
`git worktree add -B ${releaseBranch} ${releaseDir} origin/${releaseBranch}`, | ||
`rm -rf ${releaseDir}/*` | ||
]; | ||
await runCommand(createCommand, { debug }); | ||
// Build | ||
const buildCommand = [ | ||
`npm run ${releaseScript}`, | ||
`cp -rf ${buildDir}/* ${releaseDir}` | ||
]; | ||
await runCommand(buildCommand, { debug }); | ||
// Release | ||
const LOG_MESSAGE = | ||
logMessage || | ||
`build: ${projectName} from ${currentBranch} as of $(git log -1 --pretty=format:%h ${currentBranch})`; | ||
const releaseCommand = [ | ||
'git status', | ||
'git add -A', | ||
`git commit -m "${LOG_MESSAGE}"`, | ||
`git push -f -u origin ${releaseBranch}` | ||
]; | ||
await runCommand(releaseCommand, { cwd: releaseDir, debug }); | ||
// Clean up | ||
clean(releaseDir); | ||
} else { | ||
logger.fatal(`Missing 'BALM_GIT_FLOW_SCRIPTS' in balm.env.js`); | ||
} | ||
} | ||
function buildReleaseBranch(_x5, _x6, _x7, _x8) { | ||
return _buildReleaseBranch.apply(this, arguments); | ||
export async function deployProject({ | ||
currentBranch, | ||
releaseBranch, | ||
releaseScript, | ||
devBranch, | ||
logMessage | ||
}) { | ||
await checkReleaseBranch(currentBranch, releaseBranch, devBranch); | ||
await buildReleaseBranch( | ||
currentBranch, | ||
releaseBranch, | ||
releaseScript, | ||
logMessage | ||
); | ||
} | ||
function _buildReleaseBranch() { | ||
_buildReleaseBranch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(currentBranch, releaseBranch, releaseScript, logMessage) { | ||
var _getConfig2, debug, projectName, buildDir, releaseDir, createCommand, LOG_MESSAGE, releaseCommand; | ||
return _regeneratorRuntime().wrap(function _callee4$(_context4) { | ||
while (1) switch (_context4.prev = _context4.next) { | ||
case 0: | ||
if (!releaseScript) { | ||
_context4.next = 19; | ||
break; | ||
} | ||
_getConfig2 = (0, _config.getConfig)(), debug = _getConfig2.debug, projectName = _getConfig2.projectName, buildDir = _getConfig2.buildDir; | ||
releaseDir = _nodePath["default"].join(process.cwd(), _config.WORKSPACE_DIR); // Clean up | ||
clean(_config.WORKSPACE_DIR); | ||
// New worktree | ||
createCommand = ['git remote prune origin', 'git pull --ff-only', "git worktree add -B ".concat(releaseBranch, " ").concat(releaseDir, " origin/").concat(releaseBranch)]; | ||
_context4.next = 7; | ||
return (0, _utils.runCommand)(createCommand, { | ||
debug: debug | ||
}); | ||
case 7: | ||
_context4.next = 9; | ||
return (0, _utils.rm)(["".concat(_config.WORKSPACE_DIR, "/**"), "!".concat(_config.WORKSPACE_DIR)]); | ||
case 9: | ||
_context4.next = 11; | ||
return (0, _utils.runCommand)("npm run ".concat(releaseScript), { | ||
debug: debug | ||
}); | ||
case 11: | ||
(0, _utils.copyDir)(buildDir, releaseDir, function (err) { | ||
_logger["default"].fatal(err); | ||
}); | ||
export async function getDevelopmentBranches() { | ||
const { main, releases } = getConfig(); | ||
// Release | ||
LOG_MESSAGE = logMessage || "build ".concat(projectName, " from ").concat(currentBranch, " as of $(git log '--format=format:%H' ").concat(currentBranch, " -1)"); | ||
releaseCommand = ['git status', 'git add -A', "git commit -m \"".concat(LOG_MESSAGE, "\""), "git push -f -u origin ".concat(releaseBranch)]; | ||
_context4.next = 16; | ||
return (0, _utils.runCommand)(releaseCommand, { | ||
cwd: releaseDir, | ||
debug: debug | ||
}); | ||
case 16: | ||
// Clean up | ||
clean(_config.WORKSPACE_DIR); | ||
_context4.next = 20; | ||
break; | ||
case 19: | ||
_logger["default"].fatal("Missing 'BALM_GIT_FLOW_SCRIPTS' in balm.env.js"); | ||
case 20: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, _callee4); | ||
})); | ||
return _buildReleaseBranch.apply(this, arguments); | ||
const { stdout } = await asyncExec('git branch'); | ||
let localBranches = parseBranchLines(stdout).filter( | ||
(branch) => !(branch === main || releases.includes(branch)) | ||
); | ||
localBranches.unshift(NO_NEED_TO_MERGE); | ||
return localBranches; | ||
} | ||
function deployProject(_x9) { | ||
return _deployProject.apply(this, arguments); | ||
} | ||
function _deployProject() { | ||
_deployProject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref) { | ||
var currentBranch, releaseBranch, releaseScript, devBranch, logMessage; | ||
return _regeneratorRuntime().wrap(function _callee5$(_context5) { | ||
while (1) switch (_context5.prev = _context5.next) { | ||
case 0: | ||
currentBranch = _ref.currentBranch, releaseBranch = _ref.releaseBranch, releaseScript = _ref.releaseScript, devBranch = _ref.devBranch, logMessage = _ref.logMessage; | ||
_context5.next = 3; | ||
return checkReleaseBranch(currentBranch, releaseBranch, devBranch); | ||
case 3: | ||
_context5.next = 5; | ||
return buildReleaseBranch(currentBranch, releaseBranch, releaseScript, logMessage); | ||
case 5: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
}, _callee5); | ||
})); | ||
return _deployProject.apply(this, arguments); | ||
} | ||
function getDevelopmentBranches() { | ||
return _getDevelopmentBranches.apply(this, arguments); | ||
} | ||
function _getDevelopmentBranches() { | ||
_getDevelopmentBranches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() { | ||
var _getConfig3, main, releases, _yield$asyncExec2, stdout, localBranches; | ||
return _regeneratorRuntime().wrap(function _callee6$(_context6) { | ||
while (1) switch (_context6.prev = _context6.next) { | ||
case 0: | ||
_getConfig3 = (0, _config.getConfig)(), main = _getConfig3.main, releases = _getConfig3.releases; | ||
_context6.next = 3; | ||
return asyncExec('git branch'); | ||
case 3: | ||
_yield$asyncExec2 = _context6.sent; | ||
stdout = _yield$asyncExec2.stdout; | ||
localBranches = (0, _utils.parseBranchLines)(stdout).filter(function (branch) { | ||
return !(branch === main || releases.includes(branch)); | ||
}); | ||
localBranches.unshift(_config.NO_NEED_TO_MERGE); | ||
return _context6.abrupt("return", localBranches); | ||
case 8: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
}, _callee6); | ||
})); | ||
return _getDevelopmentBranches.apply(this, arguments); | ||
} |
104
lib/env.js
@@ -1,71 +0,37 @@ | ||
"use strict"; | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import { setConfig } from './config.js'; | ||
import logger from './logger.js'; | ||
import { writeIterableToFile } from './utils.js'; | ||
import { init } from './branch.js'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.setEnvironment = setEnvironment; | ||
var _nodePath = _interopRequireDefault(require("node:path")); | ||
var _nodeFs = _interopRequireDefault(require("node:fs")); | ||
var _config = require("./config.js"); | ||
var _logger = _interopRequireDefault(require("./logger.js")); | ||
var _utils = require("./utils.js"); | ||
var _branch = require("./branch.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var balmEnvFile = _nodePath["default"].join(process.cwd(), 'balm.env.js'); | ||
var defaultContents = ["process.env.BALM_GIT_FLOW_NAME = '';", "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';"]; | ||
function setEnvironment() { | ||
return _setEnvironment.apply(this, arguments); | ||
const balmEnvFile = path.join(process.cwd(), 'balm.env.js'); | ||
const defaultContents = [ | ||
`process.env.BALM_GIT_FLOW_NAME = '';`, | ||
`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';` | ||
]; | ||
async function setEnvironment(checkEnvFile = false) { | ||
if (fs.existsSync(balmEnvFile)) { | ||
await import(balmEnvFile); | ||
setConfig(); | ||
checkEnvFile && init(); | ||
} else { | ||
if (checkEnvFile) { | ||
await writeIterableToFile(defaultContents, balmEnvFile); | ||
logger.success(`'balm.env.js' has been created`); | ||
setEnvironment(true); | ||
} else { | ||
logger.fatal(`Missing 'balm.env.js' in the project root directory`); | ||
} | ||
} | ||
} | ||
function _setEnvironment() { | ||
_setEnvironment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { | ||
var checkEnvFile, | ||
_args = arguments; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
checkEnvFile = _args.length > 0 && _args[0] !== undefined ? _args[0] : false; | ||
if (!_nodeFs["default"].existsSync(balmEnvFile)) { | ||
_context.next = 8; | ||
break; | ||
} | ||
_context.next = 4; | ||
return function (specifier) { | ||
return new Promise(function (r) { | ||
return r("".concat(specifier)); | ||
}).then(function (s) { | ||
return _interopRequireWildcard(require(s)); | ||
}); | ||
}(balmEnvFile); | ||
case 4: | ||
(0, _config.setConfig)(); | ||
checkEnvFile && (0, _branch.init)(); | ||
_context.next = 16; | ||
break; | ||
case 8: | ||
if (!checkEnvFile) { | ||
_context.next = 15; | ||
break; | ||
} | ||
_context.next = 11; | ||
return (0, _utils.writeIterableToFile)(defaultContents, balmEnvFile); | ||
case 11: | ||
_logger["default"].success("'balm.env.js' has been created"); | ||
setEnvironment(true); | ||
_context.next = 16; | ||
break; | ||
case 15: | ||
_logger["default"].fatal("Missing 'balm.env.js' in the project root directory"); | ||
case 16: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return _setEnvironment.apply(this, arguments); | ||
} | ||
export default setEnvironment; |
@@ -1,10 +0,4 @@ | ||
"use strict"; | ||
import { format } from 'node:util'; | ||
import chalk from 'chalk'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _nodeUtil = require("node:util"); | ||
var _chalk = _interopRequireDefault(require("chalk")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
/** | ||
@@ -14,4 +8,4 @@ * Prefix. | ||
var prefix = '[Balm Git Flow]'; | ||
var sep = _chalk["default"].gray('·'); | ||
const prefix = '[Balm Git Flow]'; | ||
const sep = chalk.gray('·'); | ||
@@ -24,8 +18,5 @@ /** | ||
function log() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var msg = _nodeUtil.format.apply(_nodeUtil.format, args); | ||
console.log(_chalk["default"].white(prefix), sep, msg); | ||
function log(...args) { | ||
const msg = format.apply(format, args); | ||
console.log(chalk.white(prefix), sep, msg); | ||
} | ||
@@ -39,9 +30,6 @@ | ||
function fatal() { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
function fatal(...args) { | ||
if (args[0] instanceof Error) args[0] = args[0].message.trim(); | ||
var msg = _nodeUtil.format.apply(_nodeUtil.format, args); | ||
console.log(_chalk["default"].red(prefix), sep, msg); | ||
const msg = format.apply(format, args); | ||
console.log(chalk.red(prefix), sep, msg); | ||
process.exit(1); | ||
@@ -56,14 +44,7 @@ } | ||
function success() { | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
var msg = _nodeUtil.format.apply(_nodeUtil.format, args); | ||
console.log(_chalk["default"].green(prefix), sep, msg); | ||
function success(...args) { | ||
const msg = format.apply(format, args); | ||
console.log(chalk.green(prefix), sep, msg); | ||
} | ||
var _default = { | ||
log: log, | ||
fatal: fatal, | ||
success: success | ||
}; | ||
exports["default"] = _default; | ||
export default { log, fatal, success }; |
353
lib/utils.js
@@ -1,301 +0,64 @@ | ||
"use strict"; | ||
import { EOL } from 'node:os'; | ||
import util from 'node:util'; | ||
import { exec } from 'node:child_process'; | ||
import stream from 'node:stream'; | ||
import fs from 'node:fs'; | ||
import { once } from 'node:events'; | ||
import logger from './logger.js'; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.copyDir = copyDir; | ||
exports.parseBranchLines = exports.isObject = void 0; | ||
exports.rm = rm; | ||
exports.runCommand = runCommand; | ||
exports.writeIterableToFile = writeIterableToFile; | ||
var _nodeOs = require("node:os"); | ||
var _nodeUtil = _interopRequireDefault(require("node:util")); | ||
var _nodeChild_process = require("node:child_process"); | ||
var _nodeStream = _interopRequireDefault(require("node:stream")); | ||
var _nodeFs = _interopRequireDefault(require("node:fs")); | ||
var _nodeEvents = require("node:events"); | ||
var _nodePath = _interopRequireDefault(require("node:path")); | ||
var _del = _interopRequireDefault(require("del")); | ||
var _logger = _interopRequireDefault(require("./logger.js")); | ||
var _config = require("./config.js"); | ||
var _excluded = ["debug"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); } | ||
function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, "return": function _return(value) { var ret = this.s["return"]; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, "throw": function _throw(value) { var thr = this.s["return"]; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); } | ||
// Define regular expression | ||
var reTypeOf = /(?:^\[object\s(.*?)\]$)/; | ||
var REGEX_STAR = /^(\*)?\s*(origin\/)?/g; | ||
var ENTER = '\n'; | ||
var asyncExec = _nodeUtil["default"].promisify(_nodeChild_process.exec); | ||
var finished = _nodeUtil["default"].promisify(_nodeStream["default"].finished); | ||
var getType = function getType(any) { | ||
return Object.prototype.toString.call(any).replace(reTypeOf, '$1').toLowerCase(); | ||
const reTypeOf = /(?:^\[object\s(.*?)\]$)/; | ||
const REGEX_STAR = /^(\*)?\s*(origin\/)?/g; | ||
const asyncExec = util.promisify(exec); | ||
const finished = util.promisify(stream.finished); | ||
const getType = (any) => { | ||
return Object.prototype.toString | ||
.call(any) | ||
.replace(reTypeOf, '$1') | ||
.toLowerCase(); | ||
}; | ||
var isObject = function isObject(obj) { | ||
return getType(obj) === 'object'; | ||
}; | ||
exports.isObject = isObject; | ||
var parseBranchLines = function parseBranchLines(str) { | ||
var branches = str.trim().split(_nodeOs.EOL); | ||
if (_config.isWin && branches[0].includes(ENTER)) { | ||
branches = str.trim().split(ENTER); | ||
export const isObject = (obj) => getType(obj) === 'object'; | ||
export const parseBranchLines = (str) => | ||
str | ||
.trim() | ||
.split(EOL) | ||
.map((line) => line.trim().replace(REGEX_STAR, '')); | ||
export async function runCommand(awesomeCommand, cmdOptions = {}) { | ||
const { debug, ...options } = cmdOptions; | ||
if (Array.isArray(awesomeCommand)) { | ||
for await (const command of awesomeCommand) { | ||
debug && console.log(command); | ||
try { | ||
const { stdout } = await asyncExec(command, options || {}); | ||
console.log(stdout); | ||
} catch (error) { | ||
logger.fatal(error); | ||
} | ||
} | ||
} else { | ||
debug && console.log(awesomeCommand); | ||
const { stdout } = await asyncExec(awesomeCommand, options || {}); | ||
console.log(stdout); | ||
} | ||
return branches.map(function (line) { | ||
return line.trim().replace(REGEX_STAR, ''); | ||
}); | ||
}; | ||
exports.parseBranchLines = parseBranchLines; | ||
function runCommand(_x) { | ||
return _runCommand.apply(this, arguments); | ||
} | ||
function _runCommand() { | ||
_runCommand = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(awesomeCommand) { | ||
var cmdOptions, | ||
debug, | ||
options, | ||
_iteratorAbruptCompletion, | ||
_didIteratorError, | ||
_iteratorError, | ||
_iterator, | ||
_step, | ||
command, | ||
_yield$asyncExec, | ||
stdout, | ||
_yield$asyncExec2, | ||
_stdout, | ||
_args = arguments; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
cmdOptions = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}; | ||
debug = cmdOptions.debug, options = _objectWithoutProperties(cmdOptions, _excluded); | ||
if (!Array.isArray(awesomeCommand)) { | ||
_context.next = 44; | ||
break; | ||
} | ||
_iteratorAbruptCompletion = false; | ||
_didIteratorError = false; | ||
_context.prev = 5; | ||
_iterator = _asyncIterator(awesomeCommand); | ||
case 7: | ||
_context.next = 9; | ||
return _iterator.next(); | ||
case 9: | ||
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) { | ||
_context.next = 26; | ||
break; | ||
} | ||
command = _step.value; | ||
debug && console.log(command); | ||
_context.prev = 12; | ||
_context.next = 15; | ||
return asyncExec(command, options || {}); | ||
case 15: | ||
_yield$asyncExec = _context.sent; | ||
stdout = _yield$asyncExec.stdout; | ||
console.log(stdout); | ||
_context.next = 23; | ||
break; | ||
case 20: | ||
_context.prev = 20; | ||
_context.t0 = _context["catch"](12); | ||
_logger["default"].fatal(_context.t0); | ||
case 23: | ||
_iteratorAbruptCompletion = false; | ||
_context.next = 7; | ||
break; | ||
case 26: | ||
_context.next = 32; | ||
break; | ||
case 28: | ||
_context.prev = 28; | ||
_context.t1 = _context["catch"](5); | ||
_didIteratorError = true; | ||
_iteratorError = _context.t1; | ||
case 32: | ||
_context.prev = 32; | ||
_context.prev = 33; | ||
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) { | ||
_context.next = 37; | ||
break; | ||
} | ||
_context.next = 37; | ||
return _iterator["return"](); | ||
case 37: | ||
_context.prev = 37; | ||
if (!_didIteratorError) { | ||
_context.next = 40; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 40: | ||
return _context.finish(37); | ||
case 41: | ||
return _context.finish(32); | ||
case 42: | ||
_context.next = 50; | ||
break; | ||
case 44: | ||
debug && console.log(awesomeCommand); | ||
_context.next = 47; | ||
return asyncExec(awesomeCommand, options || {}); | ||
case 47: | ||
_yield$asyncExec2 = _context.sent; | ||
_stdout = _yield$asyncExec2.stdout; | ||
console.log(_stdout); | ||
case 50: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, null, [[5, 28, 32, 42], [12, 20], [33,, 37, 41]]); | ||
})); | ||
return _runCommand.apply(this, arguments); | ||
export async function writeIterableToFile(iterable, filePath) { | ||
const writable = fs.createWriteStream(filePath, { encoding: 'utf8' }); | ||
for await (const chunk of iterable) { | ||
if (!writable.write(`${chunk}\n`)) { | ||
// Handle backpressure | ||
await once(writable, 'drain'); | ||
} | ||
} | ||
writable.end(); | ||
// Wait until done. Throws if there are errors. | ||
await finished(writable); | ||
} | ||
function writeIterableToFile(_x2, _x3) { | ||
return _writeIterableToFile.apply(this, arguments); | ||
} | ||
function _writeIterableToFile() { | ||
_writeIterableToFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(iterable, filePath) { | ||
var writable, _iteratorAbruptCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, chunk; | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
writable = _nodeFs["default"].createWriteStream(filePath, { | ||
encoding: 'utf8' | ||
}); | ||
_iteratorAbruptCompletion2 = false; | ||
_didIteratorError2 = false; | ||
_context2.prev = 3; | ||
_iterator2 = _asyncIterator(iterable); | ||
case 5: | ||
_context2.next = 7; | ||
return _iterator2.next(); | ||
case 7: | ||
if (!(_iteratorAbruptCompletion2 = !(_step2 = _context2.sent).done)) { | ||
_context2.next = 15; | ||
break; | ||
} | ||
chunk = _step2.value; | ||
if (writable.write("".concat(chunk, "\n"))) { | ||
_context2.next = 12; | ||
break; | ||
} | ||
_context2.next = 12; | ||
return (0, _nodeEvents.once)(writable, 'drain'); | ||
case 12: | ||
_iteratorAbruptCompletion2 = false; | ||
_context2.next = 5; | ||
break; | ||
case 15: | ||
_context2.next = 21; | ||
break; | ||
case 17: | ||
_context2.prev = 17; | ||
_context2.t0 = _context2["catch"](3); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context2.t0; | ||
case 21: | ||
_context2.prev = 21; | ||
_context2.prev = 22; | ||
if (!(_iteratorAbruptCompletion2 && _iterator2["return"] != null)) { | ||
_context2.next = 26; | ||
break; | ||
} | ||
_context2.next = 26; | ||
return _iterator2["return"](); | ||
case 26: | ||
_context2.prev = 26; | ||
if (!_didIteratorError2) { | ||
_context2.next = 29; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 29: | ||
return _context2.finish(26); | ||
case 30: | ||
return _context2.finish(21); | ||
case 31: | ||
writable.end(); | ||
// Wait until done. Throws if there are errors. | ||
_context2.next = 34; | ||
return finished(writable); | ||
case 34: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, null, [[3, 17, 21, 31], [22,, 26, 30]]); | ||
})); | ||
return _writeIterableToFile.apply(this, arguments); | ||
} | ||
function rm(_x4) { | ||
return _rm.apply(this, arguments); | ||
} | ||
/** | ||
* 复制文件夹到目标文件夹 | ||
* @param {string} src 源目录 | ||
* @param {string} dest 目标目录 | ||
* @param {function} callback 回调 | ||
*/ | ||
function _rm() { | ||
_rm = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(dir) { | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return (0, _del["default"])(dir, { | ||
force: true | ||
}); | ||
case 2: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3); | ||
})); | ||
return _rm.apply(this, arguments); | ||
} | ||
function copyDir(src, dest, callback) { | ||
var copy = function copy(copySrc, copyDest) { | ||
_nodeFs["default"].readdir(copySrc, function (err, list) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
list.forEach(function (item) { | ||
var ss = _nodePath["default"].resolve(copySrc, item); | ||
_nodeFs["default"].stat(ss, function (err, stat) { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
var curSrc = _nodePath["default"].resolve(copySrc, item); | ||
var curDest = _nodePath["default"].resolve(copyDest, item); | ||
if (stat.isFile()) { | ||
// 文件,直接复制 | ||
_nodeFs["default"].createReadStream(curSrc).pipe(_nodeFs["default"].createWriteStream(curDest)); | ||
} else if (stat.isDirectory()) { | ||
// 目录,进行递归 | ||
_nodeFs["default"].mkdirSync(curDest, { | ||
recursive: true | ||
}); | ||
copy(curSrc, curDest); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
_nodeFs["default"].access(dest, function (err) { | ||
if (err) { | ||
// 若目标目录不存在,则创建 | ||
_nodeFs["default"].mkdirSync(dest, { | ||
recursive: true | ||
}); | ||
} | ||
copy(src, dest); | ||
}); | ||
} |
{ | ||
"name": "balm-git-flow", | ||
"version": "0.3.2-legacy", | ||
"version": "0.3.2", | ||
"description": "The best practices for front-end git flow", | ||
@@ -20,6 +20,3 @@ "keywords": [ | ||
}, | ||
"files": [ | ||
"bin", | ||
"lib" | ||
], | ||
"type": "module", | ||
"bin": { | ||
@@ -32,3 +29,2 @@ "balm-git": "bin/balm-git.js", | ||
"scripts": { | ||
"build": "gulp prepublish", | ||
"test:doctor": "node ./bin/balm-doctor.js", | ||
@@ -48,16 +44,9 @@ "test:dev": "node ./bin/balm-dev.js", | ||
"dependencies": { | ||
"chalk": "4", | ||
"chalk": "^5.2.0", | ||
"commander": "^10.0.0", | ||
"del": "6", | ||
"inquirer": "8" | ||
"inquirer": "^9.1.4" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.21.0", | ||
"@babel/preset-env": "^7.20.2", | ||
"gulp": "^4.0.2", | ||
"gulp-babel": "^8.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=14.18.0" | ||
"node": ">=12.20.0" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3
0
16
0
Yes
17261
434
+ Added@inquirer/figures@1.0.9(transitive)
+ Addedchalk@5.4.1(transitive)
+ Addedcli-width@4.1.0(transitive)
+ Addedinquirer@9.3.7(transitive)
+ Addedmute-stream@1.0.0(transitive)
+ Addedrun-async@3.0.0(transitive)
+ Addedyoctocolors-cjs@2.1.2(transitive)
- Removeddel@6
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removedaggregate-error@3.1.0(transitive)
- Removedarray-union@2.1.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbraces@3.0.3(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedcli-width@3.0.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddel@6.1.1(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfast-glob@3.3.3(transitive)
- Removedfastq@1.18.0(transitive)
- Removedfigures@3.2.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedglobby@11.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedignore@5.3.2(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinquirer@8.2.6(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedis-path-cwd@2.2.0(transitive)
- Removedis-path-inside@3.0.3(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedmute-stream@0.0.8(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-map@4.0.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedrun-async@2.4.1(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedslash@3.0.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedchalk@^5.2.0
Updatedinquirer@^9.1.4