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