Fix build tools

It should now be possible to build from a fresh checkout with
`node build`.
This commit is contained in:
Guangcong Luo 2018-05-17 11:43:15 -05:00
parent 1dfaddafa1
commit 399f1735b6
3 changed files with 176 additions and 21 deletions

32
build
View File

@ -1,8 +1,36 @@
#!/usr/bin/env node
const execSync = require('child_process').execSync;
try {
eval('{ let a = {}; let b = {...a}; }');
} catch (e) {
console.log("We require Node.js version 9 or later; you're using " + process.version);
process.exit(1);
}
const options = {cwd: __dirname, stdio: 'inherit'};
var execSync = require('child_process').execSync;
var fs = require('fs');
var path = require('path');
try {
require.resolve('@babel/core');
} catch (e) {
console.log('Installing dependencies...');
execSync('npm install', {stdio: 'inherit'});
}
try {
require.resolve('./config/config');
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') throw err; // should never happen
console.log('config.js does not exist. Creating one with default settings...');
fs.writeFileSync(
path.resolve(__dirname, 'config/config.js'),
fs.readFileSync(path.resolve(__dirname, 'config/config-example.js'))
);
}
var options = {cwd: __dirname, stdio: 'inherit'};
switch (process.argv[2] || '') {
case 'full':

View File

@ -68,28 +68,30 @@ function updateIndex() {
});
console.log("DONE");
// add news
process.stdout.write("Updating news... ");
child_process.exec('php ' + path.resolve(thisDir, 'news-data.php'), function (error, stdout, stderr) {
let newsData = [0, '[failed to retrieve news]'];
if (!error && !stderr) {
try {
newsData = JSON.parse(stdout);
} catch (e) {
console.log("git hook failed to retrieve news (parsing JSON failed):\n" + e.stack);
// add news, only if it's actually likely to exist
if (__dirname.endsWith('play.pokemonshowdown.com/build-tools')) {
process.stdout.write("Updating news... ");
child_process.exec('php ' + path.resolve(thisDir, 'news-data.php'), function (error, stdout, stderr) {
let newsData = [0, '[failed to retrieve news]'];
if (!error && !stderr) {
try {
newsData = JSON.parse(stdout);
} catch (e) {
console.log("git hook failed to retrieve news (parsing JSON failed):\n" + e.stack);
}
} else {
console.log("git hook failed to retrieve news (exec command failed):\n" + (error + stderr + stdout));
}
} else {
console.log("git hook failed to retrieve news (exec command failed):\n" + (error || stderr));
}
indexContents = indexContents.replace(/<!-- newsid -->/g, newsData[0]);
indexContents = indexContents.replace(/<!-- news -->/g, newsData[1]);
console.log("DONE");
indexContents = indexContents.replace(/<!-- newsid -->/g, newsData[0]);
indexContents = indexContents.replace(/<!-- news -->/g, newsData[1]);
console.log("DONE");
process.stdout.write("Writing new `index.html` file... ");
fs.writeFileSync('index.html', indexContents);
console.log("DONE");
});
process.stdout.write("Writing new `index.html` file... ");
fs.writeFileSync('index.html', indexContents);
console.log("DONE");
});
}
}
updateIndex();

125
config/config-example.js Normal file
View File

@ -0,0 +1,125 @@
var Config = Config || {};
/* version */ Config.version = "0";
Config.bannedHosts = ['cool.jit.su', 'pokeball-nixonserver.rhcloud.com'];
Config.whitelist = [
// general sites
'wikipedia\\.org',
'wikimedia\\.org',
'wiktionary\\.org',
'github\\.com',
'reddit\\.com',
'gamefaqs\\.com',
'facebook\\.com',
'fbcdn\\.net',
'twitter\\.com',
'deviantart\\.com',
'youtube\\.com',
'youtu\\.be',
'zombo\\.com',
'strawpoll\\.me',
'twitch\\.tv',
'take-a-screenshot\\.org',
'myanimelist\\.net',
'4chan\\.org',
'tumblr\\.com',
'git\\.io',
'mibbit\\.com',
'codecademy\\.com',
'xkcd\\.com',
'stackoverflow\\.com',
'stackexchange\\.com',
'malwarebytes\\.org',
'animenewsnetwork\\.com',
'animenewsnetwork\\.cc',
'zombo\\.com',
'html5zombo\\.com',
// pokemon sites
'pokemonshowdown\\.com',
'psim\\.us',
'smogon\\.com',
'upokecenter\\.com',
'veekun\\.com',
'bulbagarden\\.net',
'serebii\\.net',
'nuggetbridge\\.com',
'pokecommunity\\.com',
'pokemon-online\\.eu',
'pokemonlab\\.com',
'shoddybattle\\.com',
'pokemonxy\\.com',
'pokemon\\.com',
'pokemon-gl\\.com',
'pokecheck\\.org',
'projectpokemon\\.org',
'pokemondb\\.net',
'pokemoncentral\\.it',
'poketrade\\.us',
'neverused\\.net',
'pokestrat\\.com',
'spo\\.ink',
'jooas\\.com',
'pokemongodb\\.net',
'pokeassistant\\.com',
'pokemon-sunmoon\\.com',
'gamepress\\.gg',
'trainertower\\.com',
'pokepast\\.es',
// personal sites
'breakdown\\.forumotion\\.com',
'pokemonmillennium\\.net',
'thebattletower\\.no-ip\\.org',
'meltsner\\.com',
'guangcongluo\\.com',
'cathyjf\\.com',
'xiaotai\\.org',
'xfix\\.pw',
'bumba\\.me',
'strategydatabase\\.jimdo\\.com',
'hidden50\\.github\\.io',
// personal hosting sites
'forumieren\\.com',
'soforums\\.com',
'proboards\\.com',
'weebly\\.com',
'freeforums\\.org',
'forumactif\\.com',
'forumotion\\.com',
'bigbangpokemon\\.com',
// rich text
'docs\\.google\\.com',
// text
'pastebin\\.com',
'hastebin\\.com',
'trello\\.com',
'challonge\\.com',
'piratepad\\.net',
// music
'plug\\.dj',
'openings\\.moe',
// images
'prntscr\\.com',
'prnt\\.sc',
'puu\\.sh',
'd\\.pr',
'snag\\.gy',
'gyazo\\.com',
'imgur\\.com',
'gfycat\\.com',
'4cdn\\.org'
];
Config.roomsFirstOpenScript = function () {
};
Config.customcolors = {
'zarel': 'aeo'
};