UNPKG

1.44 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const path = require("path");
5const chalk_1 = require("chalk");
6const Debug = require("debug");
7const semver = require("semver");
8const node_1 = require("@ionic/cli-framework/utils/node");
9if (process.argv.includes('--no-color')) {
10 chalk_1.default.enabled = false;
11}
12const debug = Debug('ionic:cli-utils:bootstrap');
13exports.ERROR_BASE_DIRECTORY_NOT_FOUND = 'BASE_DIRECTORY_NOT_FOUND';
14exports.ERROR_LOCAL_CLI_NOT_FOUND = 'LOCAL_CLI_NOT_FOUND';
15exports.ERROR_VERSION_TOO_OLD = 'VERSION_TOO_OLD';
16function 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 // ignore
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}
36exports.detectLocalCLI = detectLocalCLI;