1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const node_1 = require("@ionic/cli-framework/utils/node");
|
4 | const Debug = require("debug");
|
5 | const path = require("path");
|
6 | const semver = require("semver");
|
7 | const color_1 = require("./lib/color");
|
8 | const debug = Debug('ionic:bootstrap');
|
9 | exports.ERROR_BASE_DIRECTORY_NOT_FOUND = 'BASE_DIRECTORY_NOT_FOUND';
|
10 | exports.ERROR_LOCAL_CLI_NOT_FOUND = 'LOCAL_CLI_NOT_FOUND';
|
11 | exports.ERROR_VERSION_TOO_OLD = 'VERSION_TOO_OLD';
|
12 | async function detectLocalCLI() {
|
13 | let pkgPath;
|
14 | try {
|
15 | pkgPath = require.resolve('ionic/package', { paths: node_1.compileNodeModulesPaths(process.cwd()) });
|
16 | }
|
17 | catch (e) {
|
18 |
|
19 | }
|
20 | if (pkgPath && process.env.IONIC_CLI_LIB !== path.dirname(pkgPath)) {
|
21 | const pkg = await node_1.readPackageJsonFile(pkgPath);
|
22 | debug(`local CLI ${color_1.strong(pkg.version)} found at ${color_1.strong(pkgPath)}`);
|
23 | if (semver.lt(pkg.version, '4.0.0')) {
|
24 | throw exports.ERROR_VERSION_TOO_OLD;
|
25 | }
|
26 | return path.dirname(pkgPath);
|
27 | }
|
28 | throw exports.ERROR_LOCAL_CLI_NOT_FOUND;
|
29 | }
|
30 | exports.detectLocalCLI = detectLocalCLI;
|