From 3aa5da1babe9fe788f4365704d9ed8fbb5c6fc35 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Thu, 26 Dec 2024 15:30:13 +0800 Subject: [PATCH] chore: try build assets in script --- apps/mobile/package.json | 1 - apps/mobile/scripts/with-follow-assets.js | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/mobile/package.json b/apps/mobile/package.json index f1105c837..080dd3350 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -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" }, diff --git a/apps/mobile/scripts/with-follow-assets.js b/apps/mobile/scripts/with-follow-assets.js index f6fea0a06..5dab2d339 100644 --- a/apps/mobile/scripts/with-follow-assets.js +++ b/apps/mobile/scripts/with-follow-assets.js @@ -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)