1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const path = require("path");
|
4 | const git_1 = require("./git");
|
5 | const utils_1 = require("./utils");
|
6 | async function getVersionTagData() {
|
7 | const projectPkgPath = path.join(process.cwd(), 'package.json');
|
8 | const projectPkgData = await utils_1.readJSONFile(projectPkgPath);
|
9 | if (utils_1.isPkgData(projectPkgData)) {
|
10 | const { version } = projectPkgData;
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 | const prefix = await utils_1.getConfig({
|
17 | npm: 'tag-version-prefix',
|
18 | yarn: 'version-tag-prefix',
|
19 | });
|
20 | |
21 |
|
22 |
|
23 |
|
24 | const tagName = `${prefix}${version}`;
|
25 | |
26 |
|
27 |
|
28 |
|
29 | const message = (await utils_1.getConfig({ npm: 'message', yarn: 'version-git-message' })).replace(/%s/g, version);
|
30 | return { tagName, message };
|
31 | }
|
32 | throw new Error('Failed to find version tag name.');
|
33 | }
|
34 | async function gitTagAlreadyExists(versionTagName, tagMessage, opts) {
|
35 | if (!(await git_1.isHeadTag(versionTagName))) {
|
36 | throw new Error(`Git tag '${versionTagName}' already exists`);
|
37 | }
|
38 | if (opts.verbose) {
|
39 | await git_1.setTag(versionTagName, {
|
40 | message: tagMessage,
|
41 | debug: (commandText) => `> #${commandText}\n # tag '${versionTagName}' already exists`,
|
42 | dryRun: true,
|
43 | });
|
44 | }
|
45 | }
|
46 | async function main(opts) {
|
47 | if (opts.dryRun) {
|
48 | console.error('Dry Run enabled');
|
49 | opts.verbose = true;
|
50 | }
|
51 | const { tagName: versionTagName, message } = await getVersionTagData();
|
52 | if (await git_1.tagExists(versionTagName)) {
|
53 | await gitTagAlreadyExists(versionTagName, message, opts);
|
54 | }
|
55 | else {
|
56 | await git_1.setTag(versionTagName, {
|
57 | message,
|
58 | debug: opts.verbose,
|
59 | dryRun: opts.dryRun,
|
60 | });
|
61 | }
|
62 | if (opts.push) {
|
63 | await git_1.push(versionTagName, {
|
64 | debug: opts.verbose,
|
65 | dryRun: opts.dryRun,
|
66 | });
|
67 | }
|
68 | }
|
69 | async function default_1(opts = {}) {
|
70 | try {
|
71 | await main(opts);
|
72 | }
|
73 | finally {
|
74 | utils_1.endPrintVerbose();
|
75 | }
|
76 | }
|
77 | exports.default = default_1;
|
78 |
|
\ | No newline at end of file |