-
Notifications
You must be signed in to change notification settings - Fork 883
/
envinfo.ts
52 lines (44 loc) · 1.51 KB
/
envinfo.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
import envinfo from 'envinfo';
import {platform} from 'os';
import {EnvironmentInfo} from '../types';
/**
* Returns information about the running system.
* If `json === true`, or no options are passed,
* the return type will be an `EnvironmentInfo`.
* If set to `false`, it will be a `string`.
*/
async function getEnvironmentInfo(): Promise<EnvironmentInfo>;
async function getEnvironmentInfo(json: true): Promise<EnvironmentInfo>;
async function getEnvironmentInfo(json: false): Promise<string>;
async function getEnvironmentInfo(
json = true,
): Promise<string | EnvironmentInfo> {
const options = {json, showNotFound: true};
const packages = ['react', 'react-native', '@react-native-community/cli'];
const outOfTreePlatforms: {[key: string]: string} = {
darwin: 'react-native-macos',
win32: 'react-native-windows',
};
const outOfTreePlatformPackage = outOfTreePlatforms[platform()];
if (outOfTreePlatformPackage) {
packages.push(outOfTreePlatformPackage);
}
const info = (await envinfo.run(
{
System: ['OS', 'CPU', 'Memory', 'Shell'],
Binaries: ['Node', 'Yarn', 'npm', 'Watchman'],
IDEs: ['Xcode', 'Android Studio', 'Visual Studio'],
Managers: ['CocoaPods'],
Languages: ['Java', 'Ruby'],
SDKs: ['iOS SDK', 'Android SDK', 'Windows SDK'],
npmPackages: packages,
npmGlobalPackages: ['*react-native*'],
},
options,
)) as string;
if (options.json) {
return JSON.parse(info);
}
return info.trim();
}
export default getEnvironmentInfo;