UNPKG

2 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4const cac_1 = require("cac");
5const _1 = require("./");
6const utils_1 = require("./utils");
7// eslint-disable-next-line @typescript-eslint/no-var-requires
8const PKG = require('../package.json');
9let pkgName;
10let pkgVersion;
11let pkgDescription = '';
12if (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}
20const cli = cac_1.cac(pkgName);
21if (pkgVersion) {
22 cli.version(pkgVersion, '-V, -v, --version');
23}
24cli.help(pkgDescription
25 ? (sections) => {
26 sections.splice(1, 0, { body: pkgDescription });
27 }
28 : undefined);
29cli.option('--push', '`git push` the added tag to the remote repository');
30cli.option('--verbose', 'show details of executed git commands');
31cli.option('-n, --dry-run', 'perform a trial run with no changes made');
32if (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//# sourceMappingURL=bin.js.map
\No newline at end of file