UNPKG

4.65 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) 2018, salesforce.com, inc.
4 * All rights reserved.
5 * Licensed under the BSD 3-Clause license.
6 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9const command_1 = require("@oclif/command");
10const config_1 = require("@oclif/config");
11const kit_1 = require("@salesforce/kit");
12const Debug = require("debug");
13const os = require("os");
14const path = require("path");
15const lazyRequire = require("./lazyRequire");
16const env_1 = require("./util/env");
17const debug = Debug('sfdx');
18function create(version, channel, run = command_1.run, env = env_1.default) {
19 const root = path.resolve(__dirname, '..');
20 const pjson = require(path.resolve(__dirname, '..', 'package.json'));
21 const args = process.argv.slice(2);
22 return {
23 async run() {
24 const config = new config_1.Config({ name: pjson.oclif.bin, root, version, channel });
25 await config.load();
26 configureUpdateSites(config, env);
27 configureAutoUpdate(env);
28 debugCliInfo(version, channel, env, config);
29 if (args[1] !== 'update' && env.isLazyRequireEnabled()) {
30 lazyRequire.start(config);
31 }
32 return await run(args, config);
33 }
34 };
35}
36exports.create = create;
37exports.UPDATE_DISABLED_INSTALLER = 'Manual and automatic CLI updates have been disabled by setting "SFDX_AUTOUPDATE_DISABLE=true". ' +
38 'To check for a new version, unset that environment variable.';
39exports.UPDATE_DISABLED_NPM = 'Use "npm update --global sfdx-cli" to update npm-based installations.';
40exports.UPDATE_DISABLED_DEMO = 'Manual and automatic CLI updates have been disabled in DEMO mode. ' +
41 'To check for a new version, unset the environment variable SFDX_ENV.';
42function configureUpdateSites(config, env = env_1.default) {
43 const s3Host = env.getS3HostOverride();
44 if (s3Host) {
45 // Override config value if set via envar
46 kit_1.set(config, 'pjson.oclif.update.s3.host', s3Host);
47 }
48 const npmRegistry = env.getNpmRegistryOverride();
49 if (npmRegistry) {
50 // Override config value if set via envar
51 kit_1.set(config, 'pjson.oclif.warn-if-update-available.registry', npmRegistry);
52 }
53}
54exports.configureUpdateSites = configureUpdateSites;
55function configureAutoUpdate(envars) {
56 if (envars.isDemoMode()) {
57 // Disable autoupdates in demo mode
58 envars.setAutoupdateDisabled(true);
59 envars.setUpdateInstructions(exports.UPDATE_DISABLED_DEMO);
60 return;
61 }
62 if (envars.isInstaller()) {
63 envars.normalizeAutoupdateDisabled();
64 if (envars.isAutoupdateDisabled()) {
65 envars.setUpdateInstructions(exports.UPDATE_DISABLED_INSTALLER);
66 }
67 return;
68 }
69 // Not an installer, so this must be running from an npm installation
70 if (!envars.isAutoupdateDisabledSet()) {
71 // Disable autoupdates if run from an npm install or in local dev, if not explicitly set
72 envars.setAutoupdateDisabled(true);
73 }
74 if (envars.isAutoupdateDisabled()) {
75 envars.setUpdateInstructions(exports.UPDATE_DISABLED_NPM);
76 }
77}
78exports.configureAutoUpdate = configureAutoUpdate;
79function debugCliInfo(version, channel, env, config) {
80 function debugSection(section, items) {
81 const pad = 25;
82 debug('%s:', section.padStart(pad));
83 items.forEach(([name, value]) => debug('%s: %s', name.padStart(pad), value));
84 }
85 debugSection('OS', [
86 ['platform', os.platform()],
87 ['architecture', os.arch()],
88 ['release', os.release()],
89 ['shell', config.shell]
90 ]);
91 debugSection('NODE', [
92 ['version', process.versions.node]
93 ]);
94 debugSection('CLI', [
95 ['version', version],
96 ['channel', channel],
97 ['bin', config.bin],
98 ['data', config.dataDir],
99 ['cache', config.cacheDir],
100 ['config', config.configDir]
101 ]);
102 debugSection('ENV', [
103 'NODE_OPTIONS',
104 env_1.Env.DISABLE_AUTOUPDATE_LEGACY,
105 'SFDX_BINPATH',
106 'SFDX_COMPILE_CACHE',
107 env_1.Env.DISABLE_AUTOUPDATE_OCLIF,
108 env_1.Env.CLI_MODE,
109 env_1.Env.CLI_INSTALLER,
110 env_1.Env.LAZY_LOAD_MODULES,
111 env_1.Env.NPM_REGISTRY,
112 'SFDX_REDIRECTED',
113 env_1.Env.S3_HOST,
114 env_1.Env.UPDATE_INSTRUCTIONS
115 ].map((key) => [key, env.getString(key, '<not set>')]));
116 debugSection('ARGS', process.argv.map((arg, i) => [i.toString(), arg]));
117}
118//# sourceMappingURL=cli.js.map
\No newline at end of file