-
Notifications
You must be signed in to change notification settings - Fork 2
/
hook.js
executable file
·224 lines (205 loc) · 6.01 KB
/
hook.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env node
var path = require("path");
var injector = require("./GIOInjector");
var packageObj = require("./package.json");
var userPackageObj = require("../../package.json");
// version for hook.js
var HOOK_VERSION = packageObj["version"];
var OPT_RUN = 0;
var OPT_DISCARD = 0;
var OPT_VERSION = 0;
var OPT_HELP = 0;
var OPT_UNKNOWN = 0;
// react-native path
var reactNativePath;
// react-navigation path
var reactNavigationPath;
var reactNavigationPath3X;
var reactNavigationPath6X;
// react-native-navigation path
var reactNativeNavigationPath;
switch (process.argv[2]) {
case "-v":
case "--version":
OPT_VERSION = 1;
break;
case "-run":
OPT_RUN = 1;
break;
case "-discard":
OPT_DISCARD = 1;
break;
case "-h":
case "--help":
OPT_HELP = 1;
break;
default:
OPT_UNKNOWN = 1;
}
if (OPT_UNKNOWN == 1) {
console.log("");
if (OPT_RUN == 1) {
console.log("You need to see the details of the -run command");
} else if (OPT_DISCARD == 1) {
console.log("You need to see the details of the -discard command");
} else {
console.log("Unknown options: " + process.argv[2]);
}
console.log("");
OPT_HELP = 1;
}
if (OPT_HELP == 1) {
console.log("");
console.log("usage: hook.js [[-v | --version] hook.js version]");
console.log(" hook.js [[-run] hook react native js]");
console.log(" hook.js [[-discard] discard hook]");
console.log(" hook.js [-h, --help: this help]");
return;
}
if (OPT_VERSION == 1) {
console.log("");
console.log("hook.js version " + HOOK_VERSION);
console.log("");
return;
}
var dir = path.resolve(__dirname, "..");
/**
* path config
*/
if (
userPackageObj &&
userPackageObj["GrowingIO"] &&
userPackageObj["GrowingIO"]["path"]
) {
var pathObj = userPackageObj["GrowingIO"]["path"];
// react-native path
var rnativePath = pathObj["react-native"];
if (rnativePath && rnativePath.length > 0) {
if (!rnativePath.endsWith("/")) {
rnativePath += "/";
}
reactNativePath = rnativePath;
} else {
reactNativePath = dir + "/react-native";
}
// react-navigation path
var rnavigationPath = pathObj["react-navigation"];
if (rnavigationPath && rnavigationPath.length > 0) {
if (!rnavigationPath.endsWith("/")) {
rnavigationPath += "/";
}
reactNavigationPath = rnavigationPath;
} else {
reactNavigationPath = dir + "/react-navigation";
}
// react-native-navigation path
var rnnPath = pathObj["react-native-navigation"];
if (rnnPath && rnnPath.length > 0) {
if (!rnnPath.endsWith("/")) {
rnnPath += "/";
}
reactNativeNavigationPath = rnnPath;
} else {
reactNativeNavigationPath = dir + "/react-native-navigation";
}
} else {
// react-native path
reactNativePath = dir + "/react-native";
// react-navigation path
reactNavigationPath = dir + "/react-navigation";
reactNavigationPath3X = dir + "/@react-navigation/native";
reactNavigationPath6X = dir + "/@react-navigation/core";
// react-native-navigation path
reactNativeNavigationPath = dir + "/react-native-navigation";
}
/**
* hook config
*/
if (OPT_RUN == 1) {
if (
userPackageObj &&
userPackageObj["GrowingIO"] &&
userPackageObj["GrowingIO"]["hook"]
) {
var hookObj = userPackageObj["GrowingIO"]["hook"];
var reactNavigationHook = hookObj["react-navigation"];
if (reactNavigationHook && reactNavigationHook == "ignore") {
} else {
injector.injectReactNavigation(reactNavigationPath);
}
var reactNativeNavigationHook = hookObj["react-native-navigation"];
if (reactNativeNavigationHook && reactNativeNavigationHook == "ignore") {
} else {
injector.injectReactNativeNavigation(reactNativeNavigationPath);
}
} else if (
userPackageObj &&
userPackageObj["GrowingIO"] &&
userPackageObj["GrowingIO"]["path"]
) {
var path = userPackageObj["GrowingIO"]["path"];
if (path["react-navigation-3x"]) {
injector.injectReactNavigation3(`${dir}/${path["react-navigation-3x"]}`);
}
if (path["react-navigation-4x"]) {
injector.injectReactNavigation4(`${dir}/${path["react-navigation-4x"]}`);
}
// 5x、6x 均使用官方建议page采集点
if (path["react-navigation-5x"]) {
injector.injectReactNavigation6(`${dir}/${path["react-navigation-5x"]}`);
}
if (path["react-navigation-6x"]) {
injector.injectReactNavigation6(`${dir}/${path["react-navigation-6x"]}`);
}
} else {
injector.injectReactNavigation(reactNavigationPath);
injector.injectReactNavigation3(reactNavigationPath3X);
injector.injectReactNavigation4(reactNavigationPath3X);
injector.injectReactNavigation6(reactNavigationPath6X);
injector.injectReactNativeNavigation(reactNativeNavigationPath);
}
injector.injectReactNative(reactNativePath);
return;
}
if (OPT_DISCARD == 1) {
injector.injectReactNative(reactNativePath, true);
if (
userPackageObj &&
userPackageObj["GrowingIO"] &&
userPackageObj["GrowingIO"]["path"]
) {
var path = userPackageObj["GrowingIO"]["path"];
if (path["react-navigation-3x"]) {
injector.injectReactNavigation3(
`${dir}/${path["react-navigation-3x"]}`,
true
);
}
if (path["react-navigation-4x"]) {
injector.injectReactNavigation4(
`${dir}/${path["react-navigation-4x"]}`,
true
);
}
// 5x、6x 均使用官方建议page采集点
if (path["react-navigation-5x"]) {
injector.injectReactNavigation6(
`${dir}/${path["react-navigation-5x"]}`,
true
);
}
if (path["react-navigation-6x"]) {
injector.injectReactNavigation6(
`${dir}/${path["react-navigation-6x"]}`,
true
);
}
} else {
injector.injectReactNavigation(reactNavigationPath, true);
injector.injectReactNavigation3(reactNavigationPath3X, true);
injector.injectReactNavigation4(reactNavigationPath3X, true);
injector.injectReactNavigation6(reactNavigationPath6X, true);
injector.injectReactNativeNavigation(reactNativeNavigationPath, true);
}
return;
}