Convert build scripts to ES modules
parent
1ac752275c
commit
44f3ebdb96
11
build.js
11
build.js
|
@ -1,5 +1,6 @@
|
||||||
const beautify = require('js-beautify').js;
|
import beautifier from 'js-beautify';
|
||||||
const fs = require('fs');
|
const { js: beautify } = beautifier;
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
if (!fs.existsSync("./build")) fs.mkdirSync("./build");
|
if (!fs.existsSync("./build")) fs.mkdirSync("./build");
|
||||||
fs.cpSync("./static/", "./build/", { recursive: true });
|
fs.cpSync("./static/", "./build/", { recursive: true });
|
||||||
|
@ -28,7 +29,7 @@ const escapeRegExp = (string) => string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&')
|
||||||
const dictionary = {};
|
const dictionary = {};
|
||||||
|
|
||||||
const matchDictionaryExpression = expression => {
|
const matchDictionaryExpression = expression => {
|
||||||
result = expression.exec(script);
|
const result = expression.exec(script);
|
||||||
if (result === null) throw new Error("no match for ") + expression;
|
if (result === null) throw new Error("no match for ") + expression;
|
||||||
if (expression.exec(script) !== null) throw new Error("more than one match for: ") + expression;
|
if (expression.exec(script) !== null) throw new Error("more than one match for: ") + expression;
|
||||||
for (let [key, value] of Object.entries(result.groups)) dictionary[key] = value;
|
for (let [key, value] of Object.entries(result.groups)) dictionary[key] = value;
|
||||||
|
@ -103,7 +104,7 @@ const rawPlayerNames = `${dict.playerData}.${dict.rawPlayerNames}`;
|
||||||
const gIsSingleplayer = `${dict.game}.${dict.gIsSingleplayer}`;
|
const gIsSingleplayer = `${dict.game}.${dict.gIsSingleplayer}`;
|
||||||
|
|
||||||
// Replace assets
|
// Replace assets
|
||||||
const assets = require('./assets.js');
|
import assets from './assets.js';
|
||||||
replaceOne(/(\(4,"crown",4,")[^"]+"\),/g, "$1" + assets.crownIcon + "\"),");
|
replaceOne(/(\(4,"crown",4,")[^"]+"\),/g, "$1" + assets.crownIcon + "\"),");
|
||||||
replaceOne(/(\(6,"territorial\.io",6,")[^"]+"\),/g, "$1" + assets.fxClientLogo + "\"),");
|
replaceOne(/(\(6,"territorial\.io",6,")[^"]+"\),/g, "$1" + assets.fxClientLogo + "\"),");
|
||||||
|
|
||||||
|
@ -359,7 +360,7 @@ script = script.replace('//api.adinplay.com/libs/aiptag/pub/TRT/territorial.io/t
|
||||||
|
|
||||||
console.log("Formatting code...");
|
console.log("Formatting code...");
|
||||||
|
|
||||||
exposeVarsToGlobalScope = true;
|
const exposeVarsToGlobalScope = true;
|
||||||
|
|
||||||
if (exposeVarsToGlobalScope && script.startsWith("\"use strict\"; (function () {") && script.endsWith("})();"))
|
if (exposeVarsToGlobalScope && script.startsWith("\"use strict\"; (function () {") && script.endsWith("})();"))
|
||||||
script = script.slice("\"use strict\"; (function () {".length, -"})();".length);
|
script = script.slice("\"use strict\"; (function () {".length, -"})();".length);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
const downloadGame = () => new Promise(resolve => {
|
|
||||||
// Download game
|
// Download game
|
||||||
// https://stackoverflow.com/a/11944984
|
// https://stackoverflow.com/a/11944984
|
||||||
const https = require('https'); // or 'https' for https:// URLs
|
import https from 'https'; // or 'https' for https:// URLs
|
||||||
const fs = require('fs');
|
import fs from 'fs';
|
||||||
|
|
||||||
|
const downloadGame = () => new Promise(resolve => {
|
||||||
if (!fs.existsSync("./game")) fs.mkdirSync("./game");
|
if (!fs.existsSync("./game")) fs.mkdirSync("./game");
|
||||||
const file = fs.createWriteStream("./game/latest.html");
|
const file = fs.createWriteStream("./game/latest.html");
|
||||||
// Download the game's code from the website
|
// Download the game's code from the website
|
||||||
|
@ -32,4 +32,4 @@ const request = https.get("https://territorial.io", function (response) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
module.exports = downloadGame;
|
export default downloadGame;
|
4
index.js
4
index.js
|
@ -1,2 +1,4 @@
|
||||||
|
import downloadGame from "./download.js";
|
||||||
console.log("Building FX Client");
|
console.log("Building FX Client");
|
||||||
require("./download.js")().then(() => require("./build.js"));
|
await downloadGame();
|
||||||
|
import("./build.js");
|
|
@ -3,6 +3,7 @@
|
||||||
"version": "0.5.3",
|
"version": "0.5.3",
|
||||||
"description": "A modded territorial.io client",
|
"description": "A modded territorial.io client",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node index.js",
|
"build": "node index.js",
|
||||||
"build-only": "node build.js"
|
"build-only": "node build.js"
|
||||||
|
|
Loading…
Reference in New Issue