mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: patch: support load from local file
This commit is contained in:
1 file changed
+9
-3
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user