UNPKG

2.97 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3// The following block should be compatible to as many Node.js versions as possible
4/* eslint-disable no-var */
5var pkg = require("../package.json");
6var semver;
7try {
8 semver = require("semver");
9} catch (err) {
10 // SyntaxError indicates an outdated Node.js version
11 if (err.name !== "SyntaxError") {
12 throw err;
13 }
14}
15var nodeVersion = process.version;
16/* eslint-enable no-var */
17if (pkg.engines && pkg.engines.node && (!semver || !semver.satisfies(nodeVersion, pkg.engines.node))) {
18 console.log("==================== UNSUPPORTED NODE.JS VERSION ====================");
19 console.log("You are using an unsupported version of Node.js");
20 console.log("Detected version " + nodeVersion + " but " + pkg.name + " requires " + pkg.engines.node);
21 console.log("");
22 console.log("=> Please upgrade to a supported version of Node.js to use this tool");
23 console.log("=====================================================================");
24 process.exit(1);
25} else {
26 // Timeout is required to log info when importing from local installation
27 setTimeout(() => {
28 if (!process.env.UI5_CLI_NO_LOCAL) {
29 const importLocal = require("import-local");
30 // Prefer a local installation of @ui5/cli.
31 // This will invoke the local CLI, so no further action required
32 if (importLocal(__filename)) {
33 if (process.argv.includes("--verbose")) {
34 console.info(`INFO: This project contains an individual ${pkg.name} installation which ` +
35 "will be used over the global one.");
36 console.info("See https://github.com/SAP/ui5-cli#local-vs-global-installation for details.");
37 console.info("");
38 } else {
39 console.info(`INFO: Using local ${pkg.name} installation`);
40 console.info("");
41 }
42 return;
43 }
44 }
45
46 const updateNotifier = require("update-notifier");
47 updateNotifier({
48 pkg,
49 updateCheckInterval: 1000 * 60 * 60 * 24, // 1 day
50 shouldNotifyInNpmScript: true
51 }).notify();
52 // Remove --no-update-notifier from argv as it's not known to yargs, but we still want to support using it
53 const NO_UPDATE_NOTIFIER = "--no-update-notifier";
54 if (process.argv.includes(NO_UPDATE_NOTIFIER)) {
55 process.argv = process.argv.filter((v) => v !== NO_UPDATE_NOTIFIER);
56 }
57
58 const cli = require("yargs");
59
60 cli.parserConfiguration({
61 "parse-numbers": false
62 });
63
64 // Explicitly set CLI version as the yargs default might
65 // be wrong in case a local CLI installation is used
66 // Also add CLI location
67 const version = `${pkg.version} (from ${__filename})`;
68 require("../lib/cli/version").set(version);
69 cli.version(version);
70
71 // Explicitly set script name to prevent windows from displaying "ui5.js"
72 cli.scriptName("ui5");
73
74 // CLI modules
75 cli.commandDir("../lib/cli/commands");
76
77 // Format terminal output to full available width
78 cli.wrap(cli.terminalWidth());
79
80 // yargs registers a get method on the argv property.
81 // The property needs to be accessed to initialize everything.
82 cli.argv;
83 }, 0);
84}