forked from ionic-team/ionic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ts
More file actions
39 lines (29 loc) · 1.11 KB
/
bootstrap.ts
File metadata and controls
39 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { compileNodeModulesPaths, readPackageJsonFile, resolve } from '@ionic/cli-framework/utils/node';
import chalk from 'chalk';
import * as Debug from 'debug';
import * as path from 'path';
import * as semver from 'semver';
if (process.argv.includes('--no-color')) {
chalk.enabled = false;
}
const debug = Debug('ionic:bootstrap');
export const ERROR_BASE_DIRECTORY_NOT_FOUND = 'BASE_DIRECTORY_NOT_FOUND';
export const ERROR_LOCAL_CLI_NOT_FOUND = 'LOCAL_CLI_NOT_FOUND';
export const ERROR_VERSION_TOO_OLD = 'VERSION_TOO_OLD';
export async function detectLocalCLI(): Promise<string> {
let pkgPath: string | undefined;
try {
pkgPath = resolve('ionic/package', { paths: compileNodeModulesPaths(process.cwd()) });
} catch (e) {
// ignore
}
if (pkgPath && process.env.IONIC_CLI_LIB !== path.dirname(pkgPath)) {
const pkg = await readPackageJsonFile(pkgPath);
debug(`local CLI ${chalk.bold(pkg.version)} found at ${chalk.bold(pkgPath)}`);
if (semver.lt(pkg.version, '4.0.0')) {
throw ERROR_VERSION_TOO_OLD;
}
return path.dirname(pkgPath);
}
throw ERROR_LOCAL_CLI_NOT_FOUND;
}