1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const path = require("path");
|
5 | const chalk_1 = require("chalk");
|
6 | const Debug = require("debug");
|
7 | const semver = require("semver");
|
8 | const node_1 = require("@ionic/cli-framework/utils/node");
|
9 | if (process.argv.includes('--no-color')) {
|
10 | chalk_1.default.enabled = false;
|
11 | }
|
12 | const debug = Debug('ionic:cli-utils:bootstrap');
|
13 | exports.ERROR_BASE_DIRECTORY_NOT_FOUND = 'BASE_DIRECTORY_NOT_FOUND';
|
14 | exports.ERROR_LOCAL_CLI_NOT_FOUND = 'LOCAL_CLI_NOT_FOUND';
|
15 | exports.ERROR_VERSION_TOO_OLD = 'VERSION_TOO_OLD';
|
16 | function detectLocalCLI() {
|
17 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
18 | let pkgPath;
|
19 | try {
|
20 | pkgPath = node_1.resolve('ionic/package', { paths: node_1.compileNodeModulesPaths(process.cwd()) });
|
21 | }
|
22 | catch (e) {
|
23 |
|
24 | }
|
25 | if (pkgPath && process.env.IONIC_CLI_LIB !== path.dirname(pkgPath)) {
|
26 | const pkg = yield node_1.readPackageJsonFile(pkgPath);
|
27 | debug(`local CLI ${chalk_1.default.bold(pkg.version)} found at ${chalk_1.default.bold(pkgPath)}`);
|
28 | if (semver.lt(pkg.version, '4.0.0')) {
|
29 | throw exports.ERROR_VERSION_TOO_OLD;
|
30 | }
|
31 | return path.dirname(pkgPath);
|
32 | }
|
33 | throw exports.ERROR_LOCAL_CLI_NOT_FOUND;
|
34 | });
|
35 | }
|
36 | exports.detectLocalCLI = detectLocalCLI;
|