mirror of https://github.com/gorhill/uBlock.git
[mv3] Salvage rule ids for all rulesets
This commit is contained in:
parent
8d47eac6e6
commit
7e00046b8e
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue