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
+7 -1
+7 -1
View File
@@ -15,15 +15,21 @@ export function register(cli: CAC) {
return; return;
} }
logger.info('Patching %s', mod); logger.info('Patching %s', mod);
let content = '';
if (patch.startsWith('http')) {
const res = await superagent.get(patch).responseType('arraybuffer'); const res = await superagent.get(patch).responseType('arraybuffer');
logger.info('Downloaded patch'); logger.info('Downloaded patch');
content = res.body;
} else {
content = await fs.readFile(patch, 'utf-8');
}
for (let i = 0; i <= 100; i++) { for (let i = 0; i <= 100; i++) {
const fp = path.join(path.dirname(mod), `${path.basename(mod)}.${i}.patch`); const fp = path.join(path.dirname(mod), `${path.basename(mod)}.${i}.patch`);
if (fs.existsSync(fp)) continue; if (fs.existsSync(fp)) continue;
patch = fp; patch = fp;
break; break;
} }
await fs.writeFile(patch, res.body); await fs.writeFile(patch, content);
child.execSync(`patch ${mod} -o ${mod}.tmp < ${patch}`); child.execSync(`patch ${mod} -o ${mod}.tmp < ${patch}`);
await fs.move(`${mod}.tmp`, mod, { overwrite: true }); await fs.move(`${mod}.tmp`, mod, { overwrite: true });
logger.info('Patched %s', mod); logger.info('Patched %s', mod);