Skip to content

Commit

Permalink
Fixed dev version (somehow?)
Browse files Browse the repository at this point in the history
  • Loading branch information
5jiji committed Jul 10, 2024
1 parent 455d1d2 commit da84287
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
29 changes: 20 additions & 9 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as esbuild from "esbuild";
import { readdir, cp as copy } from "node:fs/promises";

import { readdir, cp as copy, rm as remove } from "node:fs/promises";

/**
*
* @param {string} path
* @param {string} ext
* @returns {Promise<string[]>}
*/
async function getJSFiles(path) {
async function getExtFiles(path, ext) {
const filesNFolder = await readdir(path);
const folders = filesNFolder.filter(v => !v.endsWith(".js"));
let files = filesNFolder.filter(v => v.endsWith(".js"));
const folders = filesNFolder.filter(v => !v.endsWith(ext));
let files = filesNFolder.filter(v => v.endsWith(ext));

for (const folder of folders) {
try {
const newFiles = await getJSFiles(`${path}/${folder}`);
const newFiles = await getExtFiles(`${path}/${folder}`);
files.push(...newFiles.map(v => `${folder}/${v}`));
} catch (e) {
if (e.code) continue;
Expand All @@ -25,20 +25,31 @@ async function getJSFiles(path) {
return files;
}

await remove("./dist", {
recursive: true,
force: true,
})

await copy("./src/client", "./dist", {
recursive: true,
force: true
});

const clientFiles = await getJSFiles("./src/client/scripts");
const clientScript = await getExtFiles("./src/client/scripts", "js");
const clientStyle = [] // await getExtFiles("./src/client/css", ".css");

const clientFiles = [];
clientFiles.push(...clientScript.map(v => `./src/client/scripts/${v}`), ...clientStyle.map(v => `./src/client/css/${v}`));

const result = await esbuild.build({
entryPoints: clientFiles.map(v => `./src/client/scripts/${v}`),
entryPoints: clientFiles,
bundle: true,
minify: true,
outdir: "dist",
outbase: "src/client",
sourcemap: true
sourcemap: true,
platform: "browser",
format: "esm",
});

console.log(result);
4 changes: 2 additions & 2 deletions src/server/utility/HTMLScriptInjector.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ function getCachedHTML(htmlFilePath) {

{ // Inject into play.html, our OBFUSCATED htmlscript.js script.
const htmlFilePath = path.join(__dirname, '..', '..', '..', 'dist', 'views', 'play.html');
const jsFilePath = path.join(__dirname, '..', '..', '..', 'dist', 'scripts', 'game', 'htmlscript.js');
const jsFilePath = path.join(__dirname, '..', '..', 'client', 'scripts', 'game', 'htmlscript.js');
prepareAndCacheHTML(htmlFilePath, jsFilePath, '<head>');
}

{ // Inject into dev.html, our htmlscript.js script.
const htmlFilePath = path.join(__dirname, '..', '..', '..', 'dist', 'views', 'dev.html');
const jsFilePath = path.join(__dirname, '..', '..', '..', 'dist', 'scripts', 'game', 'htmlscript.js');
const jsFilePath = path.join(__dirname, '..', '..', 'client', 'scripts', 'game', 'htmlscript.js');
prepareAndCacheHTML(htmlFilePath, jsFilePath, '<head>');
}

Expand Down

0 comments on commit da84287

Please sign in to comment.