-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
70 lines (51 loc) · 2.12 KB
/
build.js
File metadata and controls
70 lines (51 loc) · 2.12 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import fs from "fs";
import plist from "plist";
import AbilitiesFile from "pokemon-showdown/dist/data/abilities.js";
import ItemsFile from "pokemon-showdown/dist/data/items.js";
import MovesFile from "pokemon-showdown/dist/data/moves.js";
import PokedexFile from "pokemon-showdown/dist/data/pokedex.js";
import NaturesFile from "pokemon-showdown/dist/data/natures.js";
console.log('-- Building Syntax Highlight File');
const files = {
JSONtmLanguage: 'PokemonTeamSyntax.JSON-tmLanguage',
tmLanguage: 'PokemonTeamSyntax.tmLanguage',
sublimeCompletions: 'PokemonTeamSyntax.sublime-completions',
}
let syntaxFile = fs.readFileSync(files.JSONtmLanguage, 'utf-8');
console.log('Started fetching.');
const patterns = {
abilities: AbilitiesFile.Abilities,
items: ItemsFile.Items,
moves: MovesFile.Moves,
pokemons: PokedexFile.Pokedex,
natures: NaturesFile.Natures
};
const toCapital = (str) => str[0].toUpperCase() + str.slice(1);
for (const [pattern, elements] of Object.entries(patterns)) {
const list = Object.values(elements).map(x => x.name);
const replaceTarget = '{{' + pattern + '}}';
const replaceValue = list.sort().reverse().join('|');
syntaxFile = syntaxFile.replace(replaceTarget, replaceValue);
}
console.log('Data gathered, writing language file.');
fs.writeFileSync(files.tmLanguage, plist.build(JSON.parse(syntaxFile)));
console.log('Done.');
console.log('-- Building Completions File');
console.log('Reading current Completions file');
let completionsFile = JSON.parse(fs.readFileSync(files.sublimeCompletions, 'utf-8'));
console.log('Updating completions from data');
completionsFile.completions = [];
for (const [pattern, elements] of Object.entries(patterns)) {
Object.values(elements).forEach(({ name }, index) => {
const type = toCapital(pattern);
let completion = toCapital(name);
if(pattern === 'natures') completion += ' Nature';
completionsFile.completions.push({
trigger: completion + '\t' + type,
contents: completion
});
})
}
console.log('Update finished, writing completions file.');
fs.writeFileSync(files.sublimeCompletions, JSON.stringify(completionsFile, null, '\t'));
console.log('Done.');