UNPKG

2.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.push = exports.setTag = exports.isHeadTag = exports.tagExists = void 0;
4const command_join_1 = require("command-join");
5const utils_1 = require("./utils");
6async function tagExists(tagName) {
7 try {
8 const { stdout } = await utils_1.execFileAsync('git', ['tag', '-l', tagName]);
9 return stdout.split(/[\r\n]+/).includes(tagName);
10 }
11 catch (error) {
12 throw new Error(`tagExists() Error: ${error}`);
13 }
14}
15exports.tagExists = tagExists;
16async function isHeadTag(tagName) {
17 try {
18 const { stdout } = await utils_1.execFileAsync('git', [
19 'tag',
20 '-l',
21 tagName,
22 '--points-at',
23 'HEAD',
24 ]);
25 return stdout.split(/[\r\n]+/).includes(tagName);
26 }
27 catch (error) {
28 throw new Error(`isHeadTag() Error: ${error}`);
29 }
30}
31exports.isHeadTag = isHeadTag;
32function genTagCmdArgs(tagName, message, sign = false) {
33 const command = 'git';
34 const args = sign || typeof message === 'string'
35 ? /**
36 * @see https://github.com/npm/cli/blob/v6.13.0/lib/version.js#L304
37 */
38 ['tag', tagName, sign ? '-sm' : '-m', message || '']
39 : ['tag', tagName];
40 return {
41 command,
42 args,
43 get commandText() {
44 return `${command} ${command_join_1.commandJoin(args)}`;
45 },
46 };
47}
48async function setTag(tagName, { message, sign, debug = false, dryRun = false, } = {}) {
49 const cmd = genTagCmdArgs(tagName, message, sign);
50 if (typeof debug === 'function') {
51 utils_1.printVerbose(debug(cmd.commandText));
52 }
53 else if (debug) {
54 utils_1.printVerbose(`> ${cmd.commandText}`);
55 }
56 if (!dryRun) {
57 try {
58 await utils_1.execFileAsync(cmd.command, cmd.args);
59 }
60 catch (error) {
61 throw new Error(`setTag() Error: ${error}`);
62 }
63 }
64}
65exports.setTag = setTag;
66async function push(src, { repository = 'origin', debug = false, dryRun = false, } = {}) {
67 try {
68 const args = ['push', repository, src];
69 if (debug) {
70 utils_1.printVerbose(`> git ${command_join_1.commandJoin(args)}`);
71 }
72 if (!dryRun) {
73 await utils_1.execFileAsync('git', args);
74 }
75 }
76 catch (error) {
77 throw new Error(`push() Error: ${error}`);
78 }
79}
80exports.push = push;
81//# sourceMappingURL=git.js.map
\No newline at end of file