forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
103 lines (95 loc) · 2.56 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import nodeJS from './nodeJS';
import {yarn, npm} from './packageManagers';
import adb from './adb';
import jdk from './jdk';
import watchman from './watchman';
import ruby from './ruby';
import androidHomeEnvVariable from './androidHomeEnvVariable';
import androidStudio from './androidStudio';
import androidSDK from './androidSDK';
import androidNDK from './androidNDK';
import xcode from './xcode';
import cocoaPods from './cocoaPods';
import {Healthchecks, HealthCheckCategory} from '../../types';
import {loadConfigAsync} from '@react-native-community/cli-config';
import xcodeEnv from './xcodeEnv';
import packager from './packager';
import gradle from './gradle';
import deepmerge from 'deepmerge';
import {logger} from '@react-native-community/cli-tools';
export const HEALTHCHECK_TYPES = {
ERROR: 'ERROR',
WARNING: 'WARNING',
};
type Options = {
fix: boolean | void;
contributor: boolean | void;
};
export const getHealthchecks = async ({
contributor,
}: Options): Promise<Healthchecks> => {
let additionalChecks: HealthCheckCategory[] = [];
let projectSpecificHealthchecks = {};
let config;
// Doctor can run in a detached mode, where there isn't a config so this can fail
try {
config = await loadConfigAsync({});
additionalChecks = config.healthChecks;
if (config.reactNativePath) {
projectSpecificHealthchecks = {
common: {
label: 'Common',
healthchecks: [packager],
},
android: {
label: 'Android',
healthchecks: [androidSDK],
},
...(process.platform === 'darwin' && {
ios: {
label: 'iOS',
healthchecks: [xcodeEnv],
},
}),
};
}
} catch {}
if (!config) {
logger.log();
logger.info(
'Detected that command has been run outside of React Native project, running basic healthchecks.',
);
}
const defaultHealthchecks = {
common: {
label: 'Common',
healthchecks: [
nodeJS,
yarn,
npm,
...(process.platform === 'darwin' ? [watchman] : []),
],
},
android: {
label: 'Android',
healthchecks: [
adb,
jdk,
androidStudio,
androidHomeEnvVariable,
gradle,
...(contributor ? [androidNDK] : []),
],
},
...(process.platform === 'darwin'
? {
ios: {
label: 'iOS',
healthchecks: [xcode, ruby, cocoaPods],
},
}
: {}),
...additionalChecks,
};
return deepmerge(defaultHealthchecks, projectSpecificHealthchecks);
};