-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbootsplash-generate.cjs
More file actions
69 lines (61 loc) · 1.65 KB
/
bootsplash-generate.cjs
File metadata and controls
69 lines (61 loc) · 1.65 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
/**
* Regenerate react-native-bootsplash **iOS/Android** native splash.
* Source of truth: assets/logo.png only.
* Input is copied to a temp PNG so generator I/O never clashes with source files.
*/
const { spawnSync } = require('node:child_process')
const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')
const root = path.join(__dirname, '..')
const LOGO_PNG = path.join(root, 'assets', 'logo.png')
const outDir = path.join(root, 'assets', 'bootsplash')
/**
* @returns {Promise<{ tmp: string; label: string }>}
*/
async function prepareSourcePng(tmp) {
if (fs.existsSync(LOGO_PNG)) {
fs.copyFileSync(LOGO_PNG, tmp)
return { tmp, label: 'assets/logo.png' }
}
throw new Error('bootsplash: missing source. Add assets/logo.png')
}
async function main() {
const tmp = path.join(
os.tmpdir(),
`bootsplash-src-${process.pid}-${Date.now()}.png`,
)
let exitCode = 1
try {
const { label } = await prepareSourcePng(tmp)
console.log(`bootsplash: using source ${label}`)
const args = [
'react-native-bootsplash',
'generate',
tmp,
'--platforms=android,ios',
'--background=#111827',
'--logo-width=160',
'--assets-output',
outDir,
'--flavor=main',
]
const result = spawnSync('npx', args, {
cwd: root,
stdio: 'inherit',
shell: process.platform === 'win32',
})
exitCode = result.status === null ? 1 : result.status
} catch (e) {
console.error(e instanceof Error ? e.message : e)
exitCode = 1
} finally {
try {
fs.unlinkSync(tmp)
} catch {
// ignore
}
}
process.exit(exitCode)
}
main()