add timeline pkg to flutter
This commit is contained in:
20
packages/z-timeline/scripts/copy-build.mjs
Normal file
20
packages/z-timeline/scripts/copy-build.mjs
Normal file
@@ -0,0 +1,20 @@
|
||||
import { cpSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const src = resolve(__dirname, "../build/web");
|
||||
const dest = resolve(__dirname, "../../../apps/web/public/flutter");
|
||||
|
||||
cpSync(src, dest, { recursive: true });
|
||||
console.log(`Copied Flutter build: ${src} → ${dest}`);
|
||||
|
||||
// Extract buildConfig from flutter_bootstrap.js so the React app can fetch it
|
||||
const bootstrap = readFileSync(resolve(dest, "flutter_bootstrap.js"), "utf-8");
|
||||
const match = bootstrap.match(/_flutter\.buildConfig\s*=\s*({.*?});/);
|
||||
if (match) {
|
||||
writeFileSync(resolve(dest, "build_config.json"), match[1]);
|
||||
console.log("Extracted build_config.json");
|
||||
} else {
|
||||
console.warn("Could not extract buildConfig from flutter_bootstrap.js");
|
||||
}
|
||||
Reference in New Issue
Block a user