@rainfw/core 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/dev.js +30 -1
- package/scripts/generate.js +27 -3
package/package.json
CHANGED
package/scripts/dev.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
const fs = require("node:fs");
|
|
2
2
|
const path = require("node:path");
|
|
3
3
|
const { spawn } = require("node:child_process");
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
generate,
|
|
6
|
+
regenerateClient,
|
|
7
|
+
copyPublicToStatic,
|
|
8
|
+
ROUTES_DIR,
|
|
9
|
+
} = require("./generate");
|
|
5
10
|
const { printBanner } = require("../cli/utils/banner");
|
|
6
11
|
|
|
7
12
|
const SRC_DIR = path.join(process.cwd(), "src");
|
|
@@ -72,6 +77,30 @@ try {
|
|
|
72
77
|
}
|
|
73
78
|
console.log("[watch] Watching src/ for client component changes...");
|
|
74
79
|
|
|
80
|
+
const PUBLIC_DIR = path.join(process.cwd(), "public");
|
|
81
|
+
let publicDebounceTimer = null;
|
|
82
|
+
try {
|
|
83
|
+
if (fs.existsSync(PUBLIC_DIR)) {
|
|
84
|
+
const publicWatcher = fs.watch(
|
|
85
|
+
PUBLIC_DIR,
|
|
86
|
+
{ recursive: true },
|
|
87
|
+
(_eventType, filename) => {
|
|
88
|
+
clearTimeout(publicDebounceTimer);
|
|
89
|
+
publicDebounceTimer = setTimeout(() => {
|
|
90
|
+
console.log(`[watch:public] ${filename}`);
|
|
91
|
+
copyPublicToStatic();
|
|
92
|
+
}, 100);
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
publicWatcher.on("error", () => {
|
|
96
|
+
console.error("[Rain] Warning: Public file watcher error.");
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
} catch (_publicWatchError) {
|
|
100
|
+
console.error("[Rain] Warning: Failed to start public file watcher.");
|
|
101
|
+
}
|
|
102
|
+
console.log("[watch] Watching public/ for static asset changes...");
|
|
103
|
+
|
|
75
104
|
const wrangler = spawn("npx", ["wrangler", "dev"], {
|
|
76
105
|
stdio: "inherit",
|
|
77
106
|
shell: true,
|
package/scripts/generate.js
CHANGED
|
@@ -286,6 +286,28 @@ function buildClientEsbuildAliases(fwPkg) {
|
|
|
286
286
|
return {};
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
function copyDirSync(src, dest) {
|
|
290
|
+
if (!fs.existsSync(dest)) {
|
|
291
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
292
|
+
}
|
|
293
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
294
|
+
const srcPath = path.join(src, entry.name);
|
|
295
|
+
const destPath = path.join(dest, entry.name);
|
|
296
|
+
if (entry.isDirectory()) {
|
|
297
|
+
copyDirSync(srcPath, destPath);
|
|
298
|
+
} else {
|
|
299
|
+
fs.copyFileSync(srcPath, destPath);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function copyPublicToStatic() {
|
|
305
|
+
const publicDir = path.join(PROJECT_ROOT, "public");
|
|
306
|
+
const staticDir = path.join(PROJECT_ROOT, BUILD_CONFIG.outDir, "static");
|
|
307
|
+
if (!fs.existsSync(publicDir)) return;
|
|
308
|
+
copyDirSync(publicDir, staticDir);
|
|
309
|
+
}
|
|
310
|
+
|
|
289
311
|
function bundleClientFilesSync(clientFiles, srcDir, fwPkg) {
|
|
290
312
|
if (clientFiles.length === 0) return [];
|
|
291
313
|
if (!esbuild) {
|
|
@@ -297,7 +319,8 @@ function bundleClientFilesSync(clientFiles, srcDir, fwPkg) {
|
|
|
297
319
|
return [];
|
|
298
320
|
}
|
|
299
321
|
|
|
300
|
-
const
|
|
322
|
+
const staticDir = path.join(PROJECT_ROOT, BUILD_CONFIG.outDir, "static");
|
|
323
|
+
const outDir = path.join(staticDir, "_rain");
|
|
301
324
|
if (!fs.existsSync(outDir)) {
|
|
302
325
|
fs.mkdirSync(outDir, { recursive: true });
|
|
303
326
|
}
|
|
@@ -334,11 +357,10 @@ function bundleClientFilesSync(clientFiles, srcDir, fwPkg) {
|
|
|
334
357
|
loader: { ".ts": "ts", ".tsx": "tsx" },
|
|
335
358
|
});
|
|
336
359
|
|
|
337
|
-
const publicDir = path.join(PROJECT_ROOT, "public");
|
|
338
360
|
const scripts = [];
|
|
339
361
|
for (const [outPath, meta] of Object.entries(result.metafile.outputs)) {
|
|
340
362
|
if (meta.entryPoint) {
|
|
341
|
-
const relPath = path.relative(
|
|
363
|
+
const relPath = path.relative(staticDir, outPath);
|
|
342
364
|
scripts.push(`/${relPath.replace(/\\/g, "/")}`);
|
|
343
365
|
}
|
|
344
366
|
}
|
|
@@ -1129,6 +1151,7 @@ function generate() {
|
|
|
1129
1151
|
const clientFiles = getClientFiles(srcDir);
|
|
1130
1152
|
const hasConfig = fs.existsSync(CONFIG_FILE);
|
|
1131
1153
|
const fwPkg = BUILD_CONFIG.frameworkPackage;
|
|
1154
|
+
copyPublicToStatic();
|
|
1132
1155
|
const clientScripts = bundleClientFilesSync(clientFiles, srcDir, fwPkg);
|
|
1133
1156
|
const frameworkImport =
|
|
1134
1157
|
fwPkg.startsWith(".") || fwPkg.startsWith("/")
|
|
@@ -1200,6 +1223,7 @@ module.exports = {
|
|
|
1200
1223
|
clientFileToIslandId,
|
|
1201
1224
|
bundleClientFilesSync,
|
|
1202
1225
|
generateClientEntrySource,
|
|
1226
|
+
copyPublicToStatic,
|
|
1203
1227
|
validateNoPageRouteColocation,
|
|
1204
1228
|
validateNoDuplicateUrls,
|
|
1205
1229
|
stripRouteGroupSegments,
|