-
Notifications
You must be signed in to change notification settings - Fork 1
/
anonymize
executable file
·41 lines (33 loc) · 1.13 KB
/
anonymize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
'use strict';
try {
require('source-map-support').install();
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') throw err;
}
const fs = require('fs');
const {Anonymizer, Verifier} = require('./build/index');
const {Generations} = require('@pkmn/data');
const {Dex} = require('@pkmn/dex');
const raw = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
const copy = JSON.parse(JSON.stringify(raw));
const gens = new Generations(Dex);
const gen = gens.get(raw.format.startsWith('gen') ? +raw.format.charAt(3) : 6);
const verifier = new Verifier();
const anon = Anonymizer.anonymize(gen, raw, {verifier});
if (!verifier.ok()) {
const msg = `Potentially leaked name from {${Array.from(verifier.names)}} in log`;
for (const {input, output} of verifier.leaks) {
console.error(`\x1b[91m${msg}:\x1b[0m\n${input}\n${output}\n`);
}
} else if (process.argv.length <= 4) {
console.log(JSON.stringify(anon, null, 2));
}
if (process.argv.length > 4) {
try {
const diff = require('json-diff');
console.log(diff.diffString(copy, anon));
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') throw err;
}
}