1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.generateIonicEnvironment = void 0;
|
4 | const cli_framework_output_1 = require("@ionic/cli-framework-output");
|
5 | const cli_framework_prompts_1 = require("@ionic/cli-framework-prompts");
|
6 | const utils_terminal_1 = require("@ionic/utils-terminal");
|
7 | const Debug = require("debug");
|
8 | const path = require("path");
|
9 | const bootstrap_1 = require("../bootstrap");
|
10 | const color_1 = require("./color");
|
11 | const config_1 = require("./config");
|
12 | const environment_1 = require("./environment");
|
13 | const http_1 = require("./http");
|
14 | const project_1 = require("./project");
|
15 | const prompts_1 = require("./prompts");
|
16 | const session_1 = require("./session");
|
17 | const shell_1 = require("./shell");
|
18 | const http_2 = require("./utils/http");
|
19 | const logger_1 = require("./utils/logger");
|
20 | const debug = Debug('ionic:lib');
|
21 | async function generateIonicEnvironment(ctx, pargv) {
|
22 | process.chdir(ctx.execPath);
|
23 | const argv = config_1.parseGlobalOptions(pargv);
|
24 | const config = new config_1.Config(path.resolve(process.env['IONIC_CONFIG_DIRECTORY'] || config_1.DEFAULT_CONFIG_DIRECTORY, config_1.CONFIG_FILE));
|
25 | debug('Terminal info: %o', utils_terminal_1.TERMINAL_INFO);
|
26 | if (config.get('interactive') === false || !utils_terminal_1.TERMINAL_INFO.tty || utils_terminal_1.TERMINAL_INFO.ci) {
|
27 | argv['interactive'] = false;
|
28 | }
|
29 | const flags = argv;
|
30 | debug('CLI global options: %o', flags);
|
31 | const log = new logger_1.Logger({
|
32 | level: argv['quiet'] ? cli_framework_output_1.LOGGER_LEVELS.WARN : cli_framework_output_1.LOGGER_LEVELS.INFO,
|
33 | handlers: logger_1.createDefaultLoggerHandlers(),
|
34 | });
|
35 | const prompt = await cli_framework_prompts_1.createPromptModule({
|
36 | interactive: argv['interactive'],
|
37 | onFallback: prompts_1.createOnFallback({ flags, log }),
|
38 | });
|
39 | const projectDir = await project_1.findProjectDirectory(ctx.execPath);
|
40 | const proxyVars = http_2.PROXY_ENVIRONMENT_VARIABLES.map((e) => [e, process.env[e]]).filter(([, v]) => !!v);
|
41 | const getInfo = async () => {
|
42 | const osName = await Promise.resolve().then(() => require('os-name'));
|
43 | const semver = await Promise.resolve().then(() => require('semver'));
|
44 | const { getUpdateConfig } = await Promise.resolve().then(() => require('./updates'));
|
45 | const os = osName();
|
46 | const [npm, nativeRun, cordovaRes] = await Promise.all([
|
47 | shell.cmdinfo('npm', ['-v']),
|
48 | shell.cmdinfo('native-run', ['--version']),
|
49 | shell.cmdinfo('cordova-res', ['--version']),
|
50 | ]);
|
51 | const { packages: latestVersions } = await getUpdateConfig({ config });
|
52 | const latestNativeRun = latestVersions.find(pkg => pkg.name === 'native-run');
|
53 | const latestCordovaRes = latestVersions.find(pkg => pkg.name === 'cordova-res');
|
54 | const nativeRunUpdate = latestNativeRun && nativeRun ? semver.gt(latestNativeRun.version, nativeRun) : false;
|
55 | const cordovaResUpdate = latestCordovaRes && cordovaRes ? semver.gt(latestCordovaRes.version, cordovaRes) : false;
|
56 | const info = [
|
57 | {
|
58 | group: 'ionic',
|
59 | name: 'Ionic CLI',
|
60 | key: 'version',
|
61 | value: ctx.version,
|
62 | path: ctx.libPath,
|
63 | },
|
64 | { group: 'system', name: 'NodeJS', key: 'node_version', value: process.version, path: process.execPath },
|
65 | { group: 'system', name: 'npm', key: 'npm_version', value: npm || 'not installed' },
|
66 | { group: 'system', name: 'OS', key: 'os', value: os },
|
67 | {
|
68 | group: 'utility',
|
69 | name: 'native-run',
|
70 | key: 'native_run_version',
|
71 | value: nativeRun || 'not installed',
|
72 | flair: nativeRunUpdate ? `update available: ${latestNativeRun ? color_1.success(latestNativeRun.version) : '???'}` : '',
|
73 | },
|
74 | {
|
75 | group: 'utility',
|
76 | name: 'cordova-res',
|
77 | key: 'cordova_res_version',
|
78 | value: cordovaRes || 'not installed',
|
79 | flair: cordovaResUpdate ? `update available: ${latestCordovaRes ? color_1.success(latestCordovaRes.version) : '???'}` : '',
|
80 | },
|
81 | ];
|
82 | info.push(...proxyVars.map(([e, v]) => ({ group: 'environment', name: e, value: v || 'not set' })));
|
83 | if (project) {
|
84 | info.push(...(await project.getInfo()));
|
85 | }
|
86 | return info;
|
87 | };
|
88 | const shell = new shell_1.Shell({ log }, { alterPath: p => projectDir ? shell_1.prependNodeModulesBinToPath(projectDir, p) : p });
|
89 | const client = new http_1.Client(config);
|
90 | const session = new session_1.ProSession({ config, client });
|
91 | const deps = { client, config, ctx, flags, log, prompt, session, shell };
|
92 | const env = new environment_1.Environment({ getInfo, ...deps });
|
93 | if (process.env['IONIC_CLI_LOCAL_ERROR']) {
|
94 | if (process.env['IONIC_CLI_LOCAL_ERROR'] === bootstrap_1.ERROR_VERSION_TOO_OLD) {
|
95 | log.warn(`Detected locally installed Ionic CLI, but it's too old--using global CLI.`);
|
96 | }
|
97 | }
|
98 | if (typeof argv['yarn'] === 'boolean') {
|
99 | log.warn(`${color_1.input('--yarn')} / ${color_1.input('--no-yarn')} has been removed. Use ${color_1.input(`ionic config set -g npmClient ${argv['yarn'] ? 'yarn' : 'npm'}`)}.`);
|
100 | }
|
101 | const project = projectDir ? await project_1.createProjectFromDirectory(projectDir, argv, deps, { logErrors: !['start', 'init'].includes(argv._[0]) }) : undefined;
|
102 | if (project) {
|
103 | shell.alterPath = p => shell_1.prependNodeModulesBinToPath(project.directory, p);
|
104 | if (project.config.get('pro_id') && argv._[1] !== 'unset') {
|
105 | log.warn(`The ${color_1.input('pro_id')} field in ${color_1.strong(utils_terminal_1.prettyPath(project.filePath))} has been deprecated.\n` +
|
106 | `Ionic Pro has been renamed to Ionic Appflow! We've copied the value in ${color_1.input('pro_id')} to ${color_1.input('id')}, but you may want to unset the deprecated property: ${color_1.input('ionic config unset pro_id')}\n`);
|
107 | }
|
108 | }
|
109 | return { env, project };
|
110 | }
|
111 | exports.generateIonicEnvironment = generateIonicEnvironment;
|