forked from mirror/Riven
1
0
Fork 0
Riven/srcgen/index.js

80 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2019-10-19 09:25:09 +00:00
const util = require('util');
const fs = require('fs');
fs.readFileAsync = util.promisify(fs.readFile);
fs.writeFileAsync = util.promisify(fs.writeFile);
const req = require("request-promise-native");
process.chdir(__dirname);
const files = [
[
'http://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json',
'.champion.json'
],
[
'http://www.mingweisamuel.com/riotapi-schema/openapi-3.0.0.json',
'.spec.json'
],
[
'http://static.developer.riotgames.com/docs/lol/seasons.json',
'.seasons.json'
2019-10-23 08:20:34 +00:00
],
[
'http://static.developer.riotgames.com/docs/lol/queues.json',
'.queues.json'
],
[
'http://static.developer.riotgames.com/docs/lol/gameTypes.json',
'.gameTypes.json'
2019-10-26 02:41:41 +00:00
],
[
'http://static.developer.riotgames.com/docs/lol/gameModes.json',
'.gameModes.json'
2019-10-26 02:52:43 +00:00
],
[
'http://static.developer.riotgames.com/docs/lol/maps.json',
'.maps.json'
2019-10-19 09:25:09 +00:00
]
]
const downloadFilesPromise = Promise.all(files.map(([url, file]) => req(url)
.then(body => fs.writeFileAsync(file, body, "utf8"))));
const doT = require('dot');
const glob = require('glob-promise');
const log = a => { console.log(a); return a; };
const suffix = '.dt';
doT.templateSettings = {
evaluate: /\r?\n?\{\{([\s\S]+?)\}\}/g,
interpolate: /\r?\n?\{\{=([\s\S]+?)\}\}/g,
encode: /\r?\n?\{\{!([\s\S]+?)\}\}/g,
use: /\r?\n?\{\{#([\s\S]+?)\}\}/g,
define: /\r?\n?\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
conditional: /\r?\n?\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
iterate: /\r?\n?\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
varname: 'it',
strip: false,
append: false,
selfcontained: false
};
global.require = require;
downloadFilesPromise.then(() => glob.promise("**/*" + suffix, { ignore: ["**/node_modules/**"] }))
.then(files => Promise.all(files
.map(log)
.map(file => fs.readFileAsync(file, "utf8")
.then(input => {
try {
return doT.template(input)({});
}
catch (e) {
console.error(`Error thrown while running "${file}":`, e);
}
})
2019-10-21 02:28:29 +00:00
.then(output => fs.writeFileAsync("../src/" + file.slice(0, -suffix.length), output, "utf8"))
2019-10-19 09:25:09 +00:00
)
))
.catch(console.error);