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;
|
||||
const fs = require('fs');
|
||||
import beautifier from 'js-beautify';
|
||||
const { js: beautify } = beautifier;
|
||||
import fs from 'fs';
|
||||
|
||||
if (!fs.existsSync("./build")) fs.mkdirSync("./build");
|
||||
fs.cpSync("./static/", "./build/", { recursive: true });
|
||||
|
@ -28,7 +29,7 @@ const escapeRegExp = (string) => string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&')
|
|||
const dictionary = {};
|
||||
|
||||
const matchDictionaryExpression = expression => {
|
||||
result = expression.exec(script);
|
||||
const result = expression.exec(script);
|
||||
if (result === null) throw new Error("no 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;
|
||||
|
@ -103,7 +104,7 @@ const rawPlayerNames = `${dict.playerData}.${dict.rawPlayerNames}`;
|
|||
const gIsSingleplayer = `${dict.game}.${dict.gIsSingleplayer}`;
|
||||
|
||||
// Replace assets
|
||||
const assets = require('./assets.js');
|
||||
import assets from './assets.js';
|
||||
replaceOne(/(\(4,"crown",4,")[^"]+"\),/g, "$1" + assets.crownIcon + "\"),");
|
||||
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...");
|
||||
|
||||
exposeVarsToGlobalScope = true;
|
||||
const exposeVarsToGlobalScope = true;
|
||||
|
||||
if (exposeVarsToGlobalScope && script.startsWith("\"use strict\"; (function () {") && script.endsWith("})();"))
|
||||
script = script.slice("\"use strict\"; (function () {".length, -"})();".length);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
const downloadGame = () => new Promise(resolve => {
|
||||
// Download game
|
||||
// https://stackoverflow.com/a/11944984
|
||||
const https = require('https'); // or 'https' for https:// URLs
|
||||
const fs = require('fs');
|
||||
import https from 'https'; // or 'https' for https:// URLs
|
||||
import fs from 'fs';
|
||||
|
||||
const downloadGame = () => new Promise(resolve => {
|
||||
if (!fs.existsSync("./game")) fs.mkdirSync("./game");
|
||||
const file = fs.createWriteStream("./game/latest.html");
|
||||
// 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");
|
||||
require("./download.js")().then(() => require("./build.js"));
|
||||
await downloadGame();
|
||||
import("./build.js");
|
|
@ -3,6 +3,7 @@
|
|||
"version": "0.5.3",
|
||||
"description": "A modded territorial.io client",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "node index.js",
|
||||
"build-only": "node build.js"
|
||||
|
|
Loading…
Reference in New Issue