Re-organize javascript files

This commit is contained in:
Ethan O'Brien 2024-07-27 15:00:29 -05:00
parent ce59daeb24
commit cb3017d533
10 changed files with 32 additions and 27 deletions

View file

@ -1,4 +1,15 @@
(async function() { (async function() {
const scripts = [
"emulator.js",
"nipplejs.js",
"shaders.js",
"storage.js",
"gamepad.js",
"GameManager.js",
"socket.io.min.js"
];
const folderPath = (path) => path.substring(0, path.length - path.split('/').pop().length); const folderPath = (path) => path.substring(0, path.length - path.split('/').pop().length);
let scriptPath = (typeof window.EJS_pathtodata === "string") ? window.EJS_pathtodata : folderPath((new URL(document.currentScript.src)).pathname); let scriptPath = (typeof window.EJS_pathtodata === "string") ? window.EJS_pathtodata : folderPath((new URL(document.currentScript.src)).pathname);
if (!scriptPath.endsWith('/')) scriptPath+='/'; if (!scriptPath.endsWith('/')) scriptPath+='/';
@ -9,8 +20,10 @@
script.src = function() { script.src = function() {
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') { if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') {
return EJS_paths[file]; return EJS_paths[file];
} else { } else if (file.endsWith(".min.js")) {
return scriptPath + file; return scriptPath + file;
} else {
return scriptPath + "src/" + file;
} }
}(); }();
script.onload = resolve; script.onload = resolve;
@ -46,13 +59,9 @@
if (minifiedFailed) { if (minifiedFailed) {
console.log("Attempting to load non-minified files"); console.log("Attempting to load non-minified files");
if (file === "emulator.min.js") { if (file === "emulator.min.js") {
await loadScript('emulator.js'); for (let i=0; i<scripts.length; i++) {
await loadScript('nipplejs.js'); await loadScript(scripts[i]);
await loadScript('shaders.js'); }
await loadScript('storage.js');
await loadScript('gamepad.js');
await loadScript('GameManager.js');
await loadScript('socket.io.min.js');
} else { } else {
await loadStyle('emulator.css'); await loadStyle('emulator.css');
} }
@ -60,13 +69,9 @@
} }
if (('undefined' != typeof EJS_DEBUG_XX && true === EJS_DEBUG_XX)) { if (('undefined' != typeof EJS_DEBUG_XX && true === EJS_DEBUG_XX)) {
await loadScript('emulator.js'); for (let i=0; i<scripts.length; i++) {
await loadScript('nipplejs.js'); await loadScript(scripts[i]);
await loadScript('shaders.js'); }
await loadScript('storage.js');
await loadScript('gamepad.js');
await loadScript('GameManager.js');
await loadScript('socket.io.min.js');
await loadStyle('emulator.css'); await loadStyle('emulator.css');
} else { } else {
await loadScript('emulator.min.js'); await loadScript('emulator.min.js');

View file

@ -2,18 +2,18 @@ const UglifyJS = require("uglify-js");
const fs = require('fs'); const fs = require('fs');
const uglifycss = require('uglifycss'); const uglifycss = require('uglifycss');
let files = [ const scripts = [
'nipplejs.js', "emulator.js",
'shaders.js', "nipplejs.js",
'storage.js', "shaders.js",
'gamepad.js', "storage.js",
'GameManager.js', "gamepad.js",
'socket.io.min.js', "GameManager.js",
'emulator.js' "socket.io.min.js"
] ];
let code = "(function() {\n"; let code = "(function() {\n";
for (let i=0; i<files.length; i++) { for (let i=0; i<scripts.length; i++) {
code += fs.readFileSync('../'+files[i], 'utf8') + "\n"; code += fs.readFileSync('../src/'+scripts[i], 'utf8') + "\n";
} }
code += "\n})();" code += "\n})();"