general cleanup + add fileSmasher to replace webpack
This commit is contained in:
parent
3ca20743a3
commit
ba1c4e04d8
9 changed files with 2434 additions and 573 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ build/
|
||||||
bundle/
|
bundle/
|
||||||
world/
|
world/
|
||||||
logs/
|
logs/
|
||||||
|
combined.ts
|
2884
package-lock.json
generated
2884
package-lock.json
generated
File diff suppressed because it is too large
Load diff
14
package.json
14
package.json
|
@ -6,8 +6,11 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev:updateCheck": "check-outdated",
|
"dev:updateCheck": "check-outdated",
|
||||||
"dev:run": "nodemon --watch './**/*.ts' index.ts",
|
"dev:run": "nodemon --watch './**/*.ts' index.ts",
|
||||||
"pack": "webpack",
|
"build": "npm-run-all build:*",
|
||||||
"build": "tsc --build",
|
"build:smash": "ts-node ./tooling/fileSmasher.ts",
|
||||||
|
"build:build": "tsc --build",
|
||||||
|
"build:cleanup": "ts-node ./tooling/cleanup.ts",
|
||||||
|
"build:mangle": "ts-node ./tooling/mangle.ts",
|
||||||
"_clean": "tsc --build --clean"
|
"_clean": "tsc --build --clean"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -22,14 +25,15 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/tgpholly/mc-beta-server#readme",
|
"homepage": "https://github.com/tgpholly/mc-beta-server#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^4.1.2",
|
"bufferstuff": "^1.3.0",
|
||||||
"net": "^1.0.2",
|
"chalk": "^4.1.2"
|
||||||
"bufferstuff": "^1.3.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.16.3",
|
"@types/node": "^18.16.3",
|
||||||
"check-outdated": "^2.11.0",
|
"check-outdated": "^2.11.0",
|
||||||
"nodemon": "^2.0.20",
|
"nodemon": "^2.0.20",
|
||||||
|
"npm-run-all": "^4.1.5",
|
||||||
|
"terser": "^5.18.1",
|
||||||
"ts-loader": "^9.4.1",
|
"ts-loader": "^9.4.1",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.0.4",
|
"typescript": "^5.0.4",
|
||||||
|
|
|
@ -70,7 +70,7 @@ export class World {
|
||||||
return this.chunks.has(coordPairOrX);
|
return this.chunks.has(coordPairOrX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getChunk(x:number, z:number, generate:boolean = true) {
|
public getChunk(x:number, z:number) {
|
||||||
const coordPair = Chunk.CreateCoordPair(x, z);
|
const coordPair = Chunk.CreateCoordPair(x, z);
|
||||||
const existingChunk = this.chunks.get(coordPair);
|
const existingChunk = this.chunks.get(coordPair);
|
||||||
if (!(existingChunk instanceof Chunk)) {
|
if (!(existingChunk instanceof Chunk)) {
|
||||||
|
|
|
@ -23,8 +23,6 @@ export class HillyGenerator implements IGenerator {
|
||||||
private caveGenerator2:Noise3D;
|
private caveGenerator2:Noise3D;
|
||||||
private caveGenerator3:Noise3D;
|
private caveGenerator3:Noise3D;
|
||||||
private caveGenerator4:Noise3D;
|
private caveGenerator4:Noise3D;
|
||||||
private caveGenerator5:Noise3D;
|
|
||||||
private caveGenerator6:Noise3D;
|
|
||||||
|
|
||||||
private underwaterGravelGenerator:Noise2D;
|
private underwaterGravelGenerator:Noise2D;
|
||||||
private underwaterSandGenerator:Noise2D;
|
private underwaterSandGenerator:Noise2D;
|
||||||
|
@ -49,8 +47,6 @@ export class HillyGenerator implements IGenerator {
|
||||||
this.caveGenerator2 = this.createGenerator3D();
|
this.caveGenerator2 = this.createGenerator3D();
|
||||||
this.caveGenerator3 = this.createGenerator3D();
|
this.caveGenerator3 = this.createGenerator3D();
|
||||||
this.caveGenerator4 = this.createGenerator3D();
|
this.caveGenerator4 = this.createGenerator3D();
|
||||||
this.caveGenerator5 = this.createGenerator3D();
|
|
||||||
this.caveGenerator6 = this.createGenerator3D();
|
|
||||||
|
|
||||||
this.underwaterGravelGenerator = this.createGenerator2D();
|
this.underwaterGravelGenerator = this.createGenerator2D();
|
||||||
this.underwaterSandGenerator = this.createGenerator2D();
|
this.underwaterSandGenerator = this.createGenerator2D();
|
||||||
|
|
12
tooling/cleanup.ts
Normal file
12
tooling/cleanup.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { readdirSync, rmSync, renameSync } from "fs";
|
||||||
|
|
||||||
|
const libFiles = readdirSync("./build");
|
||||||
|
|
||||||
|
for (const file of libFiles) {
|
||||||
|
if (!file.startsWith("combined")) {
|
||||||
|
rmSync(`./build/${file}`, { recursive: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renameSync("./build/combined.js", "./build/index.js");
|
||||||
|
//renameSync("./build/combined.d.ts", "./build/index.d.ts");
|
63
tooling/fileSmasher.ts
Normal file
63
tooling/fileSmasher.ts
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
// fileSmasher ~.~
|
||||||
|
// for when you're just too lazy to
|
||||||
|
// do it properly.
|
||||||
|
|
||||||
|
import { readdirSync, statSync, readFileSync, writeFileSync } from "fs";
|
||||||
|
|
||||||
|
let tsFileData:Array<string> = new Array<string>();
|
||||||
|
let tsFirstFileData:Array<string> = new Array<string>();
|
||||||
|
let tsLastFileData:Array<string> = new Array<string>();
|
||||||
|
let tsEverythingElse:Array<string> = new Array<string>();
|
||||||
|
|
||||||
|
function readDir(nam:string) {
|
||||||
|
const files = readdirSync(nam);
|
||||||
|
for (const file of files) {
|
||||||
|
if (nam == "./" && (file.startsWith(".") || file == "tooling" || file == "build" || file == "node_modules" || file == "combined.ts")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a very dumb way of checking for folders
|
||||||
|
// protip: don't do this.
|
||||||
|
if (statSync(`${nam}/${file}`).size == 0) {
|
||||||
|
readDir(`${nam}/${file}`);
|
||||||
|
} else if (file.endsWith(".ts")) {
|
||||||
|
if (file == "index.ts") {
|
||||||
|
tsLastFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
|
||||||
|
} else if (nam.includes("enum")) {
|
||||||
|
tsFirstFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
|
||||||
|
} else {
|
||||||
|
tsEverythingElse.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readDir("./");
|
||||||
|
|
||||||
|
tsFileData = tsFileData.concat(tsFirstFileData).concat(tsEverythingElse).concat(tsLastFileData);
|
||||||
|
|
||||||
|
const combinedFiles = tsFileData.join("\n");
|
||||||
|
|
||||||
|
const splitLines = combinedFiles.split("\n");
|
||||||
|
const resultLines:Array<string> = new Array<string>();
|
||||||
|
|
||||||
|
// Insert allowed imports
|
||||||
|
resultLines.push(`import chalk from "chalk";
|
||||||
|
import { createWriteStream, mkdirSync, existsSync, readFileSync, readFile, writeFile, writeFileSync, readdirSync } from "fs";
|
||||||
|
import { deflate, inflate } from "zlib";
|
||||||
|
import { createWriter, createReader, IReader, Endian } from "bufferstuff";
|
||||||
|
import { Server, Socket } from "net";`);
|
||||||
|
|
||||||
|
// Let's process the file to make it usable
|
||||||
|
for (const line of splitLines) {
|
||||||
|
// Throw away imports as they aren't needed
|
||||||
|
// TODO: Add allow list for npm module imports
|
||||||
|
if (line.startsWith("import")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Fix up classes, interfaces and such.
|
||||||
|
//resultLines.push(line);
|
||||||
|
resultLines.push(line.replace("export class", "class").replace("export interface", "interface").replace("export enum", "enum").replace("export type", "type"));
|
||||||
|
}
|
||||||
|
|
||||||
|
writeFileSync("./combined.ts", resultLines.join("\n"));
|
10
tooling/mangle.ts
Normal file
10
tooling/mangle.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { readFileSync, writeFileSync } from "fs";
|
||||||
|
import { minify } from "terser";
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const mangled = await minify(readFileSync("./build/index.js").toString(), {
|
||||||
|
mangle: true,
|
||||||
|
toplevel: true,
|
||||||
|
});
|
||||||
|
writeFileSync("./build/index.min.js", `${mangled.code}`);
|
||||||
|
})();
|
|
@ -1,15 +0,0 @@
|
||||||
const path = require('path');
|
|
||||||
const nodeExternals = require('webpack-node-externals');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
target: 'node',
|
|
||||||
externals: [ nodeExternals() ],
|
|
||||||
entry: './build/index.js',
|
|
||||||
output: {
|
|
||||||
path: path.join(__dirname, 'bundle'),
|
|
||||||
filename: 'MCBS.js',
|
|
||||||
},
|
|
||||||
optimization: {
|
|
||||||
minimize: true,
|
|
||||||
},
|
|
||||||
};
|
|
Loading…
Reference in a new issue