1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const node_1 = require("@ionic/cli-framework/utils/node");
|
4 | const chalk_1 = require("chalk");
|
5 | const Debug = require("debug");
|
6 | const path = require("path");
|
7 | const semver = require("semver");
|
8 | const color_1 = require("./lib/color");
|
9 | if (process.argv.includes('--no-color')) {
|
10 | chalk_1.default.enabled = false;
|
11 | }
|
12 | const debug = Debug('ionic: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 | async function detectLocalCLI() {
|
17 | let pkgPath;
|
18 | try {
|
19 | pkgPath = require.resolve('ionic/package', { paths: node_1.compileNodeModulesPaths(process.cwd()) });
|
20 | }
|
21 | catch (e) {
|
22 |
|
23 | }
|
24 | if (pkgPath && process.env.IONIC_CLI_LIB !== path.dirname(pkgPath)) {
|
25 | const pkg = await node_1.readPackageJsonFile(pkgPath);
|
26 | debug(`local CLI ${color_1.strong(pkg.version)} found at ${color_1.strong(pkgPath)}`);
|
27 | if (semver.lt(pkg.version, '4.0.0')) {
|
28 | throw exports.ERROR_VERSION_TOO_OLD;
|
29 | }
|
30 | return path.dirname(pkgPath);
|
31 | }
|
32 | throw exports.ERROR_LOCAL_CLI_NOT_FOUND;
|
33 | }
|
34 | exports.detectLocalCLI = detectLocalCLI;
|