UNPKG

@eljs/utils

Version:
107 lines (105 loc) 2.88 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/git/operate.ts var operate_exports = {}; __export(operate_exports, { gitCommit: () => gitCommit, gitPush: () => gitPush, gitTag: () => gitTag }); module.exports = __toCommonJS(operate_exports); var import_cp = require("../cp"); var import_type = require("../type"); var import_meta = require("./meta"); async function gitCommit(message, args, options) { if ((0, import_type.isObject)(args)) { options = args; args = []; } try { await (0, import_cp.run)("git", ["add", "-A"], options); await (0, import_cp.run)( "git", ["commit", "-m", message, ...args ? args : []], options ); } catch (error) { const err = error; if (/nothing to commit/.test(err.message) || /无文件要提交/.test(err.message)) { return; } err.message = `Git commit failed: ${err.message}.`; throw err; } } async function gitPush(args, options) { if ((0, import_type.isObject)(args)) { options = args; args = []; } try { const upstreamBranch = await (0, import_meta.getGitUpstreamBranch)({ ...options, verbose: false }); const upstreamArg = !upstreamBranch ? [ "--set-upstream", "origin", await (0, import_meta.getGitBranch)({ ...options, verbose: false }) ] : []; const cliArgs = [ "push", ...args ? args : [], ...upstreamArg ]; await (0, import_cp.run)("git", cliArgs, options); } catch (error) { const err = error; err.message = `Git push failed: ${err.message}`; throw err; } } async function gitTag(tagName, args, options) { if ((0, import_type.isObject)(args)) { options = args; args = []; } const cliArgs = [ "tag", tagName, "-m", tagName, ...args ? args : [] ]; try { await (0, import_cp.run)("git", cliArgs, options); } catch (error) { const err = error; err.message = `Git Tag failed: ${err.message}`; throw err; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { gitCommit, gitPush, gitTag });