[mv3] Salvage rule ids for all rulesets

This commit is contained in:
Raymond Hill 2024-02-15 08:02:46 -05:00
parent 8d47eac6e6
commit 7e00046b8e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 52 additions and 43 deletions

View File

@ -55,14 +55,22 @@ if ( beforeDir === '' || afterDir === '' ) {
/******************************************************************************/ /******************************************************************************/
async function main() { async function main() {
const afterFiles = await fs.readdir(`${afterDir}/rulesets/main`); const folders = [
'main',
'modify-headers',
'redirect',
'regex',
'removeparam',
];
const writePromises = []; const writePromises = [];
for ( const folder of folders ) {
const afterFiles = await fs.readdir(`${afterDir}/rulesets/${folder}`);
for ( const file of afterFiles ) { for ( const file of afterFiles ) {
let raw = await fs.readFile(`${beforeDir}/rulesets/main/${file}`, 'utf-8').catch(( ) => ''); let raw = await fs.readFile(`${beforeDir}/rulesets/${folder}/${file}`, 'utf-8').catch(( ) => '');
let beforeRules; let beforeRules;
try { beforeRules = JSON.parse(raw); } catch(_) { } try { beforeRules = JSON.parse(raw); } catch(_) { }
if ( Array.isArray(beforeRules) === false ) { continue; } if ( Array.isArray(beforeRules) === false ) { continue; }
raw = await fs.readFile(`${afterDir}/rulesets/main/${file}`, 'utf-8').catch(( ) => ''); raw = await fs.readFile(`${afterDir}/rulesets/${folder}/${file}`, 'utf-8').catch(( ) => '');
let afterRules; let afterRules;
try { afterRules = JSON.parse(raw); } catch(_) { } try { afterRules = JSON.parse(raw); } catch(_) { }
if ( Array.isArray(afterRules) === false ) { continue; } if ( Array.isArray(afterRules) === false ) { continue; }
@ -96,11 +104,12 @@ async function main() {
} }
writePromises.push( writePromises.push(
fs.writeFile( fs.writeFile(
`${afterDir}/rulesets/main/${file}`, `${afterDir}/rulesets/${folder}/${file}`,
`[\n${lines.join(',\n')}\n]\n` `[\n${lines.join(',\n')}\n]\n`
) )
); );
} }
}
await Promise.all(writePromises); await Promise.all(writePromises);
} }