UNPKG

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