UNPKG

1.18 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const node_1 = require("@ionic/cli-framework/utils/node");
4const Debug = require("debug");
5const path = require("path");
6const semver = require("semver");
7const color_1 = require("./lib/color");
8const debug = Debug('ionic:bootstrap');
9exports.ERROR_BASE_DIRECTORY_NOT_FOUND = 'BASE_DIRECTORY_NOT_FOUND';
10exports.ERROR_LOCAL_CLI_NOT_FOUND = 'LOCAL_CLI_NOT_FOUND';
11exports.ERROR_VERSION_TOO_OLD = 'VERSION_TOO_OLD';
12async function detectLocalCLI() {
13 let pkgPath;
14 try {
15 pkgPath = require.resolve('ionic/package', { paths: node_1.compileNodeModulesPaths(process.cwd()) });
16 }
17 catch (e) {
18 // ignore
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}
30exports.detectLocalCLI = detectLocalCLI;