mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-03-21 17:50:29 -05:00
The idea is to eventually move all client parts to their domain name subdirectory, for clarity and better organization. New Replays is just first. Anyway, yeah, minor updates to New Replays, but otherwise it's just getting deployed as-is, straight to https://replay.pokemonshowdown.com/ The old URLs are getting taken down; they were only used for development anyway.
49 lines
1.7 KiB
JavaScript
Executable File
49 lines
1.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* This script parses index.html and sets the version query string of each
|
|
* resource to be the MD5 hash of that resource.
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const crypto = require('crypto');
|
|
|
|
process.chdir(__dirname);
|
|
|
|
function updateIndex() {
|
|
let indexContents = fs.readFileSync('theme/wrapper.inc.template.php', {encoding: 'utf8'});
|
|
|
|
// add hashes to js and css files
|
|
process.stdout.write("Updating hashes... ");
|
|
// Check for <script, <link or <img so we don't add useless hashes to <a
|
|
indexContents = indexContents.replace(/(<script[^>]+?src|<link[^>]+?href|<img[^>]+?src)="\/(.*?)(\?[a-z0-9]*?)?"/g, runReplace);
|
|
console.log("DONE");
|
|
|
|
process.stdout.write("Writing new `wrapper.inc.php` file... ");
|
|
fs.writeFileSync('theme/wrapper.inc.php', indexContents);
|
|
console.log("DONE");
|
|
}
|
|
|
|
function runReplace(a, b, c) {
|
|
let hash = Math.random(); // just in case creating the hash fails
|
|
const routes = JSON.parse(fs.readFileSync('../config/routes.json'));
|
|
try {
|
|
var filepath = c;
|
|
if (c.includes('/' + routes.client + '/')) {
|
|
const filename = c.replace('/' + routes.client + '/', '');
|
|
filepath = '../' + filename;
|
|
}
|
|
const fstr = fs.readFileSync(filepath, {encoding: 'utf8'});
|
|
hash = crypto.createHash('md5').update(fstr).digest('hex').substr(0, 8);
|
|
} catch (e) {}
|
|
c = c.replace('/replay.pokemonshowdown.com/', '/' + routes.replays + '/');
|
|
c = c.replace('/dex.pokemonshowdown.com/', '/' + routes.dex + '/');
|
|
c = c.replace('/play.pokemonshowdown.com/', '/' + routes.client + '/');
|
|
c = c.replace('/pokemonshowdown.com/users/', '/' + routes.users + '/');
|
|
c = c.replace('/pokemonshowdown.com/', '/' + routes.root + '/');
|
|
|
|
return b + '="/' + c + '?' + hash + '"';
|
|
}
|
|
|
|
updateIndex();
|