UNPKG

19.7 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.commands = void 0;
4const tslib_1 = require("tslib");
5const chalk_1 = tslib_1.__importDefault(require("chalk"));
6const command_line_application_1 = require("command-line-application");
7const endent_1 = tslib_1.__importDefault(require("endent"));
8const core_1 = require("@auto-it/core");
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 base 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 noGitCommit = {
108 name: "no-git-commit",
109 type: Boolean,
110 description: "Do not commit changes",
111 group: "main",
112};
113const url = {
114 name: "url",
115 type: String,
116 description: "URL to associate with this status",
117 group: "main",
118};
119const noVersionPrefix = {
120 name: "no-version-prefix",
121 type: Boolean,
122 description: "Use the version as the tag without the 'v' prefix. WARNING: some plugins might need extra config to use this option (ex: npm)",
123 group: "main",
124};
125const name = {
126 name: "name",
127 type: String,
128 description: "Git name to commit with. Defaults to package definition for the platform",
129 group: "main",
130};
131const email = {
132 name: "email",
133 type: String,
134 description: "Git email to commit with. Defaults to package definition for the platform",
135 group: "main",
136};
137const context = {
138 name: "context",
139 type: String,
140 description: "A string label to differentiate this status from others",
141 group: "main",
142};
143const message = {
144 name: "message",
145 group: "main",
146 type: String,
147 alias: "m",
148};
149const changelogTitle = {
150 name: "title",
151 type: String,
152 group: "main",
153 description: "Override the title used in the addition to the CHANGELOG.md.",
154};
155const changelogCommitMessage = Object.assign(Object.assign({}, message), { description: "Message to commit the changelog with. Defaults to 'Update CHANGELOG.md [skip ci]'", config: true });
156const noChangelog = {
157 name: "no-changelog",
158 type: Boolean,
159 group: "main",
160 description: "Skip creating the changelog",
161 config: true,
162};
163const force = {
164 name: "force",
165 type: Boolean,
166 group: "main",
167 config: true,
168};
169const useVersion = {
170 name: "use-version",
171 type: String,
172 group: "main",
173 description: "Version number to publish as. Defaults to reading from the package definition for the platform.",
174};
175const latestCommandArgs = [
176 name,
177 email,
178 onlyPublishWithReleaseLabel,
179 baseBranch,
180 dryRun,
181 noVersionPrefix,
182 prerelease,
183 changelogTitle,
184 changelogCommitMessage,
185 quiet,
186 noChangelog,
187];
188exports.commands = [
189 {
190 name: "init",
191 group: "Setup Command",
192 description: "Interactive setup for minimum working configuration.",
193 examples: ["{green $} auto init"],
194 },
195 {
196 name: "info",
197 group: "Setup Command",
198 description: "Determine the environment, check if auto is set up correctly, and list plugins.",
199 examples: ["{green $} auto info"],
200 options: [
201 {
202 name: "list-plugins",
203 type: Boolean,
204 description: "List the available plugins",
205 group: "main",
206 },
207 ],
208 },
209 {
210 name: "create-labels",
211 group: "Setup Command",
212 description: "Create your project's labels on github. If labels exist it will update them.",
213 examples: ["{green $} auto create-labels"],
214 options: [dryRun],
215 },
216 {
217 name: "label",
218 group: "Pull Request Interaction Commands",
219 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!",
220 options: [
221 Object.assign(Object.assign({}, pr), { description: `${pr.description} (defaults to last merged PR)` }),
222 {
223 name: "exists",
224 type: String,
225 group: "main",
226 description: "Checks for existence of a specific label",
227 },
228 ],
229 examples: ["{green $} auto label --pr 123"],
230 },
231 {
232 name: "comment",
233 group: "Pull Request Interaction Commands",
234 description: "Comment on a pull request with a markdown message. Each comment has a context, and each context only has one comment.",
235 require: [["message", "delete"]],
236 options: [
237 pr,
238 context,
239 {
240 name: "edit",
241 type: Boolean,
242 alias: "e",
243 group: "main",
244 description: "Edit old comment",
245 config: true,
246 },
247 {
248 name: "delete",
249 type: Boolean,
250 group: "main",
251 description: "Delete old comment",
252 config: true,
253 },
254 Object.assign(Object.assign({}, message), { description: "Message to post to comment" }),
255 dryRun,
256 ],
257 examples: [
258 "{green $} auto comment --delete",
259 '{green $} auto comment --pr 123 --message "# Why you\'re wrong..."',
260 '{green $} auto comment --pr 123 --edit --message "This smells..." --context code-smell',
261 ],
262 },
263 {
264 name: "pr-check",
265 group: "Pull Request Interaction Commands",
266 description: "Check that a pull request has a SemVer label and run all pr-check plugins.",
267 require: ["url"],
268 options: [
269 pr,
270 url,
271 dryRun,
272 Object.assign(Object.assign({}, context), { defaultValue: "ci/pr-check" }),
273 ],
274 examples: ["{green $} auto pr-check --url http://your-ci.com/build/123"],
275 },
276 {
277 name: "pr-status",
278 group: "Pull Request Interaction Commands",
279 description: "Set the status on a PR commit",
280 require: ["state", "url", "description", "context"],
281 options: [
282 {
283 name: "sha",
284 type: String,
285 group: "main",
286 description: "Specify a custom git sha. Defaults to the HEAD for a git repo in the current repository",
287 },
288 Object.assign(Object.assign({}, pr), { description: "PR to set the status on. Detects PR number in CI" }),
289 url,
290 {
291 name: "state",
292 type: String,
293 group: "main",
294 description: "State of the PR. ['pending', 'success', 'error', 'failure']",
295 },
296 {
297 name: "description",
298 type: String,
299 group: "main",
300 description: "A description of the status",
301 },
302 {
303 name: "context",
304 type: String,
305 group: "main",
306 description: "A string label to differentiate this status from others",
307 },
308 dryRun,
309 ],
310 examples: [
311 `{green $} auto pr-status \\\\ \n --state pending \\\\ \n --description "Build still running..." \\\\ \n --context build-check`,
312 ],
313 },
314 {
315 name: "pr-body",
316 group: "Pull Request Interaction Commands",
317 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.",
318 require: ["message"],
319 options: [
320 pr,
321 context,
322 Object.assign(Object.assign({}, message), { description: "Message to post to PR body" }),
323 dryRun,
324 ],
325 examples: [
326 "{green $} auto pr-body --delete",
327 '{green $} auto pr-body --pr 123 --comment "The new version is: 1.2.3"',
328 ],
329 },
330 {
331 name: "version",
332 group: "Release Commands",
333 description: endent_1.default `
334 Calculate a semantic version bump for the given changes.
335 Requires all PRs to have labels for the change type.
336 If a PR does not have a label associated with it, it will default to \`patch\` or whatever you configure the default label to.
337
338 NOTE: This does not change the version of your project or anything in your repo. It just returns \`patch\`, \`minor\`, or \`major\`.
339 `,
340 options: [
341 onlyPublishWithReleaseLabel,
342 {
343 name: "from",
344 type: String,
345 group: "main",
346 description: "Git revision (tag, commit sha, ...) to calculate version bump from. Defaults to latest github release",
347 },
348 ],
349 examples: [
350 {
351 desc: "Get the new version using the last release to head",
352 example: "{green $} auto version",
353 },
354 ],
355 },
356 {
357 name: "changelog",
358 group: "Release Commands",
359 description: "Prepend release notes to `CHANGELOG.md`, create one if it doesn't exist, and commit the changes.",
360 options: [
361 dryRun,
362 noVersionPrefix,
363 name,
364 email,
365 {
366 name: "from",
367 type: String,
368 group: "main",
369 description: "Tag to start changelog generation on. Defaults to latest tag or if a prerelease the latest tag in the branch. Provide latest to override.",
370 },
371 {
372 name: "to",
373 type: String,
374 group: "main",
375 description: "Tag to end changelog generation on. Defaults to HEAD.",
376 },
377 changelogTitle,
378 changelogCommitMessage,
379 baseBranch,
380 quiet,
381 noGitCommit,
382 ],
383 examples: [
384 {
385 desc: "Generate a changelog from the last release to head",
386 example: "{green $} auto changelog",
387 },
388 {
389 desc: "Generate a changelog across specific versions",
390 example: "{green $} auto changelog --from v0.20.1 --to v0.21.0",
391 },
392 ],
393 },
394 {
395 name: "release",
396 group: "Release Commands",
397 description: endent_1.default `
398 Create a GitHub release for a tag. Defaults to last tag in branch.
399
400 > NOTE: The tag must already be pushed to GitHub. If it isn't GitHub will create a tag pointing to the "to" option value.
401 `,
402 options: [
403 dryRun,
404 noVersionPrefix,
405 name,
406 email,
407 {
408 name: "from",
409 type: String,
410 group: "main",
411 description: "Tag to start changelog generation on. Defaults to latest tag or if a prerelease the latest tag in the branch. Provide latest to override.",
412 },
413 {
414 name: "to",
415 type: String,
416 group: "main",
417 description: "Git revision (tag, commit sha, ...) to end release notes at. Defaults to HEAD.",
418 },
419 useVersion,
420 baseBranch,
421 prerelease,
422 ],
423 examples: [
424 {
425 desc: "Create a GitHub release",
426 example: "{green $} auto release",
427 },
428 {
429 desc: "Create a GitHub release using provided commit range and version",
430 example: "{green $} auto release --from v0.20.1 --to HEAD --use-version v0.21.0",
431 },
432 ],
433 },
434 {
435 name: "shipit",
436 group: "Release Commands",
437 description: endent_1.default `
438 Context aware publishing.
439
440 1. call from base branch -> latest version released (LATEST)
441 2. call from prerelease branch -> prerelease version released (NEXT)
442 3. call from PR in CI -> canary version released (CANARY)
443 4. call locally when not on base/prerelease branch -> canary version released (CANARY)
444 `,
445 examples: ["{green $} auto shipit"],
446 options: [
447 ...latestCommandArgs,
448 Object.assign(Object.assign({}, useVersion), { description: `${useVersion.description} Currently only supported for the **npm plugin**.` }),
449 {
450 name: "only-graduate-with-release-label",
451 type: Boolean,
452 defaultValue: false,
453 group: "main",
454 description: 'Make auto publish prerelease versions when merging to baseBranch. 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 baseBranch.',
455 config: true,
456 },
457 ],
458 },
459 {
460 name: "latest",
461 group: "Release Commands",
462 description: endent_1.default `
463 Run the full \`auto\` release pipeline. Force a release to latest and bypass \`shipit\` safeguards.
464 `,
465 examples: ["{green $} auto latest"],
466 options: latestCommandArgs,
467 },
468 {
469 name: "canary",
470 group: "Release Commands",
471 description: endent_1.default `
472 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".
473
474 1. In PR: 1.2.3-canary.123.0 + add version to PR body
475 2. Locally: 1.2.3-canary.1810cfd
476 `,
477 examples: [
478 "{green $} auto canary",
479 "{green $} auto canary --force",
480 "{green $} auto canary --pr 123 --build 5",
481 '{green $} auto canary --message "Install PR version: `yarn add -D my-project@%v`"',
482 "{green $} auto canary --message false",
483 ],
484 options: [
485 dryRun,
486 Object.assign(Object.assign({}, pr), { description: "PR number to use to create the canary version. Detected in CI env" }),
487 {
488 name: "build",
489 type: String,
490 group: "main",
491 description: "Build number to use to create the canary version. Detected in CI env",
492 },
493 {
494 name: "target",
495 type: String,
496 group: "main",
497 defaultValue: "pr-body",
498 description: "How the canary version should be attached to a PR",
499 typeLabel: "pr-body | comment | status",
500 config: true,
501 },
502 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 }),
503 Object.assign(Object.assign({}, force), { description: "Force a next release, even if the last commit is marked to skip the release" }),
504 quiet,
505 ],
506 },
507 {
508 name: "next",
509 group: "Release Commands",
510 description: endent_1.default `
511 Make a release for your "prerelease" release line. This is ran automatically by "shipit" in a prerelease branch.
512
513 1. Creates a prerelease on package management platform
514 2. Creates a "Pre Release" on GitHub releases page
515 3. If ran from a PR build in a CI, posts the prerelease's full releases notes and expected version of the prerelease
516
517 Calling the \`next\` command from a prerelease branch will publish a prerelease for just that branch, otherwise it will publish to the default prerelease branch.
518 `,
519 examples: ["{green $} auto next"],
520 options: [
521 dryRun,
522 Object.assign(Object.assign({}, message), { description: "The message used when attaching the prerelease version to a PR", config: true }),
523 Object.assign(Object.assign({}, force), { description: "Force a canary release, even if the PR is marked to skip the release" }),
524 quiet,
525 ],
526 },
527];
528/** Parse the CLI args and return command + options provided. */
529function parseArgs(testArgs) {
530 const mainOptions = command_line_application_1.app({
531 name: "auto",
532 logo,
533 description: "Generate releases based on semantic version labels on pull requests, and other pull request automation tools.",
534 commands: exports.commands,
535 options: [version, ...defaultOptions],
536 }, {
537 argv: testArgs,
538 });
539 if (!mainOptions) {
540 return [];
541 }
542 if (!mainOptions._command) {
543 if (mainOptions.version) {
544 const version = "11.1.6" || core_1.getAutoVersion();
545 console.log(`v${version}`);
546 }
547 return [];
548 }
549 return [mainOptions._command, mainOptions];
550}
551exports.default = parseArgs;
552//# sourceMappingURL=parse-args.js.map
\No newline at end of file