Skip to content

Commit

Permalink
feat: build system
Browse files Browse the repository at this point in the history
  • Loading branch information
znotfireman committed Sep 13, 2024
1 parent 2929f50 commit db853f9
Show file tree
Hide file tree
Showing 60 changed files with 286 additions and 71 deletions.
31 changes: 31 additions & 0 deletions .darklua-dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"generator": "retain_lines",
"rules": [
{
"current": {
"name": "path",
"sources": {
"lib": "lib"
}
},
"rule": "convert_require",
"target": {
"indexing_style": "property",
"name": "roblox",
"rojo_sourcemap": "./sourcemap.json"
}
},
{
"identifier": "__DEV__",
"rule": "inject_global_value",
"value": false
},
"compute_expression",
"remove_unused_if_branch",
"remove_unused_while",
"filter_after_early_return",
"remove_nil_declaration",
"remove_empty_do",
"remove_spaces"
]
}
34 changes: 34 additions & 0 deletions .darklua.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"generator": {
"column_span": 9999999999,
"name": "dense"
},
"rules": [
{
"current": {
"name": "path",
"sources": {
"lib": "lib"
}
},
"rule": "convert_require",
"target": {
"indexing_style": "property",
"name": "roblox",
"rojo_sourcemap": "./sourcemap.json"
}
},
{
"identifier": "__DEV__",
"rule": "inject_global_value",
"value": false
},
"compute_expression",
"remove_unused_if_branch",
"remove_unused_while",
"filter_after_early_return",
"remove_nil_declaration",
"remove_empty_do",
"remove_spaces"
]
}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Selene
run: |
selene src/
selene lib/
formatting:
name: Formatting
runs-on: ubuntu-latest
Expand All @@ -35,4 +35,4 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v0.20.0
args: --check src/
args: --check lib/
89 changes: 89 additions & 0 deletions .lune/build/builder.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
local fs = require("@lune/fs")
local path = require("../utils/path")
local pesdeTemplate = require("./templates/pesde")
local process = require("@lune/process")
local rojoProject = require("./templates/rojo")
local serde = require("@lune/serde")
local summon = require("../utils/summon")
local wallyTemplate = require("./templates/wally")

local PATH_LIB = path(process.cwd, "lib")
local PATH_DIST = path(process.cwd, "dist")
local DARKLUA_DEV = path(process.cwd, ".darklua-dev.json")
local DARKLUA_STD = path(process.cwd, ".darklua.json")
local ROJO_PROJECT = path(process.cwd, "default.project.json")
local ROJO_SOURCEMAP = path(process.cwd, "sourcemap.json")

local Builder = {}

local function reset(dir: string)
if not fs.isDir(dir) then
fs.writeDir(dir)
else
for _, file in fs.readDir(dir) do
if fs.isFile(path(dir, file)) then
fs.removeFile(path(dir, file))
end
end
end
end

function Builder.build(props: {
createModel: boolean,
createRelease: boolean,
version: string,
})
-- stylua: ignore
local createModel, createRelease, version = props.createModel, props.createRelease, props.version
assert(
version:match("^(%d+)%.?(%d*)%.?(%d*)(.-)$") ~= nil,
`{version} is not a valid semver version`
)

reset(PATH_DIST)

print("Generating sourcemap")
summon("rojo", "sourcemap", ROJO_PROJECT, "-o", ROJO_SOURCEMAP)

-- FIXME: Darklua is stinky & cant give good types on bundle
print("Processing library files")
local darkluaConfig = createRelease and DARKLUA_STD or DARKLUA_DEV
summon("darklua", "process", PATH_LIB, path(PATH_DIST, "lib"), "-c", darkluaConfig, "-v")

fs.copy(path(process.cwd, "README.md"), path(PATH_DIST, "README.md"))

print("Writing Rojo project")
fs.writeFile(path(PATH_DIST, "default.project.json"), serde.encode("json", rojoProject))

if createRelease then
print("Writing Wally config")
local wally = table.clone(wallyTemplate)
wally.package.version = version
fs.writeFile(path(PATH_DIST, "wally.toml"), serde.encode("toml", wally))

print("Writing Pesde config")
local pesde = table.clone(pesdeTemplate)
pesde.version = version
fs.writeFile(path(PATH_DIST, "pesde.yaml"), serde.encode("yaml", pesde))

