index.js 6.3 KB

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