Repository navigation
Expand file tree
/
Copy pathapp.plugin.js
More file actions
62 lines (54 loc) · 1.54 KB
/
Copy pathapp.plugin.js
File metadata and controls
62 lines (54 loc) · 1.54 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
const { withDangerousMod, withPlugins } = require('expo/config-plugins')
const path = require('path')
const fs = require('fs')
function getPackageRoot() {
const pkgJson = require.resolve('react-native-scc-storage/package.json')
return path.dirname(pkgJson)
}
function buildRustIfNeeded(buildScriptName, platform) {
let pkgRoot
try {
pkgRoot = getPackageRoot()
} catch {
console.warn(`[react-native-scc-storage] Could not resolve package root.`)
return
}
const buildScript = path.join(pkgRoot, 'scripts', buildScriptName)
if (!fs.existsSync(buildScript)) {
console.warn(
`[react-native-scc-storage] ${platform} build script missing.`
)
return
}
const { execFileSync } = require('child_process')
try {
execFileSync('bash', [buildScript, '--if-needed'], { stdio: 'inherit', cwd: pkgRoot })
} catch {
console.warn(
`[react-native-scc-storage] ${platform} Rust build failed. ` +
`Run manually: cd node_modules/react-native-scc-storage && npm run rust:build:${platform.toLowerCase()}`
)
}
}
function withSccKvIOS(config) {
return withDangerousMod(config, [
'ios',
async (config) => {
buildRustIfNeeded('build-ios.sh', 'iOS')
return config
},
])
}
function withSccKvAndroid(config) {
return withDangerousMod(config, [
'android',
async (config) => {
buildRustIfNeeded('build-android.sh', 'Android')
return config
},
])
}
function withSccKv(config) {
return withPlugins(config, [withSccKvIOS, withSccKvAndroid])
}
module.exports = withSccKv