24 lines
1.1 KiB
JavaScript
24 lines
1.1 KiB
JavaScript
import {spawnSync} from 'node:child_process';
|
|
import {readFileSync} from 'node:fs';
|
|
import {dirname, resolve} from 'node:path';
|
|
import {fileURLToPath} from 'node:url';
|
|
|
|
const patchDir = resolve(dirname(fileURLToPath(import.meta.url)), '../patches');
|
|
const source = resolve(process.argv[2] || 'fluxer-src');
|
|
const names = readFileSync(resolve(patchDir, 'series'), 'utf8').split(/\r?\n/).filter(Boolean);
|
|
if (!names.length) throw new Error('The patch series is empty');
|
|
const patches = names.map((name) => {
|
|
if (!/^[0-9]{4}-[a-z0-9-]+\.patch$/.test(name)) throw new Error(`Invalid patch name: ${name}`);
|
|
return resolve(patchDir, name);
|
|
});
|
|
function apply(...options) {
|
|
const result = spawnSync('git', ['-C', source, 'apply', '--whitespace=error-all', ...options, ...patches], {
|
|
stdio: 'inherit',
|
|
});
|
|
if (result.error) throw result.error;
|
|
if (result.status !== 0) throw new Error(`git apply ${options.join(' ')} failed (${result.status})`);
|
|
}
|
|
apply('--check');
|
|
if (!process.argv.includes('--check')) apply();
|
|
console.log(`Validated ${patches.length} GSCORD patches${process.argv.includes('--check') ? '' : ' and applied them'}.`);
|