chore: include build script to bundle compiled files too

The build command now compiles the project to lua using roblox-ts, then uses darklua to bundle the files, powered by terracotta.
This commit is contained in:
Erica Marigold 2024-03-29 22:25:57 +05:30
parent 830f91c376
commit fef63ec48c
No known key found for this signature in database
GPG key ID: 2768CC0C23D245D1
7 changed files with 75 additions and 5 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule ".lune/terracotta"]
path = .lune/terracotta
url = https://github.com/0x5eal/terracotta.git

66
.lune/bundle.luau Normal file
View file

@ -0,0 +1,66 @@
local fs = require("@lune/fs")
local stdio = require("@lune/stdio")
local task = require("@lune/task")
local terracotta = require("terracotta")
local function map<k, v>(tbl: { [k]: v }, callback: (k: k, v: v) -> v)
for k, v in tbl do
local ok, val = pcall(function()
return callback(k, v)
end)
if not ok then
tbl[k] = nil
else
tbl[k] = val
end
end
return tbl
end
print("\n")
local dirChildren = fs.readDir("out/rbxts")
local ENTYRPOINTS = map(dirChildren, function(k, path)
if path ~= "rbxts" and path:find("%.lua$") then
print(`{k}/{#dirChildren} include`, path)
return "out/rbxts/" .. path
end
print(`{k}/{#dirChildren} ignore`, path)
error("not a lua file")
end)
function main()
local bundleStart = os.clock()
local out = terracotta.Build({
entryPoints = ENTYRPOINTS,
bundle = true,
rules = {
"remove_spaces",
"remove_unused_while",
"remove_unused_if_branch",
"remove_empty_do",
},
})
print(`\nbundled {#ENTYRPOINTS} files in {os.clock() - bundleStart}s`)
local fsStart = os.clock()
for pos, path in ENTYRPOINTS do
local bundle = out[path]
path = "out/" .. path:split("/")[3]
stdio.write(`\x1B[2K\r{pos}/{#ENTYRPOINTS} write {path}`)
task.wait(0.1)
fs.writeFile(path, bundle)
end
stdio.write(`\x1B[2K\rwrote {#ENTYRPOINTS} files in {os.clock() - fsStart}s`)
end
return main()

1
.lune/terracotta Submodule

@ -0,0 +1 @@
Subproject commit c27e3849e3180b8b15a1116a08cef0e73faeeb8d

View file

@ -4,7 +4,7 @@
"description": "A lua implementation of the wireguard keygen algorithm.", "description": "A lua implementation of the wireguard keygen algorithm.",
"main": "out/init.lua", "main": "out/init.lua",
"scripts": { "scripts": {
"build": "rbxtsc --verbose", "build": "rbxtsc --verbose && ./lunew bundle",
"watch": "rbxtsc -w", "watch": "rbxtsc -w",
"lint": "eslint src", "lint": "eslint src",
"check_fmt": "prettier -c src/", "check_fmt": "prettier -c src/",

View file

@ -1,6 +1,6 @@
const { slice } = require<{ const { slice } = require<{
slice: <T extends defined>(arr: T[], start: number, stop?: number) => T[]; slice: <T extends defined>(arr: T[], start: number, stop?: number) => T[];
}>("util"); }>("./util.lua");
function stringToBytes(str: string) { function stringToBytes(str: string) {
const result = []; const result = [];

View file

@ -1,8 +1,8 @@
const { generatePrivateKey, generatePublicKey } = require<{ const { generatePrivateKey, generatePublicKey } = require<{
generatePrivateKey: () => number[]; generatePrivateKey: () => number[];
generatePublicKey: (privateKey: number[]) => number[]; generatePublicKey: (privateKey: number[]) => number[];
}>("wg"); }>("./wg.lua");
const { atob } = require<{ atob: (buf: number[]) => string }>("base64"); const { atob } = require<{ atob: (buf: number[]) => string }>("./base64.lua");
export interface Keypair { export interface Keypair {
publicKey: string; publicKey: string;

View file

@ -19,7 +19,7 @@
// configurable // configurable
"rootDir": "src", "rootDir": "src",
"outDir": "out", "outDir": "out/rbxts",
"incremental": true, "incremental": true,
"tsBuildInfoFile": "out/tsconfig.tsbuildinfo", "tsBuildInfoFile": "out/tsconfig.tsbuildinfo",
"declaration": true "declaration": true