From 399f1735b6e23b61eac5916af6362ef307df3dc7 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Thu, 17 May 2018 11:43:15 -0500 Subject: [PATCH] Fix build tools It should now be possible to build from a fresh checkout with `node build`. --- build | 32 +++++++++- build-tools/update | 40 +++++++------ config/config-example.js | 125 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+), 21 deletions(-) create mode 100644 config/config-example.js diff --git a/build b/build index 0ab262f19..d36503d2b 100755 --- a/build +++ b/build @@ -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': diff --git a/build-tools/update b/build-tools/update index 96d681608..7def4860a 100755 --- a/build-tools/update +++ b/build-tools/update @@ -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(//g, newsData[0]); - indexContents = indexContents.replace(//g, newsData[1]); - console.log("DONE"); + indexContents = indexContents.replace(//g, newsData[0]); + indexContents = indexContents.replace(//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(); diff --git a/config/config-example.js b/config/config-example.js new file mode 100644 index 000000000..6d4c58efd --- /dev/null +++ b/config/config-example.js @@ -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' +};