print("Publishing")
summon("wally", "publish", "-v", "--project-path", PATH_DIST)
process.spawn("pesde", { "publish" }, {
shell = true,
cwd = PATH_DIST,
})
end

if createModel then
print("Creating Roblox model")
summon(
"rojo",
"build",
path(PATH_DIST, "default.project.json"),
"-o",
path(PATH_DIST, "pretty-fusion-utils.rbxm")
)
end
end

return Builder
23 changes: 23 additions & 0 deletions .lune/build/init.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--!strict
-- (c) Prvd 'M Wrong, dual-licensed under MIT or Apache 2.0 terms.

local Builder = require("./builder")
local stdio = require("@lune/stdio")

local createModel = stdio.prompt("confirm", "Create .rbxm models?")
local createRelease = stdio.prompt("confirm", "Release to Wally/Pesde?")
local version = "0.0.0-dev"
if createRelease then
local promptedVersion = stdio.prompt("text", "Semver version to publish as?")
assert(
promptedVersion:match("^(%d+)%.?(%d*)%.?(%d*)(.-)$") ~= nil,
`{version} is not a valid semver version`
)
version = promptedVersion
end

Builder.build {
createModel = createModel,
createRelease = createRelease,
version = version,
}
16 changes: 16 additions & 0 deletions .lune/build/templates/pesde.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
return {
name = "znotfireman/pretty_fusion_utils",
description = "An opinionated collection of modern Fusion 0.3 utilities.",
version = (nil :: any) :: string,
license = "MIT",
authors = { "znotfireman <znotfireman+hello@gmail.com>" },
realm = "shared",
repository = "https://github.com/znotfireman/pretty-fusion-utils",
indices = {
default = "https://github.com/daimond113/pesde-index",
},
exports = {
lib = "./lib/init.luau",
},
dependencies = {},
}
6 changes: 6 additions & 0 deletions .lune/build/templates/rojo.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
return {
name = "pretty-fusion-utils",
tree = {
["$path"] = "lib",
},
}
14 changes: 14 additions & 0 deletions .lune/build/templates/wally.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
return {
package = {
name = "znotfireman/pretty-fusion-utils",
description = "An opinionated collection of modern Fusion 0.3 utilities.",
version = (nil :: any) :: string,
license = "Apache-2.0 OR MIT",
authors = { "znotfireman <znotfireman+hello@gmail.com>" },
realm = "shared",
repository = "https://github.com/znotfireman/pretty-fusion-utils",
registry = "https://github.com/UpliftGames/wally-index",
include = { "./lib", "./default.project.json" },
exclude = { "node_modules" },
},
}
18 changes: 9 additions & 9 deletions .lune/regen/regenerator.luau
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local serde = require("@lune/serde")
local stringer = require("../utils/stringer")

local PATH_DOCS = path(process.cwd, "docs")
local PATH_SRC = path(process.cwd, "src")
local PATH_LIB = path(process.cwd, "lib")
local TEMPLATE_INDEX = path(process.cwd, ".lune", "regen", "templates", "index.md")

local function reset(dir: string)
Expand All @@ -25,8 +25,8 @@ end

local utils = {}

for _, dir in fs.readDir(PATH_SRC) do
local dirPath, configPath = path(PATH_SRC, dir), path(PATH_SRC, dir, "doc.toml")
for _, dir in fs.readDir(PATH_LIB) do
local dirPath, configPath = path(PATH_LIB, dir), path(PATH_LIB, dir, "doc.toml")
if not fs.isDir(dirPath) or not fs.isFile(configPath) then
continue
end
Expand Down Expand Up @@ -55,10 +55,10 @@ function Regenerator.initFile()

for _, util in utils do
print("Exporting", util.config.name)
initFile:appendLine(util.config.name, "=", `require("src/{util.dir}"),`)
initFile:appendLine(util.config.name, "=", `require("lib/{util.dir}"),`)
end

fs.writeFile(path(PATH_SRC, "init.luau"), initFile:unIndent():appendLine("}"):build())
fs.writeFile(path(PATH_LIB, "init.luau"), initFile:unIndent():appendLine("}"):build())
end

