1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | const command_1 = require("@oclif/command");
|
10 | const config_1 = require("@oclif/config");
|
11 | const kit_1 = require("@salesforce/kit");
|
12 | const Debug = require("debug");
|
13 | const os = require("os");
|
14 | const path = require("path");
|
15 | const lazyRequire = require("./lazyRequire");
|
16 | const env_1 = require("./util/env");
|
17 | const debug = Debug('sfdx');
|
18 | function 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 | }
|
36 | exports.create = create;
|
37 | exports.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.';
|
39 | exports.UPDATE_DISABLED_NPM = 'Use "npm update --global sfdx-cli" to update npm-based installations.';
|
40 | exports.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.';
|
42 | function configureUpdateSites(config, env = env_1.default) {
|
43 | const s3Host = env.getS3HostOverride();
|
44 | if (s3Host) {
|
45 |
|
46 | kit_1.set(config, 'pjson.oclif.update.s3.host', s3Host);
|
47 | }
|
48 | const npmRegistry = env.getNpmRegistryOverride();
|
49 | if (npmRegistry) {
|
50 |
|
51 | kit_1.set(config, 'pjson.oclif.warn-if-update-available.registry', npmRegistry);
|
52 | }
|
53 | }
|
54 | exports.configureUpdateSites = configureUpdateSites;
|
55 | function configureAutoUpdate(envars) {
|
56 | if (envars.isDemoMode()) {
|
57 |
|
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 |
|
70 | if (!envars.isAutoupdateDisabledSet()) {
|
71 |
|
72 | envars.setAutoupdateDisabled(true);
|
73 | }
|
74 | if (envars.isAutoupdateDisabled()) {
|
75 | envars.setUpdateInstructions(exports.UPDATE_DISABLED_NPM);
|
76 | }
|
77 | }
|
78 | exports.configureAutoUpdate = configureAutoUpdate;
|
79 | function 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 |
|
\ | No newline at end of file |