refactor: split large modules and normalize rust layout

This commit is contained in:
kdletters
2026-05-18 19:40:14 +08:00
parent 472a47eae7
commit 269f35cecf
51 changed files with 17492 additions and 17169 deletions

View File

@@ -21,6 +21,14 @@ const TARGETS = [
'src',
'module_bindings',
),
entryFile: path.join(
REPO_ROOT,
'server-rs',
'crates',
'spacetime-client',
'src',
'module_bindings.rs',
),
},
];
@@ -64,6 +72,7 @@ for (const target of selectedTargets) {
console.log(`[spacetime:generate] 同步 ${fileCount} 个文件到 ${target.outDir}`);
await replaceGeneratedDir(tempOutDir, target.outDir);
await moveGeneratedEntryFile(target);
}
await rm(tempRoot, {recursive: true, force: true});
@@ -111,6 +120,23 @@ async function replaceGeneratedDir(fromDir, toDir) {
}
}
async function moveGeneratedEntryFile(target) {
if (!target.entryFile) {
return;
}
assertInside(target.entryFile, REPO_ROOT, '生成入口文件');
const generatedModFile = path.join(target.outDir, 'mod.rs');
if (!existsSync(generatedModFile)) {
throw new Error(`${target.name} bindings 缺少入口文件: ${generatedModFile}`);
}
await rm(target.entryFile, {force: true});
await cp(generatedModFile, target.entryFile, {force: true});
await rm(generatedModFile, {force: true});
}
function assertInside(candidate, parent, label) {
const relative = path.relative(path.resolve(parent), path.resolve(candidate));
if (relative === '' || relative.startsWith('..') || path.isAbsolute(relative)) {