UNPKG

2.31 kBJavaScriptView Raw
1#!/usr/bin/env node
2Object.defineProperty(exports, "__esModule", { value: true });
3const once = require("once");
4const yargs = require("yargs");
5const logger_1 = require("./logger");
6const env_1 = require("./utils/env");
7const helpers_1 = require("./utils/helpers");
8const noInput_1 = require("./utils/noInput");
9const sentry_1 = require("./utils/sentry");
10const version_1 = require("./utils/version");
11/**
12 * Handler for '--dry-run' option
13 */
14function processDryRun(arg) {
15 // if the user explicitly set the flag on the command line, their choice
16 // should override any previously set env var
17 if (process.argv.indexOf('--dry-run') > -1) {
18 process.env.DRY_RUN = String(arg);
19 }
20 if (helpers_1.isDryRun()) {
21 logger_1.logger.info('[dry-run] Dry-run mode is on!');
22 }
23 return arg;
24}
25/**
26 * Handler for '--no-input' option
27 */
28function processNoInput(arg) {
29 if (arg) {
30 noInput_1.setNoInput(true);
31 }
32 if (noInput_1.hasNoInput()) {
33 logger_1.logger.info('[no-input] The script will not accept any input!');
34 }
35 return arg;
36}
37/**
38 * Prints the current version
39 */
40function printVersion() {
41 if (process.argv.indexOf('-v') === -1 &&
42 process.argv.indexOf('--version') === -1) {
43 // Print the current version
44 logger_1.logger.info(`craft ${version_1.getPackageVersion()}`);
45 }
46}
47/**
48 * Main entrypoint
49 */
50function main() {
51 version_1.checkForUpdates();
52 printVersion();
53 env_1.readEnvironmentConfig();
54 logger_1.init();
55 sentry_1.initSentrySdk();
56 yargs
57 .parserConfiguration({
58 'boolean-negation': false,
59 })
60 .commandDir('commands')
61 .demandCommand()
62 .version()
63 .alias('v', 'version')
64 .help()
65 .alias('h', 'help')
66 .option('no-input', {
67 boolean: true,
68 coerce: once(processNoInput),
69 default: false,
70 describe: 'Suppresses all user prompts',
71 })
72 .global('no-input')
73 .option('dry-run', {
74 boolean: true,
75 coerce: once(processDryRun),
76 default: false,
77 describe: 'Dry run mode: do not perform any real actions',
78 })
79 .global('dry-run')
80 .strict()
81 .showHelpOnFail(true)
82 .parse();
83}
84main();
85//# sourceMappingURL=index.js.map
\No newline at end of file