added unpack & moved build stuff
This commit is contained in:
parent
baae1428bd
commit
adb758bd53
37
Makefile
37
Makefile
@ -1,32 +1,57 @@
|
||||
BUNDLE_NAME = bundle.lua
|
||||
HAXE_NAME = haxe.lua
|
||||
MINIFYD_NAME = bundle.min.lua
|
||||
HAXE_ZIP_NAME = "haxe.zip"
|
||||
UNPACK_NAME = unpack.lua
|
||||
UNPACK_POLYFILLED_NAME = unpack.polyfill.lua
|
||||
UNPACK_MINIFYD_NAME = unpack.min.lua
|
||||
BUILD_DIR = build
|
||||
HAXE_FLAGS =
|
||||
POLYFILLED_NAME = bundle.polyfill.lua
|
||||
POLYFILL_SRC = src/polyfill.lua
|
||||
CREAFTOS_PATH = craftos
|
||||
BUILD_HXML = build.hxml
|
||||
|
||||
HAXE_PATH := $(BUILD_DIR)/$(HAXE_NAME)
|
||||
MIN_PATH := $(BUILD_DIR)/$(MINIFYD_NAME)
|
||||
POLYFILL_PATH := $(BUILD_DIR)/$(POLYFILLED_NAME)
|
||||
UNPACK_PATH := $(BUILD_DIR)/$(UNPACK_NAME)
|
||||
UNPACK_MINIFYD_PATH := $(BUILD_DIR)/$(UNPACK_MINIFYD_NAME)
|
||||
HAXE_ZIP_PATH := $(BUILD_DIR)/$(HAXE_ZIP_NAME)
|
||||
UNPACK_POLYFILLED_PATH := $(BUILD_DIR)/$(UNPACK_POLYFILLED_NAME)
|
||||
|
||||
all: clean build
|
||||
all: clean build unpack
|
||||
|
||||
build: HAXE_FLAGS += --main kernel.Entrypoint -D analyzer-optimize
|
||||
build: HAXE_FLAGS += -D analyzer-optimize
|
||||
build: $(MIN_PATH)
|
||||
|
||||
debug: HAXE_FLAGS += -D webconsole -D error_stack --debug
|
||||
debug: build
|
||||
debug: $(MIN_PATH)
|
||||
|
||||
unpack: $(UNPACK_MINIFYD_PATH) $(HAXE_ZIP_PATH)
|
||||
|
||||
$(HAXE_PATH): HAXE_FLAGS += --main kernel.Entrypoint --lua $(HAXE_PATH)
|
||||
$(HAXE_PATH): $(shell find src -name '*.hx')
|
||||
haxe build.hxml $(HAXE_FLAGS)
|
||||
haxe $(BUILD_HXML) $(HAXE_FLAGS)
|
||||
|
||||
$(POLYFILL_PATH): $(POLYFILL_SRC) $(HAXE_PATH)
|
||||
cat $(POLYFILL_SRC) $(HAXE_PATH) > $@
|
||||
|
||||
$(MIN_PATH): $(POLYFILL_PATH)
|
||||
node minify.js $(POLYFILL_PATH) $@
|
||||
node tools/minify.js < $(POLYFILL_PATH) > $@
|
||||
|
||||
$(HAXE_ZIP_PATH): $(MIN_PATH)
|
||||
node tools/zlibDeflate.js < $(MIN_PATH) > $@
|
||||
|
||||
$(UNPACK_PATH): HAXE_FLAGS += --main Unpack -D analyzer-optimize --lua $(UNPACK_PATH)
|
||||
$(UNPACK_PATH): $(shell find src -name '*.hx')
|
||||
haxe $(BUILD_HXML) $(HAXE_FLAGS)
|
||||
|
||||
$(UNPACK_POLYFILLED_PATH): $(UNPACK_PATH)
|
||||
cat $(POLYFILL_SRC) $(UNPACK_PATH) > $@
|
||||
|
||||
$(UNPACK_MINIFYD_PATH): $(UNPACK_POLYFILLED_PATH)
|
||||
node tools/minify.js < $(UNPACK_POLYFILLED_PATH) > $@
|
||||
|
||||
.PHONY: deps
|
||||
deps: deps-hx deps-node
|
||||
@ -54,7 +79,7 @@ emulator:
|
||||
|
||||
.PHONY: webconsole
|
||||
webconsole:
|
||||
node console.js
|
||||
node tools/console.js
|
||||
|
||||
.PHONY: format
|
||||
format:
|
||||
|
@ -10,5 +10,3 @@
|
||||
-D lua-ver 5.1
|
||||
|
||||
--macro include("bin")
|
||||
|
||||
--lua build/haxe.lua
|
||||
|
10
minify.js
10
minify.js
@ -1,10 +0,0 @@
|
||||
const fs = require("fs");
|
||||
const luamin = require("luamin");
|
||||
|
||||
const haxeOutput = fs.readFileSync(process.argv[2] ?? "build/Haxe.min.lua",{encoding:"utf8"});
|
||||
|
||||
const minified = luamin.minify(haxeOutput);
|
||||
|
||||
fs.writeFileSync(process.argv[3] ?? "build/Haxe.min.lua",minified);
|
||||
|
||||
console.log("minified lua");
|
29
src/Unpack.hx
Normal file
29
src/Unpack.hx
Normal file
@ -0,0 +1,29 @@
|
||||
import lua.Lua;
|
||||
import haxe.io.Bytes;
|
||||
import kernel.fs.FS;
|
||||
import haxe.zip.Uncompress;
|
||||
|
||||
class Unpack {
|
||||
public static function main() {
|
||||
var filename = "/haxe.zip";
|
||||
var handle = FS.openReadBinary(filename);
|
||||
var size = FS.attributes(filename).size;
|
||||
var data = Bytes.alloc(size);
|
||||
|
||||
for (i in 0...size) {
|
||||
data.set(i, handle.readByte());
|
||||
}
|
||||
|
||||
var uncompressed = Uncompress.run(data);
|
||||
|
||||
var res = Lua.load(uncompressed.toString()); // FIXME: Haxe is missing some parameters. This does not work.
|
||||
|
||||
var f = res.func; // Required for silly haxe bug.
|
||||
|
||||
if (res.message == null) {
|
||||
f();
|
||||
} else {
|
||||
trace('Failed: ${res.message}');
|
||||
}
|
||||
}
|
||||
}
|
8
tools/minify.js
Normal file
8
tools/minify.js
Normal file
@ -0,0 +1,8 @@
|
||||
const fs = require("fs");
|
||||
const luamin = require("luamin");
|
||||
|
||||
const haxeOutput = fs.readFileSync(0, { encoding: "utf8" });
|
||||
|
||||
const minified = luamin.minify(haxeOutput);
|
||||
|
||||
fs.writeFileSync(1, minified);
|
5
tools/zlibDeflate.js
Normal file
5
tools/zlibDeflate.js
Normal file
@ -0,0 +1,5 @@
|
||||
const zlib = require('node:zlib');
|
||||
|
||||
let def = zlib.createDeflate();
|
||||
|
||||
process.stdin.pipe(def).pipe(process.stdout);
|
Loading…
Reference in New Issue
Block a user