core: patch: support load from local file

This commit is contained in:
undefined committed 2025-07-17 17:41:12 +08:00
1 parent aa2e35ab42
commit 7c38cc6be8
1 file changed
+9 -3
+9 -3
View File
@@ -15,15 +15,21 @@ export function register(cli: CAC) {
return;
}
logger.info('Patching %s', mod);
const res = await superagent.get(patch).responseType('arraybuffer');
logger.info('Downloaded patch');
let content = '';
if (patch.startsWith('http')) {
const res = await superagent.get(patch).responseType('arraybuffer');
logger.info('Downloaded patch');
content = res.body;
} else {
content = await fs.readFile(patch, 'utf-8');
}
for (let i = 0; i <= 100; i++) {
const fp = path.join(path.dirname(mod), `${path.basename(mod)}.${i}.patch`);
if (fs.existsSync(fp)) continue;
patch = fp;
break;
}
await fs.writeFile(patch, res.body);
await fs.writeFile(patch, content);
child.execSync(`patch ${mod} -o ${mod}.tmp < ${patch}`);
await fs.move(`${mod}.tmp`, mod, { overwrite: true });
logger.info('Patched %s', mod);