function Regenerator.mkdocsConfig()
Expand Down Expand Up @@ -212,11 +212,11 @@ function Regenerator.regenerate()
:append(codeDocumentation:build())

pages[util] = content:build()
fs.writeFile(path(PATH_SRC, util.dir, "README.md"), content:build())
fs.writeFile(path(PATH_LIB, util.dir, "README.md"), content:build())

local srcFilepath = path(PATH_SRC, util.dir, "init.luau")
local srcFile = fs.readFile(srcFilepath)
fs.writeFile(srcFilepath, (srcFile:gsub("%-%-%[=%[.*]=]", function()
local libFilepath = path(PATH_LIB, util.dir, "init.luau")
local libFile = fs.readFile(libFilepath)
fs.writeFile(libFilepath, (libFile:gsub("%-%-%[=%[.*]=]", function()
return docComment:append("]=]"):unIndent():build()
end)))
end
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.8.8/",
"src": "src"
"lib": "lib"
}
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<h1>
<img
src="./assets/logo-light.svg#gh-light-mode-only"
lib="./assets/logo-light.svg#gh-light-mode-only"
height="100px"
alt="Flower bouquet with Fusion accent colors"
/><img
src="./assets/logo-dark.svg#gh-dark-mode-only"
lib="./assets/logo-dark.svg#gh-dark-mode-only"
height="100px"
alt="Flower bouquet with Fusion accent colors"/>
</h1>
Expand Down Expand Up @@ -49,11 +49,11 @@ specific Fusion utilities.
- [X] `useTasks`
- [X] `useThread`
- [X] `useAsync` (analogous to [Fusion Eventuals])
- [X] `useEffect` (somewhat broken, see `src/use-effect/init.luau`)
- [X] `useEffect` (somewhat broken, see `lib/use-effect/init.luau`)

### Misc

- [ ] Darklua setup & build system
- [X] Darklua setup & build system
- [ ] TypeScript support (waiting for `@rbxts/fusion@0.3`, may defer to using `@znotfireman/fusion`)
- [ ] Memoize utility for some utilities e.g. `usePx` really should be cached

Expand Down
4 changes: 2 additions & 2 deletions default.project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pretty-fusion-utils",
"tree": {
"$path": "src"
"$path": "lib"
}
}
}
19 changes: 19 additions & 0 deletions lib/init.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- This file was @generated and is not intended for manual editing.
-- Run `lune run regen` to generate a fresh init file.

return table.freeze {
useAsync = require("lib/use-async"),
useCamera = require("lib/use-camera"),
useCoroutine = require("lib/use-coroutine"),
useEffect = require("lib/use-effect"),
useEventListener = require("lib/use-event-listener"),
useInterval = require("lib/use-interval"),
useMouse = require("lib/use-mouse"),
usePrevious = require("lib/use-previous"),
usePx = require("lib/use-px"),
useTagged = require("lib/use-tagged"),
useTasks = require("lib/use-tasks"),
useThread = require("lib/use-thread"),
useTimer = require("lib/use-timer"),
useViewport = require("lib/use-viewport"),
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/use-async/init.luau → lib/use-async/init.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local Types = require("src/types")
local castToState = require("src/utils/cast-to-state")
local lockValue = require("src/utils/lock-value")
local Types = require("lib/types")
local castToState = require("lib/utils/cast-to-state")
local lockValue = require("lib/utils/lock-value")

type Become = <T>(value: T) -> T

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/use-camera/init.luau → lib/use-camera/init.luau
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local Workspace = game:GetService("Workspace")

local Types = require("src/types")
local lockValue = require("src/utils/lock-value")
local useEventListener = require("src/use-event-listener")
local Types = require("lib/types")
local lockValue = require("lib/utils/lock-value")
local useEventListener = require("lib/use-event-listener")

local onCameraChanged = Workspace:GetPropertyChangedSignal("CurrentCamera")

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Types = require("src/types")
local Types = require("lib/types")

--[=[
Spawns a new coroutine that is closed once the scope is cleaned up.
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/use-effect/init.luau → lib/use-effect/init.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Types = require("src/types")
local Types = require("lib/types")

local function doNothing() end

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Types = require("src/types")
local Types = require("lib/types")

type EventLike =
RBXScriptConnection
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit db853f9

Please sign in to comment.