UNPKG

4.78 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3/* eslint-disable complexity */
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.runCli = exports.execute = void 0;
6const tslib_1 = require("tslib");
7const core_1 = tslib_1.__importStar(require("@auto-it/core"));
8const endent_1 = tslib_1.__importDefault(require("endent"));
9const await_to_js_1 = tslib_1.__importDefault(require("await-to-js"));
10const terminal_link_1 = tslib_1.__importDefault(require("terminal-link"));
11/** Spin up the "auto" node API and provide it the parsed CLI args. */
12async function execute(command, args) {
13 var _a, _b;
14 const auto = new core_1.default(args);
15 try {
16 if (command === "init") {
17 await auto.init();
18 return;
19 }
20 await auto.loadConfig();
21 if (args.verbose || command === "info") {
22 try {
23 // We don't want auto.info throwing an error during another
24 // command
25 const { hasError } = await auto.info(args);
26 if (command === "info") {
27 // eslint-disable-next-line max-depth
28 if (hasError) {
29 process.exit(1);
30 }
31 else {
32 return;
33 }
34 }
35 }
36 catch (error) {
37 if (command === "info") {
38 process.exit(1);
39 }
40 }
41 }
42 switch (command) {
43 case "create-labels":
44 await auto.createLabels(args);
45 break;
46 case "label":
47 await auto.label(args);
48 break;
49 case "pr-check":
50 await auto.prCheck(args);
51 break;
52 case "pr-status":
53 await auto.prStatus(args);
54 break;
55 case "comment":
56 await auto.comment(args);
57 break;
58 case "pr-body":
59 await auto.prBody(args);
60 break;
61 case "version":
62 await auto.version(args);
63 break;
64 case "changelog":
65 await auto.changelog(args);
66 break;
67 case "release":
68 await auto.runRelease(args);
69 break;
70 case "shipit":
71 await auto.shipit(args);
72 break;
73 case "latest":
74 await auto.latest(args);
75 break;
76 case "canary":
77 await auto.canary(args);
78 break;
79 case "next":
80 await auto.next(args);
81 break;
82 default:
83 throw new Error(`idk what i'm doing.`);
84 }
85 }
86 catch (error) {
87 if (error.status === 404) {
88 const [, project] = await await_to_js_1.default(auto.git.getProject());
89 const repoLink = terminal_link_1.default(`${(_a = auto.git) === null || _a === void 0 ? void 0 : _a.options.owner}/${(_b = auto.git) === null || _b === void 0 ? void 0 : _b.options.repo}`, (project === null || project === void 0 ? void 0 : project.html_url) || "");
90 auto.logger.log.error(endent_1.default `
91 Received 404!
92
93 This usually because the GitHub token you're using doesn't have the correct permissions to the repo.
94
95 The token used with auto must have at least "write" permission to your repo (${repoLink}) to create releases and labels.
96
97 You can check the permission for your token by running "auto info".
98 `);
99 console.log("");
100 auto.logger.verbose.error(error);
101 }
102 else if (error.message.includes("TypeError: Cannot read property 'tap")) {
103 auto.logger.log.error(endent_1.default `
104 One of the plugins you're using calls an unknown hook!
105
106 This usually because your project is trying to use mismatched plugin + core version.
107
108 To fix this do one of the following:
109
110 1. Ensure that you have the same version of auto and it's plugins installed
111 2. Ensure that any non-official plugins use the same version of @auto-it/core
112 3. Ensure your environment's version of auto matches the plugins you're using
113 `);
114 auto.logger.log.error(error);
115 }
116 else if (!(error instanceof core_1.LabelExistsError)) {
117 console.log(error);
118 }
119 process.exit(1);
120 }
121 finally {
122 await auto.teardown();
123 }
124}
125exports.execute = execute;
126/** Run "auto" for a given command. */
127async function runCli(command, args) {
128 await execute(command, args);
129}
130exports.runCli = runCli;
131//# sourceMappingURL=run.js.map
\No newline at end of file