UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const node_1 = require("@ionic/cli-framework/utils/node");
4const chalk_1 = require("chalk");
5const Debug = require("debug");
6const path = require("path");
7const semver = require("semver");
8const color_1 = require("./lib/color");
9if (process.argv.includes('--no-color')) {
10 chalk_1.default.enabled = false;
11}
12const debug = Debug('ionic: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';
16async function detectLocalCLI() {
17 let pkgPath;
18 try {
19 pkgPath = require.resolve('ionic/package', { paths: node_1.compileNodeModulesPaths(process.cwd()) });
20 }
21 catch (e) {
22 // ignore
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}
34exports.detectLocalCLI = detectLocalCLI;