UNPKG

17.7 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.commands = void 0;
4const tslib_1 = require("tslib");
5const core_1 = require("@auto-it/core");
6const chalk_1 = tslib_1.__importDefault(require("chalk"));
7const command_line_application_1 = require("command-line-application");
8const endent_1 = tslib_1.__importDefault(require("endent"));
9const p = chalk_1.default.hex("#870048");
10const y = chalk_1.default.hex("#F1A60E");
11const r = chalk_1.default.hex("#C5000B");
12const g = chalk_1.default.hex("#888888");
13// prettier-ignore
14const logo = `
15 ${y('_________')}
16 ${p('/')}${y('\\ /')}${r('\\')} _______ _ _ _______ _____
17 ${p('/')} ${y('\\_____/')} ${r('\\')} |_____| | | | | |
18 ${p('/ /')} ${r('\\ \\')} | | |_____| | |_____|
19 ${p('/___/')} \\▔▔\\ ${r(' \\___\\')}
20 ${g('\\ \\')} \\_/ ${g('/ /')} ______ _______ _______ _______ _______ _______
21 ${g('\\ \\')} ${g('/ /')} |_____/ |______ | |______ |_____| |______ |______
22 ${g('\\ ▔▔▔▔▔ /')} | \\_ |______ |_____ |______ | | ______| |______
23 ${g('\\ /')}
24 ${g('▔▔▔▔▔▔▔▔▔ ')}
25`.replace(/\\/g, '\\\\');
26const version = {
27 name: "version",
28 alias: "V",
29 type: Boolean,
30 description: "Display auto's version",
31 group: "global",
32};
33const prerelease = {
34 name: "prerelease",
35 type: Boolean,
36 group: "main",
37 description: "Publish a prerelease on GitHub.",
38 config: true,
39};
40const onlyPublishWithReleaseLabel = {
41 name: "only-publish-with-release-label",
42 type: Boolean,
43 description: "Only bump version if 'release' label is on pull request",
44 group: "main",
45};
46const quiet = {
47 name: "quiet",
48 alias: "q",
49 type: Boolean,
50 description: "Print **only** the result of the command",
51 group: "global",
52};
53const defaultOptions = [
54 {
55 name: "verbose",
56 alias: "v",
57 type: Boolean,
58 description: "Show some more logs. Pass -vv for very verbose logs.",
59 group: "global",
60 multiple: true,
61 },
62 {
63 name: "repo",
64 type: String,
65 description: "The repo to set the status on. Defaults to looking in the package definition for the platform",
66 group: "global",
67 },
68 {
69 name: "owner",
70 type: String,
71 description: "The owner of the GitHub repo. Defaults to reading from the package definition for the platform",
72 group: "global",
73 },
74 {
75 name: "github-api",
76 type: String,
77 description: "GitHub API to use",
78 group: "global",
79 },
80 {
81 name: "plugins",
82 type: String,
83 multiple: true,
84 description: "Plugins to load auto with. (defaults to just npm)",
85 group: "global",
86 },
87];
88const baseBranch = {
89 name: "base-branch",
90 type: String,
91 description: 'Branch to treat as the "master" branch',
92 group: "global",
93};
94const pr = {
95 name: "pr",
96 type: Number,
97 description: "The pull request the command should use. Detects PR number in CI",
98 group: "main",
99};
100const dryRun = {
101 name: "dry-run",
102 alias: "d",
103 type: Boolean,
104 description: "Report what command will do but do not actually do anything",
105 group: "main",
106};
107const url = {
108 name: "url",
109 type: String,
110 description: "URL to associate with this status",
111 group: "main",
112};
113const noVersionPrefix = {
114 name: "no-version-prefix",
115 type: Boolean,
116 description: "Use the version as the tag without the 'v' prefix. WARNING: some plugins might need extra config to use this option (ex: npm)",
117 group: "main",
118};
119const name = {
120 name: "name",
121 type: String,
122 description: "Git name to commit with. Defaults to package definition for the platform",
123 group: "main",
124};
125const email = {
126 name: "email",
127 type: String,
128 description: "Git email to commit with. Defaults to package definition for the platform",
129 group: "main",
130};
131const context = {
132 name: "context",
133 type: String,
134 description: "A string label to differentiate this status from others",
135 group: "main",
136};
137const message = {
138 name: "message",
139 group: "main",
140 type: String,
141 alias: "m",
142};
143const changelogTitle = {
144 name: "title",
145 type: String,
146 group: "main",
147 description: "Override the title used in the addition to the CHANGELOG.md.",
148};
149const changelogCommitMessage = Object.assign(Object.assign({}, message), { description: "Message to commit the changelog with. Defaults to 'Update CHANGELOG.md [skip ci]'", config: true });
150const noChangelog = {
151 name: "no-changelog",
152 type: Boolean,
153 group: "main",
154 description: "Skip creating the changelog",
155 config: true,
156};
157const latestCommandArgs = [
158 name,
159 email,
160 onlyPublishWithReleaseLabel,
161 baseBranch,
162 dryRun,
163 noVersionPrefix,
164 prerelease,
165 changelogTitle,
166 changelogCommitMessage,
167 quiet,
168 noChangelog,
169];
170exports.commands = [
171 {
172 name: "init",
173 group: "Setup Command",
174 description: "Interactive setup for minimum working configuration.",
175 examples: ["{green $} auto init"],
176 },
177 {
178 name: "info",
179 group: "Setup Command",
180 description: "Determine the environment, check if auto is set up correctly, and list plugins.",
181 examples: ["{green $} auto info"],
182 options: [
183 {
184 name: "list-plugins",
185 type: Boolean,
186 description: "List the available plugins",
187 group: "main",
188 },
189 ],
190 },
191 {
192 name: "create-labels",
193 group: "Setup Command",
194 description: "Create your project's labels on github. If labels exist it will update them.",
195 examples: ["{green $} auto create-labels"],
196 options: [dryRun],
197 },
198 {
199 name: "label",
200 group: "Pull Request Interaction Commands",
201 description: "Get the labels for a pull request. Doesn't do much, but the return value lets you write you own scripts based off of the PR labels!",
202 options: [
203 Object.assign(Object.assign({}, pr), { description: `${pr.description} (defaults to last merged PR)` }),
204 ],
205 examples: ["{green $} auto label --pr 123"],
206 },
207 {
208 name: "comment",
209 group: "Pull Request Interaction Commands",
210 description: "Comment on a pull request with a markdown message. Each comment has a context, and each context only has one comment.",
211 require: [["message", "delete"]],
212 options: [
213 pr,
214 context,
215 {
216 name: "edit",
217 type: Boolean,
218 alias: "e",
219 group: "main",
220 description: "Edit old comment",
221 config: true,
222 },
223 {
224 name: "delete",
225 type: Boolean,
226 group: "main",
227 description: "Delete old comment",
228 config: true,
229 },
230 Object.assign(Object.assign({}, message), { description: "Message to post to comment" }),
231 dryRun,
232 ],
233 examples: [
234 "{green $} auto comment --delete",
235 '{green $} auto comment --pr 123 --message "# Why you\'re wrong..."',
236 '{green $} auto comment --pr 123 --edit --message "This smells..." --context code-smell',
237 ],
238 },
239 {
240 name: "pr-check",
241 group: "Pull Request Interaction Commands",
242 description: "Check that a pull request has a SemVer label",
243 require: ["url"],
244 options: [
245 pr,
246 url,
247 dryRun,
248 Object.assign(Object.assign({}, context), { defaultValue: "ci/pr-check" }),
249 ],
250 examples: ["{green $} auto pr-check --url http://your-ci.com/build/123"],
251 },
252 {
253 name: "pr-status",
254 group: "Pull Request Interaction Commands",
255 description: "Set the status on a PR commit",
256 require: ["state", "url", "description", "context"],
257 options: [
258 {
259 name: "sha",
260 type: String,
261 group: "main",
262 description: "Specify a custom git sha. Defaults to the HEAD for a git repo in the current repository",
263 },
264 Object.assign(Object.assign({}, pr), { description: "PR to set the status on. Detects PR number in CI" }),
265 url,
266 {
267 name: "state",
268 type: String,
269 group: "main",
270 description: "State of the PR. ['pending', 'success', 'error', 'failure']",
271 },
272 {
273 name: "description",
274 type: String,
275 group: "main",
276 description: "A description of the status",
277 },
278 {
279 name: "context",
280 type: String,
281 group: "main",
282 description: "A string label to differentiate this status from others",
283 },
284 dryRun,
285 ],
286 examples: [
287 `{green $} auto pr-status \\\\ \n --state pending \\\\ \n --description "Build still running..." \\\\ \n --context build-check`,
288 ],
289 },
290 {
291 name: "pr-body",
292 group: "Pull Request Interaction Commands",
293 description: "Update the body of a PR with a message. Appends to PR and will not overwrite user content. Each comment has a context, and each context only has one comment.",
294 require: ["message"],
295 options: [
296 pr,
297 context,
298 Object.assign(Object.assign({}, message), { description: "Message to post to PR body" }),
299 dryRun,
300 ],
301 examples: [
302 "{green $} auto pr-body --delete",
303 '{green $} auto pr-body --pr 123 --comment "The new version is: 1.2.3"',
304 ],
305 },
306 {
307 name: "version",
308 group: "Release Commands",
309 description: "Get the semantic version bump for the given changes. Requires all PRs to have labels for the change type. If a PR does not have a label associated with it, it will default to `patch`.",
310 options: [
311 onlyPublishWithReleaseLabel,
312 {
313 name: "from",
314 type: String,
315 group: "main",
316 description: "Git revision (tag, commit sha, ...) to calculate version bump from. Defaults to latest github release",
317 },
318 ],
319 examples: [
320 {
321 desc: "Get the new version using the last release to head",
322 example: "{green $} auto version",
323 },
324 ],
325 },
326 {
327 name: "changelog",
328 group: "Release Commands",
329 description: "Prepend release notes to `CHANGELOG.md`, create one if it doesn't exist, and commit the changes.",
330 options: [
331 dryRun,
332 noVersionPrefix,
333 name,
334 email,
335 {
336 name: "from",
337 type: String,
338 group: "main",
339 description: "Tag to start changelog generation on. Defaults to latest tag.",
340 },
341 {
342 name: "to",
343 type: String,
344 group: "main",
345 description: "Tag to end changelog generation on. Defaults to HEAD.",
346 },
347 changelogTitle,
348 changelogCommitMessage,
349 baseBranch,
350 quiet,
351 ],
352 examples: [
353 {
354 desc: "Generate a changelog from the last release to head",
355 example: "{green $} auto changelog",
356 },
357 {
358 desc: "Generate a changelog across specific versions",
359 example: "{green $} auto changelog --from v0.20.1 --to v0.21.0",
360 },
361 ],
362 },
363 {
364 name: "release",
365 group: "Release Commands",
366 description: "Auto-generate a github release",
367 options: [
368 dryRun,
369 noVersionPrefix,
370 name,
371 email,
372 {
373 name: "from",
374 type: String,
375 group: "main",
376 description: "Git revision (tag, commit sha, ...) to start release notes from. Defaults to latest tag.",
377 },
378 {
379 name: "to",
380 type: String,
381 group: "main",
382 description: "Git revision (tag, commit sha, ...) to end release notes at. Defaults to HEAD",
383 },
384 {
385 name: "use-version",
386 type: String,
387 group: "main",
388 description: "Version number to publish as. Defaults to reading from the package definition for the platform.",
389 },
390 baseBranch,
391 prerelease,
392 ],
393 examples: [
394 "{green $} auto release",
395 "{green $} auto release --from v0.20.1 --use-version v0.21.0",
396 ],
397 },
398 {
399 name: "shipit",
400 group: "Release Commands",
401 description: endent_1.default `
402 Context aware publishing.
403
404 1. call from base branch -> latest version released (LATEST)
405 2. call from prerelease branch -> prerelease version released (NEXT)
406 3. call from PR in CI -> canary version released (CANARY)
407 4. call locally when not on base/prerelease branch -> canary version released (CANARY)
408 `,
409 examples: ["{green $} auto shipit"],
410 options: [
411 ...latestCommandArgs,
412 {
413 name: "only-graduate-with-release-label",
414 type: Boolean,
415 defaultValue: false,
416 group: "main",
417 description: 'Make auto publish prerelease versions when merging to master. Only PRs merged with "release" label will generate a "latest" release. Only use this flag if you do not want to maintain a prerelease branch, and instead only want to use master.',
418 config: true,
419 },
420 ],
421 },
422 {
423 name: "latest",
424 group: "Release Commands",
425 description: endent_1.default `
426 Run the full \`auto\` release pipeline. Force a release to latest and bypass \`shipit\` safeguards.
427 `,
428 examples: ["{green $} auto latest"],
429 options: latestCommandArgs,
430 },
431 {
432 name: "canary",
433 group: "Release Commands",
434 description: endent_1.default `
435 Make a canary release of the project. Useful on PRs. If ran locally, \`canary\` will release a canary version for your current git HEAD. This is ran automatically from "shipit".
436
437 1. In PR: 1.2.3-canary.123.0 + add version to PR body
438 2. Locally: 1.2.3-canary.1810cfd
439 `,
440 examples: [
441 "{green $} auto canary",
442 "{green $} auto canary --force",
443 "{green $} auto canary --pr 123 --build 5",
444 '{green $} auto canary --message "Install PR version: `yarn add -D my-project@%v`"',
445 "{green $} auto canary --message false",
446 ],
447 options: [
448 dryRun,
449 Object.assign(Object.assign({}, pr), { description: "PR number to use to create the canary version. Detected in CI env" }),
450 {
451 name: "build",
452 type: String,
453 group: "main",
454 description: "Build number to use to create the canary version. Detected in CI env",
455 },
456 Object.assign(Object.assign({}, message), { description: "Message to comment on PR with. Defaults to 'Published PR with canary version: %v'. Pass false to disable the comment", config: true }),
457 {
458 name: "force",
459 type: Boolean,
460 group: "main",
461 description: "Force a canary release, even if the PR is marked to skip the release",
462 config: true,
463 },
464 quiet,
465 ],
466 },
467 {
468 name: "next",
469 group: "Release Commands",
470 description: endent_1.default `
471 Make a release for your "prerelease" release line. This is ran automatically from "shipit".
472
473 1. Creates a prerelease on package management platform
474 2. Creates a "Pre Release" on GitHub releases page.
475
476 Calling the \`next\` command from a prerelease branch will publish a prerelease, otherwise it will publish to the default prerelease branch.
477 `,
478 examples: ["{green $} auto next"],
479 options: [
480 dryRun,
481 Object.assign(Object.assign({}, message), { description: "The message used when attaching the prerelease version to a PR", config: true }),
482 quiet,
483 ],
484 },
485];
486/** Parse the CLI args and return command + options provided. */
487function parseArgs(testArgs) {
488 const mainOptions = command_line_application_1.app({
489 name: "auto",
490 logo,
491 description: "Generate releases based on semantic version labels on pull requests, and other pull request automation tools.",
492 commands: exports.commands,
493 options: [version, ...defaultOptions],
494 }, {
495 argv: testArgs,
496 });
497 if (!mainOptions) {
498 return [];
499 }
500 if (!mainOptions._command) {
501 if (mainOptions.version) {
502 console.log(`v${core_1.getAutoVersion()}`);
503 }
504 return [];
505 }
506 return [mainOptions._command, mainOptions];
507}
508exports.default = parseArgs;
509//# sourceMappingURL=parse-args.js.map
\No newline at end of file