mirror of
https://github.com/0x5eal/wg-lua.git
synced 2024-12-12 04:40:36 +00:00
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:
parent
830f91c376
commit
fef63ec48c
7 changed files with 75 additions and 5 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule ".lune/terracotta"]
|
||||||
|
path = .lune/terracotta
|
||||||
|
url = https://github.com/0x5eal/terracotta.git
|
66
.lune/bundle.luau
Normal file
66
.lune/bundle.luau
Normal 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
1
.lune/terracotta
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit c27e3849e3180b8b15a1116a08cef0e73faeeb8d
|
|
@ -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/",
|
||||||
|
|
|
@ -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 = [];
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue