-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathgenerate-react-native-cli-fixture.js
More file actions
121 lines (94 loc) · 3.86 KB
/
generate-react-native-cli-fixture.js
File metadata and controls
121 lines (94 loc) · 3.86 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
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
#!/usr/bin/env node
const { execFileSync, execSync } = require('child_process')
const { resolve } = require('path')
const fs = require('fs')
const common = require('./common')
const androidUtils = require('./react-native/android-utils')
const iosUtils = require('./react-native/ios-utils')
if (!process.env.RN_VERSION) {
console.error('Please provide a React Native version')
process.exit(1)
}
if (!process.env.RCT_NEW_ARCH_ENABLED || (process.env.RCT_NEW_ARCH_ENABLED !== '1' && process.env.RCT_NEW_ARCH_ENABLED !== '0')) {
console.error('RCT_NEW_ARCH_ENABLED must be set to 1 or 0')
process.exit(1)
}
const notifierVersion = process.env.NOTIFIER_VERSION || common.getCommitId()
const reactNativeVersion = process.env.RN_VERSION
const ROOT_DIR = resolve(__dirname, '../')
const isNewArchEnabled = process.env.RCT_NEW_ARCH_ENABLED === '1'
let exportArchive = true
let fixturePath = process.env.FIXTURE_DIR || 'test/react-native-cli/features/fixtures/generated/'
if (isNewArchEnabled) {
fixturePath += 'new-arch/'
} else {
fixturePath += 'old-arch/'
}
const fixtureDir = resolve(ROOT_DIR, fixturePath, reactNativeVersion)
const replacementFilesDir = resolve(ROOT_DIR, 'test/react-native-cli/features/fixtures/app/dynamic/')
function packLocalPackages () {
// Build all packages first
execSync('npm ci', { cwd: ROOT_DIR, stdio: 'inherit' })
execSync('npm run build', { cwd: ROOT_DIR, stdio: 'inherit' })
// Pack the react-native-cli package
const packagesDir = resolve(ROOT_DIR, 'packages')
const packages = [
'react-native-cli'
]
// Pack each package and move the tarballs to the fixture directory
for (const pkg of packages) {
execSync(`npm pack "${resolve(packagesDir, pkg)}" --pack-destination "${fixtureDir}"`, { stdio: 'inherit' })
}
}
// Generate the fixture
if (!process.env.SKIP_GENERATE_FIXTURE) {
// remove the fixture directory if it already exists
if (fs.existsSync(fixtureDir)) {
fs.rmSync(fixtureDir, { recursive: true, force: true })
}
// create the test fixture
const RNInitArgs = ['@react-native-community/cli@16', 'init', 'reactnative', '--directory', fixtureDir, '--version', reactNativeVersion, '--pm', 'npm', '--skip-install']
execFileSync('npx', RNInitArgs, { stdio: 'inherit' })
replaceGeneratedFixtureFiles()
androidUtils.configureAndroidProject(fixtureDir, isNewArchEnabled)
iosUtils.configureIOSProject(fixtureDir)
// Pack and install local packages
packLocalPackages()
execSync('npm install --save bugsnag-*.tgz --legacy-peer-deps', { cwd: fixtureDir, stdio: 'inherit' })
if (process.env.INIT_RN_CLI === 'true' || process.env.INIT_RN_CLI === '1') {
enableSourceMaps()
}
}
// Build the android fixture
if (process.env.BUILD_ANDROID === 'true' || process.env.BUILD_ANDROID === '1') {
// build the android app
androidUtils.buildAPK(fixtureDir)
}
// Build the iOS fixture
if (process.env.BUILD_IOS === 'true' || process.env.BUILD_IOS === '1') {
if (process.env.EXPORT_ARCHIVE !== 'true' || process.env.EXPORT_ARCHIVE !== '1') {
exportArchive = false
}
iosUtils.buildIPA(fixtureDir, exportArchive)
}
function enableSourceMaps () {
common.changeDir(`${ROOT_DIR}/scripts`)
const initCommand = `./init-rn-cli.sh ${notifierVersion} ${reactNativeVersion} ${fixtureDir}`
common.run(initCommand, true)
}
/** Replace native files generated by react-native cli with pre-configured files */
function replaceGeneratedFixtureFiles () {
// copy the exportOptions.plist file
fs.copyFileSync(
resolve(replacementFilesDir, 'ios/exportOptions.plist'),
resolve(fixtureDir, 'exportOptions.plist')
)
// replace the App.js/App.tsx file with our own App.js file
fs.readdirSync(resolve(fixtureDir))
.filter((file) => /App\.[tj]sx?$/.test(file))
.map((file) => fs.unlinkSync(resolve(fixtureDir, file)))
fs.copyFileSync(
resolve(replacementFilesDir, 'App.js'),
resolve(fixtureDir, 'App.js')
)
}