Unit test before release, move src/init to cli form
This commit is contained in:
parent
7d7aa8de33
commit
b52882ef2d
15 changed files with 956 additions and 3008 deletions
|
@ -1,42 +1,17 @@
|
|||
--!strict
|
||||
local datetime = require("@lune/datetime")
|
||||
local fs = require("@lune/fs")
|
||||
local net = require("@lune/net")
|
||||
local serde = require("@lune/serde")
|
||||
local stdio = require("@lune/stdio")
|
||||
|
||||
local progress_bar = require("./util/progress")
|
||||
local result = require("./util/result")
|
||||
|
||||
--- Fetches the given file raw from the jecs github
|
||||
local function fetch_raw(file: string): result.Identity<string>
|
||||
local res = net.request(`https://raw.githubusercontent.com/Ukendio/jecs/refs/heads/main/{file}`)
|
||||
if not res.ok then
|
||||
return result(false, `Not ok: {res.statusMessage} @ {res.statusCode}`)
|
||||
end
|
||||
return result(true, res.body)
|
||||
end
|
||||
|
||||
local function save_if_diff(filepath: string, contents: string): result.Identity<nil>
|
||||
if not fs.metadata(filepath).exists then
|
||||
fs.writeFile(filepath, contents)
|
||||
return result(true, nil)
|
||||
end
|
||||
|
||||
local existing = fs.readFile(filepath)
|
||||
if existing == contents then
|
||||
return result(false, "Contents are the same.")
|
||||
end
|
||||
|
||||
fs.writeFile(filepath, contents)
|
||||
return result(true, nil)
|
||||
end
|
||||
|
||||
local function round_to(n: number, places: number)
|
||||
local x = 10 ^ (places or 0)
|
||||
return math.round(n * x) / x
|
||||
end
|
||||
local shared = require("./shared")
|
||||
local types = require("./types")
|
||||
|
||||
--- Synchronizes the required files from the jecs main branch.
|
||||
local function sync(to: string): result.Identity<boolean>
|
||||
local now = datetime.now()
|
||||
local begin = os.clock()
|
||||
|
||||
local progress = progress_bar
|
||||
|
@ -44,13 +19,15 @@ local function sync(to: string): result.Identity<boolean>
|
|||
:withStage("init", "Initializing")
|
||||
:withStage("fetch", "Fetching latest files")
|
||||
:withStage("save", "Saving files")
|
||||
progress:start()
|
||||
:withStage("version", "Pulling latest jecs version")
|
||||
:withStage("metadata", "Writing build metadata")
|
||||
progress:start() -- init
|
||||
|
||||
if not fs.metadata(to).exists then
|
||||
fs.writeDir(to)
|
||||
end
|
||||
|
||||
progress:nextStage()
|
||||
progress:nextStage() -- fetch
|
||||
|
||||
local includes = {
|
||||
"jecs.luau",
|
||||
|
@ -58,13 +35,12 @@ local function sync(to: string): result.Identity<boolean>
|
|||
"CHANGELOG.md",
|
||||
"LICENSE",
|
||||
".luaurc",
|
||||
"default.project.json",
|
||||
}
|
||||
|
||||
local sources = {}
|
||||
|
||||
for _, file in includes do
|
||||
local contents = fetch_raw(file)
|
||||
local contents = shared.fetch_raw(file)
|
||||
if not contents.ok then
|
||||
progress:stop()
|
||||
stdio.ewrite(`🔥 Couldn't get the latest source for {file}:\n{contents.err}\n`)
|
||||
|
@ -74,12 +50,12 @@ local function sync(to: string): result.Identity<boolean>
|
|||
sources[file] = contents.val
|
||||
end
|
||||
|
||||
progress:nextStage()
|
||||
progress:nextStage() -- save
|
||||
|
||||
local sources_modified = {}
|
||||
local any_changed = false
|
||||
for file, contents in sources do
|
||||
local res = save_if_diff(`{to}/{file}`, contents)
|
||||
local res = shared.save_if_diff(`{to}/{file}`, contents)
|
||||
if res.ok then
|
||||
any_changed = true
|
||||
table.insert(sources_modified, file)
|
||||
|
@ -88,7 +64,7 @@ local function sync(to: string): result.Identity<boolean>
|
|||
|
||||
if not any_changed then
|
||||
progress:stop()
|
||||
local took = round_to((os.clock() - begin) * 1_000, 2)
|
||||
local took = shared.round_to((os.clock() - begin) * 1_000, 2)
|
||||
print(
|
||||
`🕛 Finished synchronizing, no changes since latest source {stdio.style("dim")}(took {took}ms){stdio.style(
|
||||
"reset"
|
||||
|
@ -97,9 +73,39 @@ local function sync(to: string): result.Identity<boolean>
|
|||
return result(true, false)
|
||||
end
|
||||
|
||||
progress:stop()
|
||||
local project_json = {
|
||||
name = "jecs-nightly",
|
||||
tree = {
|
||||
["$path"] = "jecs.luau",
|
||||
},
|
||||
}
|
||||
local encoded_project_json = serde.encode("json", project_json)
|
||||
fs.writeFile(`{to}/default.project.json`, encoded_project_json)
|
||||
|
||||
local took = round_to((os.clock() - begin) * 1_000, 2)
|
||||
progress:nextStage() -- version
|
||||
|
||||
local wally_contents = shared.fetch_raw("wally.toml")
|
||||
if not wally_contents.ok then
|
||||
progress:stop()
|
||||
stdio.ewrite(`🔥 Couldn't get the jecs wally manifest:\n{wally_contents.err}\n`)
|
||||
return result(false, `Couldn't get the jecs wally manifest:\n{wally_contents.err}`)
|
||||
end
|
||||
|
||||
local parsed: types.WallyManifest = serde.decode("toml", wally_contents.val)
|
||||
|
||||
progress:nextStage() -- metadata
|
||||
|
||||
local version = `{parsed.package.version}-nightly.{shared.iso_date_light(now)}`
|
||||
local metadata = {
|
||||
version = version,
|
||||
modified = sources_modified,
|
||||
}
|
||||
local encoded_metadata = serde.encode("toml", metadata)
|
||||
fs.writeFile(`{to}/build.txt`, encoded_metadata)
|
||||
|
||||
progress:stop() -- finish
|
||||
|
||||
local took = shared.round_to((os.clock() - begin) * 1_000, 2)
|
||||
print(`🪨 Finished synchronizing {stdio.style("dim")}(took {took}ms){stdio.style("reset")}`)
|
||||
print(`Changed files:`)
|
||||
print(sources_modified)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue