1 | "use strict";
|
2 | var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
3 | if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
4 | return cooked;
|
5 | };
|
6 | var __assign = (this && this.__assign) || function () {
|
7 | __assign = Object.assign || function(t) {
|
8 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
9 | s = arguments[i];
|
10 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
11 | t[p] = s[p];
|
12 | }
|
13 | return t;
|
14 | };
|
15 | return __assign.apply(this, arguments);
|
16 | };
|
17 | var __read = (this && this.__read) || function (o, n) {
|
18 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
19 | if (!m) return o;
|
20 | var i = m.call(o), r, ar = [], e;
|
21 | try {
|
22 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
23 | }
|
24 | catch (error) { e = { error: error }; }
|
25 | finally {
|
26 | try {
|
27 | if (r && !r.done && (m = i["return"])) m.call(i);
|
28 | }
|
29 | finally { if (e) throw e.error; }
|
30 | }
|
31 | return ar;
|
32 | };
|
33 | var __spread = (this && this.__spread) || function () {
|
34 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
35 | return ar;
|
36 | };
|
37 | var __importStar = (this && this.__importStar) || function (mod) {
|
38 | if (mod && mod.__esModule) return mod;
|
39 | var result = {};
|
40 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
41 | result["default"] = mod;
|
42 | return result;
|
43 | };
|
44 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
45 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
46 | };
|
47 | Object.defineProperty(exports, "__esModule", { value: true });
|
48 | var fs = __importStar(require("fs"));
|
49 | var path = __importStar(require("path"));
|
50 | var chalk_1 = __importDefault(require("chalk"));
|
51 | var command_line_args_1 = __importDefault(require("command-line-args"));
|
52 | var command_line_usage_1 = __importDefault(require("command-line-usage"));
|
53 | var dedent_1 = __importDefault(require("dedent"));
|
54 | var signale_1 = __importDefault(require("signale"));
|
55 | var p = chalk_1.default.hex('#870048');
|
56 | var y = chalk_1.default.hex('#F1A60E');
|
57 | var r = chalk_1.default.hex('#C5000B');
|
58 | var g = chalk_1.default.hex('#888888');
|
59 |
|
60 | var logo = "\n " + y('_________') + "\n " + p('/') + y('\\ /') + r('\\') + " _______ _ _ _______ _____\n " + p('/') + " " + y('\\_____/') + " " + r('\\') + " |_____| | | | | |\n " + p('/ /') + " " + r('\\ \\') + " | | |_____| | |_____|\n " + p('/___/') + " \\\u2594\u2594\\ " + r(' \\___\\') + "\n " + g('\\ \\') + " \\_/ " + g('/ /') + " ______ _______ _______ _______ _______ _______\n " + g('\\ \\') + " " + g('/ /') + " |_____/ |______ | |______ |_____| |______ |______\n " + g('\\ ▔▔▔▔▔ /') + " | \\_ |______ |_____ |______ | | ______| |______\n " + g('\\ /') + "\n " + g('▔▔▔▔▔▔▔▔▔ ') + "\n";
|
61 | var help = {
|
62 | name: 'help',
|
63 | alias: 'h',
|
64 | type: Boolean
|
65 | };
|
66 | var version = {
|
67 | name: 'version',
|
68 | alias: 'V',
|
69 | type: Boolean,
|
70 | description: "Display auto's version"
|
71 | };
|
72 | var mainDefinitions = [
|
73 | { name: 'command', type: String, defaultOption: true },
|
74 | __assign({}, help, { description: 'Display the help output. Works on each command as well' }),
|
75 | version
|
76 | ];
|
77 | var defaultOptions = [
|
78 | __assign({}, help, { description: 'Display the help output for the command', group: 'misc' }),
|
79 | {
|
80 | name: 'verbose',
|
81 | alias: 'v',
|
82 | type: Boolean,
|
83 | description: 'Show some more logs',
|
84 | group: 'misc'
|
85 | },
|
86 | {
|
87 | name: 'very-verbose',
|
88 | alias: 'w',
|
89 | type: Boolean,
|
90 | description: 'Show a lot more logs',
|
91 | group: 'misc'
|
92 | },
|
93 | {
|
94 | name: 'repo',
|
95 | type: String,
|
96 | description: 'The repo to set the status on. Defaults to looking in the package definition for the platform',
|
97 | group: 'misc'
|
98 | },
|
99 | {
|
100 | name: 'owner',
|
101 | type: String,
|
102 | description: 'The owner of the GitHub repo. Defaults to reading from the package definition for the platform',
|
103 | group: 'misc'
|
104 | },
|
105 | {
|
106 | name: 'github-api',
|
107 | type: String,
|
108 | description: 'GitHub API to use',
|
109 | group: 'misc'
|
110 | },
|
111 | {
|
112 | name: 'plugins',
|
113 | type: String,
|
114 | multiple: true,
|
115 | description: 'Plugins to load auto with. (defaults to just npm)',
|
116 | group: 'misc'
|
117 | }
|
118 | ];
|
119 | var baseBranch = {
|
120 | name: 'base-branch',
|
121 | type: String,
|
122 | description: 'Branch to treat as the "master" branch',
|
123 | group: 'misc'
|
124 | };
|
125 | var pr = {
|
126 | name: 'pr',
|
127 | type: Number,
|
128 | description: 'The pull request the command should use. Detects PR number in CI',
|
129 | group: 'main'
|
130 | };
|
131 | var dryRun = {
|
132 | name: 'dry-run',
|
133 | alias: 'd',
|
134 | type: Boolean,
|
135 | description: 'Report what command will do but do not actually do anything',
|
136 | group: 'main'
|
137 | };
|
138 | var url = {
|
139 | name: 'url',
|
140 | type: String,
|
141 | description: 'URL to associate with this status',
|
142 | group: 'main'
|
143 | };
|
144 | var noVersionPrefix = {
|
145 | name: 'no-version-prefix',
|
146 | type: Boolean,
|
147 | description: "Use the version as the tag without the 'v' prefix",
|
148 | group: 'main'
|
149 | };
|
150 | var jira = {
|
151 | name: 'jira',
|
152 | type: String,
|
153 | description: 'Jira base URL',
|
154 | group: 'main'
|
155 | };
|
156 | var name = {
|
157 | name: 'name',
|
158 | type: String,
|
159 | description: 'Git name to commit and release with. Defaults to package definition for the platform',
|
160 | group: 'main'
|
161 | };
|
162 | var email = {
|
163 | name: 'email',
|
164 | type: String,
|
165 | description: 'Git email to commit with. Defaults to package definition for the platform',
|
166 | group: 'main'
|
167 | };
|
168 | var context = {
|
169 | name: 'context',
|
170 | type: String,
|
171 | description: 'A string label to differentiate this status from others',
|
172 | group: 'main'
|
173 | };
|
174 | var message = {
|
175 | name: 'message',
|
176 | group: 'main',
|
177 | type: String,
|
178 | alias: 'm'
|
179 | };
|
180 | var skipReleaseLabels = {
|
181 | name: 'skip-release-labels',
|
182 | type: String,
|
183 | group: 'main',
|
184 | multiple: true,
|
185 | description: "Labels that will not create a release. Defaults to just 'skip-release'"
|
186 | };
|
187 | var commands = [
|
188 | {
|
189 | name: 'init',
|
190 | summary: 'Interactive setup for most configurable options',
|
191 | examples: ['{green $} auto init'],
|
192 | options: [
|
193 | {
|
194 | name: 'only-labels',
|
195 | type: Boolean,
|
196 | group: 'main',
|
197 | description: 'Only run init for the labels. As most other options are for advanced users'
|
198 | },
|
199 | dryRun
|
200 | ]
|
201 | },
|
202 | {
|
203 | name: 'create-labels',
|
204 | summary: "Create your project's labels on github. If labels exist it will update them.",
|
205 | examples: ['{green $} auto create-labels'],
|
206 | options: __spread(defaultOptions, [dryRun])
|
207 | },
|
208 | {
|
209 | name: 'label',
|
210 | summary: 'Get the labels for a pull request',
|
211 | options: __spread([
|
212 | __assign({}, pr, { description: pr.description + " (defaults to last merged PR)" })
|
213 | ], defaultOptions),
|
214 | examples: ['{green $} auto label --pr 123']
|
215 | },
|
216 | {
|
217 | name: 'pr-check',
|
218 | summary: 'Check that a pull request has a SemVer label',
|
219 | require: ['url'],
|
220 | options: __spread([
|
221 | pr,
|
222 | url,
|
223 | dryRun,
|
224 | __assign({}, context, { defaultValue: 'ci/pr-check' }),
|
225 | skipReleaseLabels
|
226 | ], defaultOptions),
|
227 | examples: ['{green $} auto pr-check --url http://your-ci.com/build/123']
|
228 | },
|
229 | {
|
230 | name: 'pr',
|
231 | summary: 'Set the status on a PR commit',
|
232 | require: ['state', 'url', 'description', 'context'],
|
233 | options: __spread([
|
234 | {
|
235 | name: 'sha',
|
236 | type: String,
|
237 | group: 'main',
|
238 | description: 'Specify a custom git sha. Defaults to the HEAD for a git repo in the current repository'
|
239 | },
|
240 | __assign({}, pr, { description: 'PR to set the status on. Detects PR number in CI' }),
|
241 | url,
|
242 | {
|
243 | name: 'state',
|
244 | type: String,
|
245 | group: 'main',
|
246 | description: "State of the PR. ['pending', 'success', 'error', 'failure']"
|
247 | },
|
248 | {
|
249 | name: 'description',
|
250 | type: String,
|
251 | group: 'main',
|
252 | description: 'A description of the status'
|
253 | },
|
254 | {
|
255 | name: 'context',
|
256 | type: String,
|
257 | group: 'main',
|
258 | description: 'A string label to differentiate this status from others'
|
259 | },
|
260 | dryRun
|
261 | ], defaultOptions),
|
262 | examples: [
|
263 | "{green $} auto pr \\\\ \n --state pending \\\\ \n --description \"Build still running...\" \\\\ \n --context build-check"
|
264 | ]
|
265 | },
|
266 | {
|
267 | name: 'version',
|
268 | summary: 'Get the semantic version bump for the given changes.',
|
269 | options: __spread([
|
270 | {
|
271 | name: 'only-publish-with-release-label',
|
272 | type: Boolean,
|
273 | description: "Only bump version if 'release' label is on pull request",
|
274 | group: 'main'
|
275 | },
|
276 | skipReleaseLabels
|
277 | ], defaultOptions),
|
278 | examples: [
|
279 | {
|
280 | desc: 'Get the new version using the last release to head',
|
281 | example: '{green $} auto version'
|
282 | },
|
283 | {
|
284 | desc: 'Skip releases with multiple labels',
|
285 | example: '{green $} auto version --skip-release-labels documentation CI'
|
286 | }
|
287 | ]
|
288 | },
|
289 | {
|
290 | name: 'changelog',
|
291 | summary: "Prepend release notes to 'CHANGELOG.md'",
|
292 | options: __spread([
|
293 | dryRun,
|
294 | noVersionPrefix,
|
295 | name,
|
296 | email,
|
297 | jira,
|
298 | {
|
299 | name: 'from',
|
300 | type: String,
|
301 | group: 'main',
|
302 | description: 'Tag to start changelog generation on. Defaults to latest tag.'
|
303 | },
|
304 | {
|
305 | name: 'to',
|
306 | type: String,
|
307 | group: 'main',
|
308 | description: 'Tag to end changelog generation on. Defaults to HEAD.'
|
309 | },
|
310 | __assign({}, message, { description: "Message to commit the changelog with. Defaults to 'Update CHANGELOG.md [skip ci]'" }),
|
311 | baseBranch
|
312 | ], defaultOptions),
|
313 | examples: [
|
314 | {
|
315 | desc: 'Generate a changelog from the last release to head',
|
316 | example: '{green $} auto changelog'
|
317 | },
|
318 | {
|
319 | desc: 'Generate a changelog across specific versions',
|
320 | example: '{green $} auto changelog --from v0.20.1 --to v0.21.0'
|
321 | }
|
322 | ]
|
323 | },
|
324 | {
|
325 | name: 'release',
|
326 | summary: 'Auto-generate a github release',
|
327 | options: __spread([
|
328 | dryRun,
|
329 | noVersionPrefix,
|
330 | name,
|
331 | email,
|
332 | jira,
|
333 | {
|
334 | name: 'use-version',
|
335 | type: String,
|
336 | group: 'main',
|
337 | description: 'Version number to publish as. Defaults to reading from the package definition for the platform.'
|
338 | },
|
339 | {
|
340 | name: 'slack',
|
341 | alias: 's',
|
342 | type: String,
|
343 | group: 'main',
|
344 | description: 'Url to post a slack message to about the release. Make sure the SLACK_TOKEN environment variable is set.'
|
345 | },
|
346 | baseBranch
|
347 | ], defaultOptions),
|
348 | examples: ['{green $} auto release']
|
349 | },
|
350 | {
|
351 | name: 'comment',
|
352 | summary: 'Comment on a pull request with a markdown message',
|
353 | require: ['message'],
|
354 | options: __spread([
|
355 | pr,
|
356 | context,
|
357 | __assign({}, message, { description: 'Message to post to comment' }),
|
358 | dryRun
|
359 | ], defaultOptions),
|
360 | examples: [
|
361 | '{green $} auto comment --pr 123 --comment "# Why you\'re wrong..."'
|
362 | ]
|
363 | },
|
364 | {
|
365 | name: 'pr-body',
|
366 | summary: 'Update the body of a PR with a message. Appends to PR and will not overwrite user content',
|
367 | require: ['message'],
|
368 | options: __spread([
|
369 | pr,
|
370 | context,
|
371 | __assign({}, message, { description: 'Message to post to PR body' }),
|
372 | dryRun
|
373 | ], defaultOptions),
|
374 | examples: [
|
375 | '{green $} auto pr-body --pr 123 --comment "The new version is: 1.2.3"'
|
376 | ]
|
377 | },
|
378 | {
|
379 | name: 'shipit',
|
380 | summary: dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n Run the full `auto` release pipeline. Detects if in a lerna project.\n\n 1. call from base branch -> latest version released\n 2. call from PR in CI -> canary version released\n 3. call locally when not on base branch -> canary version released\n "], ["\n Run the full \\`auto\\` release pipeline. Detects if in a lerna project.\n\n 1. call from base branch -> latest version released\n 2. call from PR in CI -> canary version released\n 3. call locally when not on base branch -> canary version released\n "]))),
|
381 | examples: ['{green $} auto shipit'],
|
382 | options: __spread(defaultOptions, [baseBranch, dryRun])
|
383 | },
|
384 | {
|
385 | name: 'canary',
|
386 | summary: dedent_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n Make a canary release of the project. Useful on PRs. If ran locally, `canary` will release a canary version for your current git HEAD.\n\n 1. In PR: 1.2.3-canary.123.0\n 2. Locally: 1.2.3-canary.1810cfd\n "], ["\n Make a canary release of the project. Useful on PRs. If ran locally, \\`canary\\` will release a canary version for your current git HEAD.\n\n 1. In PR: 1.2.3-canary.123.0\n 2. Locally: 1.2.3-canary.1810cfd\n "]))),
|
387 | examples: [
|
388 | '{green $} auto canary',
|
389 | '{green $} auto canary --pr 123 --build 5',
|
390 | '{green $} auto canary --message "Install PR version: `yarn add -D my-project@%v`"',
|
391 | '{green $} auto canary --message false'
|
392 | ],
|
393 | options: __spread(defaultOptions, [
|
394 | dryRun,
|
395 | __assign({}, pr, { description: 'PR number to use to create the canary version. Detected in CI env' }),
|
396 | {
|
397 | name: 'build',
|
398 | type: String,
|
399 | group: 'main',
|
400 | description: 'Build number to use to create the canary version. Detected in CI env'
|
401 | },
|
402 | __assign({}, message, { description: "Message to comment on PR with. Defaults to 'Published PR with canary version: %v'. Pass false to disable the comment" })
|
403 | ])
|
404 | }
|
405 | ];
|
406 | function filterCommands(allCommands, include) {
|
407 | return allCommands
|
408 | .filter(function (command) { return include.includes(command.name); })
|
409 | .map(function (command) { return ({
|
410 | name: command.name,
|
411 | summary: command.summary
|
412 | }); });
|
413 | }
|
414 | function printRootHelp() {
|
415 | var options = __spread([
|
416 | __assign({}, version, { group: 'misc' })
|
417 | ], mainDefinitions, defaultOptions);
|
418 | options.forEach(function (option) {
|
419 | styleTypes({}, option);
|
420 | });
|
421 | var usage = command_line_usage_1.default([
|
422 | {
|
423 | content: logo.replace(/\\/g, '\\\\'),
|
424 | raw: true
|
425 | },
|
426 | {
|
427 | content: 'Generate releases based on semantic version labels on pull requests'
|
428 | },
|
429 | {
|
430 | header: 'Synopsis',
|
431 | content: '$ auto <command> <options>'
|
432 | },
|
433 | {
|
434 | header: 'Setup Commands',
|
435 | content: filterCommands(commands, ['init', 'create-labels'])
|
436 | },
|
437 | {
|
438 | header: 'Release Commands',
|
439 | content: filterCommands(commands, [
|
440 | 'release',
|
441 | 'version',
|
442 | 'changelog',
|
443 | 'canary',
|
444 | 'shipit'
|
445 | ])
|
446 | },
|
447 | {
|
448 | header: 'Pull Request Interaction Commands',
|
449 | content: filterCommands(commands, [
|
450 | 'label',
|
451 | 'pr-check',
|
452 | 'pr',
|
453 | 'pr-body',
|
454 | 'comment'
|
455 | ])
|
456 | },
|
457 | {
|
458 | header: 'Global Options',
|
459 | optionList: options,
|
460 | group: 'misc'
|
461 | }
|
462 | ]);
|
463 | console.log(usage);
|
464 | }
|
465 | function printCommandHelp(command) {
|
466 | var sections = [
|
467 | {
|
468 | header: "auto " + command.name,
|
469 | content: command.summary
|
470 | }
|
471 | ];
|
472 | if (command.options) {
|
473 | var hasLocalOptions = command.options.filter(function (option) { return option.group === 'main'; });
|
474 | if (hasLocalOptions.length > 0) {
|
475 | sections.push({
|
476 | header: 'Options',
|
477 | optionList: command.options,
|
478 | group: 'main'
|
479 | });
|
480 | }
|
481 | var hasGlobalOptions = command.options.filter(function (option) { return option.group === 'misc'; });
|
482 | if (hasGlobalOptions.length > 0) {
|
483 | sections.push({
|
484 | header: 'Global Options',
|
485 | optionList: command.options,
|
486 | group: 'misc'
|
487 | });
|
488 | }
|
489 | }
|
490 | sections.push({
|
491 | header: 'Examples',
|
492 | content: command.examples,
|
493 | raw: command.name === 'pr'
|
494 | });
|
495 | console.log(command_line_usage_1.default(sections));
|
496 | }
|
497 | function printVersion() {
|
498 | var packagePath = path.join(__dirname, '../../package.json');
|
499 | var packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
500 | console.log("v" + packageJson.version);
|
501 | }
|
502 | function styleTypes(command, option) {
|
503 | var isRequired = command.require && command.require.includes(option.name);
|
504 | if (isRequired && option.type === Number) {
|
505 | option.typeLabel =
|
506 | '{rgb(173, 216, 230) {underline number}} [{rgb(254,91,92) required}]';
|
507 | }
|
508 | else if (option.type === Number) {
|
509 | option.typeLabel = '{rgb(173, 216, 230) {underline number}}';
|
510 | }
|
511 | if (isRequired && option.type === String) {
|
512 | option.typeLabel =
|
513 | '{rgb(173, 216, 230) {underline string}} [{rgb(254,91,92) required}]';
|
514 | }
|
515 | else if (option.multiple && option.type === String) {
|
516 | option.typeLabel = '{rgb(173, 216, 230) {underline string[]}}';
|
517 | }
|
518 | else if (option.type === String) {
|
519 | option.typeLabel = '{rgb(173, 216, 230) {underline string}}';
|
520 | }
|
521 | }
|
522 | function parseArgs(testArgs) {
|
523 | var mainOptions = command_line_args_1.default(mainDefinitions, {
|
524 | stopAtFirstUnknown: true,
|
525 | camelCase: true,
|
526 | argv: testArgs
|
527 | });
|
528 | var argv = mainOptions._unknown || [];
|
529 | var command = commands.find(function (c) { return c.name === mainOptions.command; });
|
530 | if (!command && mainOptions.version) {
|
531 | printVersion();
|
532 | return;
|
533 | }
|
534 | if (!command) {
|
535 | printRootHelp();
|
536 | return;
|
537 | }
|
538 | var options = command.options || [];
|
539 | options.forEach(function (option) {
|
540 | styleTypes(command, option);
|
541 | });
|
542 | if (mainOptions.help) {
|
543 | printCommandHelp(command);
|
544 | return;
|
545 | }
|
546 | var autoOptions = __assign({ command: mainOptions.command }, command_line_args_1.default(options, { argv: argv, camelCase: true })._all);
|
547 | if (command.require) {
|
548 | var missing = command.require
|
549 | .filter(function (option) {
|
550 | return !autoOptions.hasOwnProperty(option) ||
|
551 |
|
552 | autoOptions[option] === null;
|
553 | })
|
554 | .map(function (option) { return "--" + option; });
|
555 | var multiple = missing.length > 1;
|
556 | if (missing.length > 0) {
|
557 | printCommandHelp(command);
|
558 | signale_1.default.error("Missing required flag" + (multiple ? 's' : '') + ": " + missing.join(', '));
|
559 | return process.exit(1);
|
560 | }
|
561 | }
|
562 | return autoOptions;
|
563 | }
|
564 | exports.default = parseArgs;
|
565 | var templateObject_1, templateObject_2;
|
566 |
|
\ | No newline at end of file |