mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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;
|
return;
|
||||||
}
|
}
|
||||||
logger.info('Patching %s', mod);
|
logger.info('Patching %s', mod);
|
||||||
const res = await superagent.get(patch).responseType('arraybuffer');
|
let content = '';
|
||||||
logger.info('Downloaded patch');
|
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++) {
|
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);
|
||||||
|
|||||||
Reference in new issue
Block a user