-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathsetup.mjs
379 lines (352 loc) · 9.54 KB
/
setup.mjs
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/* eslint-disable import/no-nodejs-modules */
import fs from 'fs';
import { $ } from 'execa';
import { Listr } from 'listr2';
import path from 'path';
const IS_CI = process.env.CI;
const IS_OSX = process.platform === 'darwin';
// iOS builds are enabled by default on macOS only but can be enabled or disabled explicitly
let BUILD_IOS = IS_OSX;
let IS_NODE = false;
let BUILD_ANDROID = true
let INSTALL_PODS;
const args = process.argv.slice(2) || [];
for (const arg of args) {
switch (arg) {
case '--build-ios':
BUILD_IOS = true;
continue;
case '--no-build-ios':
BUILD_IOS = false;
continue;
case '--install-pods':
INSTALL_PODS = true;
continue;
case '--no-install-pods':
INSTALL_PODS = false;
continue;
case '--node':
IS_NODE = true;
continue;
case '--no-build-android':
BUILD_ANDROID = false
continue;
default:
throw new Error(`Unrecognized CLI arg ${arg}`);
}
}
if (INSTALL_PODS === undefined) {
INSTALL_PODS = BUILD_IOS;
}
if (INSTALL_PODS && !BUILD_IOS) {
throw new Error('Cannot install pods if iOS setup has been skipped');
}
const rendererOptions = {
collapseErrors: false,
showSkipMessage: false,
suffixSkips: true,
collapseSubtasks: false,
};
/*
* TODO: parse example env file and add missing variables to existing .js.env
*/
const copyAndSourceEnvVarsTask = {
title: 'Copy and source environment variables',
task: (_, task) => {
if (IS_CI) {
return task.skip('Skipping copying and sourcing environment variables.');
}
return task.newListr(
[
{
title: 'Copy env vars',
task: async () => {
const envFiles = [
'.js.env',
'.ios.env',
'.android.env',
'.e2e.env',
];
envFiles.forEach((envFileName) => {
try {
fs.copyFileSync(
`${envFileName}.example`,
envFileName,
fs.constants.COPYFILE_EXCL,
);
} catch (err) {
// Ignore if file already exists
return;
}
});
},
},
{
title: 'Source env vars',
task: async () => {
const envFiles = [
'.js.env',
'.ios.env',
'.android.env',
'.e2e.env',
];
envFiles.forEach((envFileName) => {
`source ${envFileName}`;
});
},
},
],
{
concurrent: false,
exitOnError: true,
rendererOptions,
},
);
},
};
const buildPpomTask = {
title: 'Build PPOM',
task: (_, task) => {
if (IS_NODE) {
return task.skip('Skipping building PPOM.');
}
const $ppom = $({ cwd: 'ppom' });
return task.newListr(
[
{
title: 'Clean',
task: async () => {
await $ppom`yarn clean`;
},
},
{
title: 'Install deps',
task: async () => {
await $ppom`yarn`;
},
},
{
title: 'Lint',
task: async () => {
await $ppom`yarn lint`;
},
},
{
title: 'Build',
task: async () => {
await $ppom`yarn build`;
},
},
],
{
concurrent: false,
exitOnError: true,
rendererOptions,
},
);
},
};
const setupIosTask = {
title: 'Set up iOS',
task: async (_, task) => {
if (!BUILD_IOS) {
return task.skip('Skipping iOS set up.');
}
const tasks = [
{
title: 'Install bundler gem',
task: async () => {
await $`gem install bundler -v 2.5.8`;
},
},
{
title: 'Install gems',
task: async () => {
await $`yarn gem:bundle:install`;
},
},
{
title: 'Create xcconfig files',
task: async () => {
fs.writeFileSync('ios/debug.xcconfig', '');
fs.writeFileSync('ios/release.xcconfig', '');
},
},
];
if (INSTALL_PODS) {
tasks.push({
title: 'Install CocoaPods',
task: async () => {
await $`yarn pod:install`;
},
});
}
return task.newListr(
tasks,
{
concurrent: false,
exitOnError: true,
},
);
},
};
const buildInpageBridgeTask = {
title: 'Build inpage bridge',
task: async (_, task) => {
if (IS_NODE) {
return task.skip('Skipping building inpage bridge.');
}
await $`./scripts/build-inpage-bridge.sh`;
},
};
const nodeifyTask = {
// TODO: find a saner alternative to bring node modules into react native bundler. See ReactNativify
title: 'Nodeify npm packages',
task: async (_, task) => {
if (IS_NODE) {
return task.skip('Skipping nodeifying npm packages.');
}
await $`node_modules/.bin/rn-nodeify --install crypto,buffer,react-native-randombytes,vm,stream,http,https,os,url,net,fs --hack`;
},
};
const jetifyTask = {
title: 'Jetify npm packages for Android',
task: async (_, task) => {
if (!BUILD_ANDROID) {
return task.skip('Skipping jetifying npm packages.');
}
if (IS_NODE) {
return task.skip('Skipping jetifying npm packages.');
}
await $`yarn jetify`;
},
};
const patchPackageTask = {
title: 'Patch npm packages',
task: async () => {
await $`yarn patch-package --error-on-fail`;
},
};
const expoBuildLinks = {
title: 'Try EXPO!',
task: async () => {
function hyperlink(label, url) {
return `\x1b]8;;${url}\x1b\\${label}\x1b]8;;\x1b\\`;
}
console.log(`
Setup complete! Consider getting started with EXPO on MetaMask. Here are the 3 easy steps to get up and running.
Step 1: Install EXPO Executable
📱 ${hyperlink('iOS .ipa (physical devices) Note: it requires Apple Registration with MetaMask', 'https://app.runway.team/bucket/MV2BJmn6D5_O7nqGw8jHpATpEA4jkPrBB4EcWXC6wV7z8jgwIbAsDhE5Ncl7KwF32qRQQD9YrahAIaxdFVvLT4v3UvBcViMtT3zJdMMfkXDPjSdqVGw=')}
🤖 ${hyperlink('iOS .app (iOS simulator unzip the file and drag in simulator)', 'https://app.runway.team/bucket/aCddXOkg1p_nDryri-FMyvkC9KRqQeVT_12sf6Nw0u6iGygGo6BlNzjD6bOt-zma260EzAxdpXmlp2GQphp3TN1s6AJE4i6d_9V0Tv5h4pHISU49dFk=')}
🤖 ${hyperlink('Android .apk (physical devices & emulators)', 'https://app.runway.team/bucket/hykQxdZCEGgoyyZ9sBtkhli8wupv9PiTA6uRJf3Lh65FTECF1oy8vzkeXdmuJKhm7xGLeV35GzIT1Un7J5XkBADm5OhknlBXzA0CzqB767V36gi1F3yg3Uss')}
Step 2: 👀 yarn watch or yarn watch:clean
Step 3: 🚀 launch app on emulator or scan QR code in terminal
`);
},
};
const updateGitSubmodulesTask = {
title: 'Init git submodules',
task: async (_, task) => {
if (IS_NODE) {
return task.skip('Skipping init git submodules.');
}
await $`git submodule update --init`;
},
};
const runLavamoatAllowScriptsTask = {
title: 'Run lavamoat allow-scripts',
task: async () => {
await $`yarn allow-scripts`;
},
};
const generateTermsOfUseTask = {
title: 'Generate Terms of Use',
task: (_, task) =>
task.newListr(
[
{
title: 'Download Terms of Use',
task: async () => {
try {
await $`curl -o ./docs/assets/termsOfUse.html https://legal.consensys.io/plain/terms-of-use/`;
} catch (error) {
throw new Error('Failed to download Terms of Use');
}
},
},
{
title: 'Write Terms of Use file',
task: async () => {
const termsOfUsePath = path.resolve(
'./docs/assets/termsOfUse.html',
);
const outputDir = path.resolve('./app/util/termsOfUse');
const outputPath = path.join(outputDir, 'termsOfUseContent.ts');
let termsOfUse = '';
try {
termsOfUse = fs.readFileSync(termsOfUsePath, 'utf8');
} catch (error) {
throw new Error('Failed to read Terms of Use file');
}
const outputContent = `export default ${JSON.stringify(
termsOfUse,
)};`;
try {
fs.mkdirSync(outputDir, { recursive: true });
fs.writeFileSync(outputPath, outputContent, 'utf8');
} catch (error) {
throw new Error('Failed to write Terms of Use content file');
}
},
},
],
{
concurrent: false,
exitOnError: true,
rendererOptions,
},
),
};
/**
* Tasks that changes node modules and should run sequentially
*/
const prepareDependenciesTask = {
title: 'Prepare dependencies',
task: (_, task) =>
task.newListr(
[
copyAndSourceEnvVarsTask,
updateGitSubmodulesTask,
// Inpage bridge must generate before node modules are altered
buildInpageBridgeTask,
nodeifyTask,
jetifyTask,
runLavamoatAllowScriptsTask,
patchPackageTask,
expoBuildLinks,
],
{
exitOnError: true,
concurrent: false,
rendererOptions,
},
),
};
/**
* Tasks that are run concurrently
*/
const concurrentTasks = {
title: 'Concurrent tasks',
task: (_, task) =>
task.newListr([setupIosTask, buildPpomTask, generateTermsOfUseTask], {
concurrent: true,
exitOnError: true,
rendererOptions,
}),
};
const tasks = new Listr([prepareDependenciesTask, concurrentTasks], {
concurrent: false,
exitOnError: true,
rendererOptions,
});
await tasks.run();