1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | const cac_1 = require("cac");
|
5 | const _1 = require("./");
|
6 | const utils_1 = require("./utils");
|
7 |
|
8 | const PKG = require('../package.json');
|
9 | let pkgName;
|
10 | let pkgVersion;
|
11 | let pkgDescription = '';
|
12 | if (utils_1.isObject(PKG)) {
|
13 | if (typeof PKG.name === 'string')
|
14 | pkgName = PKG.name;
|
15 | if (typeof PKG.version === 'string')
|
16 | pkgVersion = PKG.version;
|
17 | if (typeof PKG.description === 'string')
|
18 | pkgDescription = PKG.description;
|
19 | }
|
20 | const cli = cac_1.cac(pkgName);
|
21 | if (pkgVersion) {
|
22 | cli.version(pkgVersion, '-V, -v, --version');
|
23 | }
|
24 | cli.help(pkgDescription
|
25 | ? (sections) => {
|
26 | sections.splice(1, 0, { body: pkgDescription });
|
27 | }
|
28 | : undefined);
|
29 | cli.option('--push', '`git push` the added tag to the remote repository');
|
30 | cli.option('--verbose', 'show details of executed git commands');
|
31 | cli.option('-n, --dry-run', 'perform a trial run with no changes made');
|
32 | if (cli.commands.length <= 0) {
|
33 | cli.usage('[options]');
|
34 | }
|
35 | (() => {
|
36 | const { options } = cli.parse();
|
37 | if (options.version || options.help) {
|
38 | return;
|
39 | }
|
40 | const unknownOptions = Object.keys(options).filter((name) => name !== '--' && !cli.globalCommand.hasOption(name));
|
41 | if (unknownOptions.length > 0) {
|
42 | process.exitCode = 1;
|
43 | console.error(`unknown ${unknownOptions.length > 1 ? 'options' : 'option'}: ` +
|
44 | `${unknownOptions
|
45 | .map((name) => /^[^-]$/.test(name) ? `-${name}` : `--${name}`)
|
46 | .join(' ')}\n` +
|
47 | `Try \`${cli.name} --help\` for valid options.`);
|
48 | return;
|
49 | }
|
50 | _1.default({
|
51 | push: options.push,
|
52 | verbose: options.verbose,
|
53 | dryRun: options.dryRun,
|
54 | }).catch((error) => {
|
55 | process.exitCode = 1;
|
56 | console.error(error instanceof Error ? error.message : error);
|
57 | });
|
58 | })();
|
59 |
|
\ | No newline at end of file |