1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const cli_framework_1 = require("@ionic/cli-framework");
|
5 | const format_1 = require("@ionic/cli-framework/utils/format");
|
6 | const terminal_1 = require("@ionic/cli-framework/utils/terminal");
|
7 | const utils_fs_1 = require("@ionic/utils-fs");
|
8 | const chalk_1 = require("chalk");
|
9 | const Debug = require("debug");
|
10 | const path = require("path");
|
11 | const bootstrap_1 = require("./bootstrap");
|
12 | const constants_1 = require("./constants");
|
13 | const config_1 = require("./lib/config");
|
14 | const environment_1 = require("./lib/environment");
|
15 | const http_1 = require("./lib/http");
|
16 | const project_1 = require("./lib/project");
|
17 | const prompts_1 = require("./lib/prompts");
|
18 | const session_1 = require("./lib/session");
|
19 | const shell_1 = require("./lib/shell");
|
20 | const http_2 = require("./lib/utils/http");
|
21 | const logger_1 = require("./lib/utils/logger");
|
22 | tslib_1.__exportStar(require("./constants"), exports);
|
23 | tslib_1.__exportStar(require("./guards"), exports);
|
24 | const debug = Debug('ionic:cli-utils');
|
25 | function getProject(projectDir, projectName, deps) {
|
26 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
27 | if (!projectDir) {
|
28 | return;
|
29 | }
|
30 | const { log } = deps;
|
31 | const projectFilePath = path.resolve(projectDir, constants_1.PROJECT_FILE);
|
32 | let projectFile;
|
33 | let type;
|
34 | try {
|
35 | projectFile = yield utils_fs_1.readJsonFile(projectFilePath);
|
36 | }
|
37 | catch (e) {
|
38 | log.error(`Error while loading project config file.\n` +
|
39 | `Attempted to load project config ${chalk_1.default.bold(format_1.prettyPath(projectFilePath))} but got error:\n\n` +
|
40 | chalk_1.default.red(e.toString()));
|
41 | }
|
42 | if (projectFile) {
|
43 | projectName = projectName || projectFile.defaultProject;
|
44 | type = yield project_1.determineProjectType(projectDir, projectName, projectFile, deps);
|
45 | debug(`Project name: ${chalk_1.default.bold(String(projectName))}`);
|
46 | }
|
47 | if (!type) {
|
48 | return;
|
49 | }
|
50 | return project_1.createProjectFromType(projectFilePath, projectName, deps, type);
|
51 | });
|
52 | }
|
53 | exports.getProject = getProject;
|
54 | function generateIonicEnvironment(ctx, pargv, env) {
|
55 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
56 | process.chdir(ctx.execPath);
|
57 | const argv = config_1.parseGlobalOptions(pargv);
|
58 | const projectName = argv['project'] ? String(argv['project']) : undefined;
|
59 | const config = new config_1.Config(path.resolve(env['IONIC_CONFIG_DIRECTORY'] || config_1.DEFAULT_CONFIG_DIRECTORY, config_1.CONFIG_FILE));
|
60 | debug('Terminal info: %o', terminal_1.TERMINAL_INFO);
|
61 | if (config.get('interactive') === false || !terminal_1.TERMINAL_INFO.tty || terminal_1.TERMINAL_INFO.ci) {
|
62 | argv['interactive'] = false;
|
63 | }
|
64 | const flags = argv;
|
65 | debug('CLI global options: %o', flags);
|
66 | const log = new logger_1.Logger({
|
67 | level: argv['quiet'] ? cli_framework_1.LOGGER_LEVELS.WARN : cli_framework_1.LOGGER_LEVELS.INFO,
|
68 | handlers: logger_1.createDefaultLoggerHandlers(),
|
69 | });
|
70 | const prompt = yield cli_framework_1.createPromptModule({
|
71 | interactive: argv['interactive'],
|
72 | onFallback: prompts_1.createOnFallback({ flags, log }),
|
73 | });
|
74 | const projectDir = yield utils_fs_1.findBaseDirectory(ctx.execPath, constants_1.PROJECT_FILE);
|
75 | const proxyVars = http_2.PROXY_ENVIRONMENT_VARIABLES.map((e) => [e, env[e]]).filter(([, v]) => !!v);
|
76 | const getInfo = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
77 | const osName = yield Promise.resolve().then(() => require('os-name'));
|
78 | const os = osName();
|
79 | const npm = yield shell.cmdinfo('npm', ['-v']);
|
80 | const info = [
|
81 | {
|
82 | group: 'ionic',
|
83 | key: 'ionic',
|
84 | flair: 'Ionic CLI',
|
85 | value: ctx.version,
|
86 | path: ctx.libPath,
|
87 | },
|
88 | { group: 'system', key: 'NodeJS', value: process.version, path: process.execPath },
|
89 | { group: 'system', key: 'npm', value: npm || 'not installed' },
|
90 | { group: 'system', key: 'OS', value: os },
|
91 | ];
|
92 | info.push(...proxyVars.map(([e, v]) => ({ group: 'environment', key: e, value: v || 'not set' })));
|
93 | if (project) {
|
94 | info.push(...(yield project.getInfo()));
|
95 | }
|
96 | return info;
|
97 | });
|
98 | const shell = new shell_1.Shell({ log }, { alterPath: p => projectDir ? shell_1.prependNodeModulesBinToPath(projectDir, p) : p });
|
99 | const client = new http_1.Client(config);
|
100 | const session = new session_1.ProSession({ config, client });
|
101 | const deps = { client, config, ctx, flags, log, prompt, session, shell };
|
102 | const ienv = new environment_1.Environment(Object.assign({ getInfo }, deps));
|
103 | if (env['IONIC_CLI_LOCAL_ERROR']) {
|
104 | if (env['IONIC_CLI_LOCAL_ERROR'] === bootstrap_1.ERROR_VERSION_TOO_OLD) {
|
105 | log.warn(`Detected locally installed Ionic CLI, but it's too old--using global CLI.`);
|
106 | }
|
107 | }
|
108 | if (typeof argv['yarn'] === 'boolean') {
|
109 | log.warn(`${chalk_1.default.green('--yarn')} / ${chalk_1.default.green('--no-yarn')} has been removed. Use ${chalk_1.default.green(`ionic config set -g npmClient ${argv['yarn'] ? 'yarn' : 'npm'}`)}.`);
|
110 | }
|
111 | let project;
|
112 | try {
|
113 | project = yield getProject(projectDir, projectName, deps);
|
114 | }
|
115 | catch (e) {
|
116 | log.warn(e.toString());
|
117 | log.nl();
|
118 | }
|
119 | return { env: ienv, project };
|
120 | });
|
121 | }
|
122 | exports.generateIonicEnvironment = generateIonicEnvironment;
|