mirror of
https://github.com/CompeyDev/codenamer.luau.git
synced 2025-05-04 10:13:46 +01:00
chore(scripts): improved scripts; deps script is platform independent now
This commit is contained in:
parent
e46a5fccc4
commit
2970271e91
2 changed files with 111 additions and 88 deletions
|
@ -1 +1 @@
|
||||||
darklua process src/init.luau dist/codenamer.luau | sed 's/^/[darklua]: /'
|
([[ $WALLY_BUILD ]] && darklua process src/init.luau dist/codenamer.luau | sed 's/^/[darklua]: /') || echo "[!] Depth build not supported yet!"
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
--!strict
|
--!strict
|
||||||
local fs = require("@lune/fs")
|
local fs = require("@lune/fs")
|
||||||
local process = require("@lune/process")
|
local process = require("@lune/process")
|
||||||
|
local task = require("@lune/task")
|
||||||
|
|
||||||
|
|
||||||
local DEPENDENCY_META = table.freeze({
|
local DEPENDENCY_META = table.freeze({
|
||||||
{
|
{
|
||||||
["author"] = "kdudedev",
|
["author"] = "kdudedev",
|
||||||
["pkgname"] = "infinite-math",
|
["pkgname"] = "infinite-math",
|
||||||
["version"] = "1.3.2"
|
["version"] = "1.3.2",
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
local match = function (val, arms: {[any]: any}): any?
|
local match = function<R>(val, arms: { [any]: any }): R
|
||||||
if arms[val] then
|
if arms[val] then
|
||||||
if typeof(arms[val]) == 'function' then
|
if typeof(arms[val]) == "function" then
|
||||||
return arms[val]()
|
return arms[val]()
|
||||||
else
|
else
|
||||||
return arms[val]
|
return arms[val]
|
||||||
|
@ -21,9 +23,8 @@ local match = function (val, arms: {[any]: any}): any?
|
||||||
print("non exhuastive pattern for ", val)
|
print("non exhuastive pattern for ", val)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if arms["_"] then
|
if arms["_"] then
|
||||||
if typeof(arms["_"]) == 'function' then
|
if typeof(arms["_"]) == "function" then
|
||||||
return arms["_"]()
|
return arms["_"]()
|
||||||
else
|
else
|
||||||
return arms["_"]
|
return arms["_"]
|
||||||
|
@ -31,7 +32,6 @@ local match = function (val, arms: {[any]: any}): any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local log = function(kind: "ERROR" | "INFO" | "WARN", msg: string)
|
local log = function(kind: "ERROR" | "INFO" | "WARN", msg: string)
|
||||||
local prefix = match(kind, {
|
local prefix = match(kind, {
|
||||||
["ERROR"] = "[!]",
|
["ERROR"] = "[!]",
|
||||||
|
@ -39,13 +39,12 @@ local log = function (kind: "ERROR" | "INFO" | "WARN", msg: string)
|
||||||
["WARN"] = "[#]",
|
["WARN"] = "[#]",
|
||||||
["_"] = function()
|
["_"] = function()
|
||||||
error("invalid log kind")
|
error("invalid log kind")
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
print(`{prefix} {msg}`)
|
print(`{prefix} {msg}`)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Converts kebab-case to upper CamelCase
|
-- Converts kebab-case to upper CamelCase
|
||||||
local to_camel_case = function(str: string)
|
local to_camel_case = function(str: string)
|
||||||
local parts = string.split(str, "-")
|
local parts = string.split(str, "-")
|
||||||
|
@ -64,24 +63,43 @@ local to_snake_case = function (str: string)
|
||||||
return table.concat(parts, "_")
|
return table.concat(parts, "_")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function main()
|
||||||
|
local shell: {[number]: string} = match(process.os, {
|
||||||
|
["windows"] = { "cmd.exe" },
|
||||||
|
["_"] = { "sh", "-c" }
|
||||||
|
})
|
||||||
|
|
||||||
|
local sh_cmd = table.remove(shell, 1)
|
||||||
|
|
||||||
for _, cmd in { "aftman", "wally" } do
|
for _, cmd in { "aftman", "wally" } do
|
||||||
log("INFO", `Running \`{cmd} install\``)
|
log("INFO", `Running \`{cmd} install\``)
|
||||||
|
|
||||||
process.spawn("sh", { "-c", `{cmd} install`, "|", `sed 's/^/[{cmd}]: /'` }, {
|
local log_scope_pat: string = match(process.os, {
|
||||||
["stdio"] = "inherit"
|
["windows"] = "",
|
||||||
|
["_"] = `| sed 's/^/[{cmd}]: /'`
|
||||||
|
})
|
||||||
|
|
||||||
|
process.spawn(sh_cmd, { shell[1] or "", `{cmd} install`, log_scope_pat }, {
|
||||||
|
["stdio"] = "inherit",
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, DEPENDENCY_DATA in DEPENDENCY_META do
|
for _, DEPENDENCY_DATA in DEPENDENCY_META do
|
||||||
local start = os.clock()
|
local start = os.clock()
|
||||||
|
|
||||||
local dependency_src_dir = `Packages/_Index/{DEPENDENCY_DATA.author}_{DEPENDENCY_DATA.pkgname}@{DEPENDENCY_DATA.version}/{DEPENDENCY_DATA.pkgname}/src/{to_camel_case(DEPENDENCY_DATA.pkgname)}`
|
local dependency_src_dir =
|
||||||
|
`Packages/_Index/{DEPENDENCY_DATA.author}_{DEPENDENCY_DATA.pkgname}@{DEPENDENCY_DATA.version}/{DEPENDENCY_DATA.pkgname}/src/{to_camel_case(DEPENDENCY_DATA.pkgname)}`
|
||||||
local entrypoint_path = dependency_src_dir .. "/init.lua"
|
local entrypoint_path = dependency_src_dir .. "/init.lua"
|
||||||
local values_dir: string?
|
local values_dir: string?
|
||||||
|
|
||||||
if DEPENDENCY_DATA.pkgname == "infinite-math" then values_dir = dependency_src_dir .. "/Values" end
|
if DEPENDENCY_DATA.pkgname == "infinite-math" then
|
||||||
|
values_dir = dependency_src_dir .. "/Values"
|
||||||
|
end
|
||||||
|
|
||||||
log("INFO", `Constructed entrypoint path for {DEPENDENCY_DATA.pkgname} -> {string.sub(entrypoint_path, 1, #entrypoint_path - 45) .. "..."}`)
|
log(
|
||||||
|
"INFO",
|
||||||
|
`Constructed entrypoint path for {DEPENDENCY_DATA.pkgname} -> {string.sub(entrypoint_path, 1, #entrypoint_path - 45) .. "..."}`
|
||||||
|
)
|
||||||
|
|
||||||
if not fs.metadata(entrypoint_path).exists then
|
if not fs.metadata(entrypoint_path).exists then
|
||||||
log("ERROR", `Could not find {DEPENDENCY_DATA.pkgname} entrypoint file`)
|
log("ERROR", `Could not find {DEPENDENCY_DATA.pkgname} entrypoint file`)
|
||||||
|
@ -99,14 +117,19 @@ for _, DEPENDENCY_DATA in DEPENDENCY_META do
|
||||||
|
|
||||||
local entrypoint_contents = fs.readFile(entrypoint_path)
|
local entrypoint_contents = fs.readFile(entrypoint_path)
|
||||||
entrypoint_contents = string.gsub(entrypoint_contents, "local values = script.Values", "")
|
entrypoint_contents = string.gsub(entrypoint_contents, "local values = script.Values", "")
|
||||||
entrypoint_contents = string.gsub(entrypoint_contents, "values.Suffixes", "./Suffixes.lua")
|
entrypoint_contents = string.gsub(entrypoint_contents, "values.Suffixes", "'./Suffixes'")
|
||||||
entrypoint_contents = string.gsub(entrypoint_contents, "values.FullNames", "./FullNames.lua")
|
entrypoint_contents = string.gsub(entrypoint_contents, "values.FullNames", "'./FullNames'")
|
||||||
|
|
||||||
fs.writeFile(dependency_src_dir .. "/" .. to_snake_case(DEPENDENCY_DATA.pkgname) .. ".lua", entrypoint_contents)
|
fs.writeFile(
|
||||||
|
dependency_src_dir .. "/" .. to_snake_case(DEPENDENCY_DATA.pkgname) .. ".lua",
|
||||||
|
entrypoint_contents
|
||||||
|
)
|
||||||
|
|
||||||
log("INFO", `Patched values for {DEPENDENCY_DATA.pkgname}`)
|
log("INFO", `Patched values for {DEPENDENCY_DATA.pkgname}`)
|
||||||
end
|
end
|
||||||
|
|
||||||
log("INFO", `Done with {DEPENDENCY_DATA.pkgname} in {string.sub(tostring(os.clock() - start), 1, 5)}s`)
|
log("INFO", `Done with {DEPENDENCY_DATA.pkgname} in {string.sub(tostring(os.clock() - start), 1, 5)}s`)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task.spawn(main)
|
||||||
|
|
Loading…
Add table
Reference in a new issue