chore: try build assets in script

This commit is contained in:
Stephen Zhou
2024-12-26 15:30:13 +08:00
parent 53ad291820
commit 3aa5da1bab
2 changed files with 16 additions and 3 deletions
-1
View File
@@ -10,7 +10,6 @@
"ios": "expo run:ios",
"ios:device": "expo run:ios --device",
"lint": "expo lint",
"prepare": "cd ../.. && shx test -d out/rn-web || pnpm run build:rn-web",
"start": "expo start --dev-client",
"web": "expo start --web"
},
+16 -2
View File
@@ -10,6 +10,8 @@
const { withDangerousMod, withXcodeProject, IOSConfig } = require("@expo/config-plugins")
const fs = require("node:fs")
const path = require("node:path")
const { execSync } = require("node:child_process")
const process = require("node:process")
const followRoot = path.resolve(__dirname, "..", "..", "..")
@@ -18,9 +20,21 @@ const ASSET_SOURCE_DIR = path.join("out", "rn-web")
const IOS_GROUP_NAME = "Assets"
const isAssetReady = () => {
return fs.existsSync(path.resolve(followRoot, ASSET_SOURCE_DIR))
}
const withFollowAssets = (config) => {
if (!fs.existsSync(path.resolve(followRoot, ASSET_SOURCE_DIR))) {
throw new Error("Assets source directory not found! Do you forget to run `pnpm build:rn-web`?")
if (!isAssetReady()) {
console.info(
"Assets source directory not found! Running `pnpm build:rn-web` to generate assets.",
)
process.chdir(followRoot)
execSync("pnpm build:rn-web")
process.chdir(__dirname)
}
if (!isAssetReady()) {
throw new Error("Assets source directory not found! Please make sure the build is successful.")
}
config = addAndroidResources(config)
config = addIOSResources(config)