mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: support hydrooj patch
This commit is contained in:
4 files changed
+55
-1
No files matched your search
@@ -204,6 +204,7 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
|
||||
fs.removeSync(newAddonPath);
|
||||
console.log(`Successfully uninstalled ${name}.`);
|
||||
});
|
||||
require('../src/commands/patch').register(cli);
|
||||
cli.help();
|
||||
cli.parse();
|
||||
if (!cli.matchedCommand) {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import child from 'child_process';
|
||||
import { CAC } from 'cac';
|
||||
import fs from 'fs-extra';
|
||||
import superagent from 'superagent';
|
||||
import { Logger } from '@hydrooj/utils';
|
||||
|
||||
const logger = new Logger('patch');
|
||||
|
||||
export function register(cli: CAC) {
|
||||
cli.command('patch <module> <patch>').action(async (filename, patch) => {
|
||||
const mod = require.resolve(filename);
|
||||
if (!mod) {
|
||||
logger.error('Module %s not found', filename);
|
||||
return;
|
||||
}
|
||||
logger.info('Patching %s', mod);
|
||||
const res = await superagent.get(patch);
|
||||
logger.info('Downloaded patch');
|
||||
for (let i = 0; i <= 100; i++) {
|
||||
const fp = `${mod}.${i}.patch`;
|
||||
if (fs.existsSync(fp)) continue;
|
||||
patch = fp;
|
||||
break;
|
||||
}
|
||||
await fs.writeFile(patch, res.text);
|
||||
child.execSync(`patch ${mod} -o ${mod} < ${patch}`);
|
||||
logger.info('Patched %s', mod);
|
||||
});
|
||||
|
||||
// TODO: support revert patch
|
||||
}
|
||||
Reference in new issue
Block a user