Skip to content

Commit

Permalink
Upgrades (#21)
Browse files Browse the repository at this point in the history
Summary of changes:
* Attempted to spruce up the ModuleLoader class' types for consumers
* Bumped Foreman tool versions
* Imported Lune scripts from flipbook repo
* Setup string requires
* Updated GitHub workflows to work with Lune scripts
* Renamed all .lua files to .luau
* Require statements are auto-sorted with stylua
* Tests are run with Jest 3

Closes #20
  • Loading branch information
vocksel authored Sep 8, 2024
1 parent c23cefe commit 47c0f7b
Show file tree
Hide file tree
Showing 59 changed files with 1,445 additions and 974 deletions.
25 changes: 25 additions & 0 deletions .darklua.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"process": [
{
"rule": "convert_require",
"current": {
"name": "path",
"sources": {
"@pkg": "./Packages",
"@root": "./src"
}
},
"target": {
"name": "roblox",
"rojo_sourcemap": "./sourcemap-darklua.json",
"indexing_style": "property"
}
},
"compute_expression",
"remove_unused_if_branch",
"remove_unused_while",
"filter_after_early_return",
"remove_nil_declaration",
"remove_empty_do"
]
}
6 changes: 0 additions & 6 deletions .github/workflows/.luaurc

This file was deleted.

48 changes: 22 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,40 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Lint
run: |
selene generate-roblox-std
selene src/
- name: Install packages
run: lune run wally-install

- name: Format
run: stylua --check src/
- name: Lint
run: lune run lint

- name: Install dependencies
run: wally install
- name: Get model file name
run: |
name=$(jq -r .name default.project.json)
sha=${GITHUB_SHA:0:7}
echo "MODEL_FILE=$name-$sha.rbxm" >> $GITHUB_ENV
- name: Build
run: rojo build -o build.rbxm
run: lune run build -- --target prod --output ${{ env.MODEL_FILE }}

- uses: actions/upload-artifact@v3
with:
name: ${{ env.MODEL_FILE }}
path: ${{ env.MODEL_FILE }}

analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: Roblox/setup-foreman@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: wally install

- name: Download global Roblox types
shell: bash
run: curl -s -O https://raw.githubusercontent.com/JohnnyMorganz/luau-lsp/master/scripts/globalTypes.d.lua

- name: Generate sourcemap for LSP
shell: bash
run: rojo sourcemap dev.project.json -o sourcemap.json
- name: Setup Lune typedefs
run: lune setup

- name: Ignore packages in analysis
shell: bash
run: mv .github/workflows/.luaurc Packages
- name: Install packages
run: lune run wally-install

- name: Analyze
shell: bash
run: luau-lsp analyze --sourcemap=sourcemap.json --defs=globalTypes.d.lua --defs=testez.d.lua --formatter=gnu src/
- name: Run Luau analysis
run: lune run analyze
27 changes: 14 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
name: Release

on:
pull_request:
release:
types: [published]

env:
OUTPUT_NAME: "ModuleLoader.rbxm"

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install toolchain
uses: Roblox/setup-foreman@v1
- uses: Roblox/setup-foreman@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Remove spec files
run: rm -rf **/*.spec.lua
- name: Get model file name
run: |
name=$(jq -r .name default.project.json)
echo "MODEL_FILE=$name.rbxm" >> $GITHUB_ENV
- name: Install packages
run: lune run wally-install

- name: Build
run: rojo build -o ${{ env.OUTPUT_NAME }}
run: lune run build -- --target prod --output ${{ env.MODEL_FILE }}

- name: Add model file to release
uses: softprops/action-gh-release@v1
- uses: softprops/action-gh-release@v1
if: ${{ github.event.release }}
with:
files: ${{ env.OUTPUT_NAME }}
files: ${{ env.MODEL_FILE }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Rojo
/*.rbxl*
/*.rbxm*
sourcemap.json

# Luau
dist/
sourcemap*.json
globalTypes.d.luau

# Selene
/roblox.toml
Expand Down
6 changes: 6 additions & 0 deletions .luaurc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"aliases": {
"pkg": "./Packages",
"root": "./src"
}
}
29 changes: 29 additions & 0 deletions .lune/analyze.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local project = require("../project")
local run = require("./lib/run")

local globalDefsPath = "globalTypes.d.luau"

run("curl", {
"-s",
"-o",
globalDefsPath,
"-O",
"https://raw.githubusercontent.com/JohnnyMorganz/luau-lsp/master/scripts/globalTypes.d.lua",
})

run("rojo", {
"sourcemap",
project.ROJO_ANALYSIS_PROJECT,
"-o",
project.SOURCEMAP_PATH,
})

run("luau-lsp", {
"analyze",
`--sourcemap={project.SOURCEMAP_PATH}`,
`--defs={globalDefsPath}`,
"--settings=./.vscode/settings.json",
"--ignore=**/_Index/**",
project.SOURCE_PATH,
project.LUNE_SCRIPTS_PATH,
})
31 changes: 31 additions & 0 deletions .lune/build.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local compile = require("./lib/compile")
local parseArgs = require("./lib/parseArgs")
local process = require("@lune/process")
local project = require("../project")
local run = require("./lib/run")
local watch = require("./lib/watcher/watch")

local args = parseArgs(process.args)

local target = if args.target then args.target else "prod"

local function build()
run("rm", { "-rf", project.BUILD_PATH })
compile(target)

if target == "prod" then
run("rm", { "-rf", `{project.BUILD_PATH}/**/*.spec.luau` })
end
end

build()

if args.watch then
watch({
filePatterns = {
"src/.*%.luau",
"example/.*%.luau",
},
onChanged = build,
})
end
33 changes: 33 additions & 0 deletions .lune/lib/compile.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local fs = require("@lune/fs")

local project = require("../../project")
local run = require("./run")

type Target = "prod" | "dev"

local function compile(target: Target)
fs.writeDir(project.BUILD_PATH)

run("rojo", {
"sourcemap",
project.ROJO_BUILD_PROJECT,
"-o",
project.DARKLUA_SOURCEMAP_PATH,
})

run("darklua", {
"process",
project.SOURCE_PATH,
project.BUILD_PATH,
})

if target == "dev" then
run("darklua", {
"process",
"example",
`{project.BUILD_PATH}/Example`,
})
end
end

return compile
23 changes: 23 additions & 0 deletions .lune/lib/findClientSettings.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local run = require("./run")

local function findClientSettings(os: string)
if os == "macos" then
return "/Applications/RobloxStudio.app/Contents/MacOS/ClientSettings"
elseif os == "windows" then
local robloxStudioPath = run("find", {
"$LOCALAPPDATA/Roblox/Versions",
"-name",
"RobloxStudioBeta.exe",
})

local dir = run("dirname", {
robloxStudioPath,
})

return `{dir}/ClientSettings`
else
return nil
end
end

return findClientSettings
25 changes: 25 additions & 0 deletions .lune/lib/findFilesByPattern.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
local fs = require("@lune/fs")

local function findFilesByPattern(rootPath: string, pattern: string)
local matches = {}

local function search(path: string)
for _, file in fs.readDir(path) do
local filePath = `{path}/{file}`

if fs.isDir(filePath) then
search(filePath)
else
if filePath:match(pattern) then
table.insert(matches, filePath)
end
end
end
end

search(rootPath)

return matches
end

return findFilesByPattern
49 changes: 49 additions & 0 deletions .lune/lib/parseArgs.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local FLAG_PATTERN = "%-%-(%w+)"
local FLAG_ALL_IN_ONE_PATTERN = `{FLAG_PATTERN}=(%w+)`

local function parseArgs(args: { string }): { [string]: string | boolean | number }
local parsedArgs: { [string]: string } = {}
local skipNextToken = false

for index, token in args do
-- When `--foo bar` is used, these are both individual tokens that we
-- process at the same time. In those cases, we need to skip the next
-- token (`bar`) since it has already been picked up as a flag value
if skipNextToken then
skipNextToken = false
continue
end

-- handle `--foo=bar` pattern
local flagName, flagValue = token:match(FLAG_ALL_IN_ONE_PATTERN)
if flagName and flagValue then
parsedArgs[flagName] = flagValue
continue
end

flagName = token:match(FLAG_PATTERN)
if flagName then
local nextToken = args[index + 1]

if nextToken then
-- When processing `--foo` in `--foo --bar` treat it like a boolean
if nextToken:match(FLAG_PATTERN) then
flagValue = true
else
flagValue = nextToken
skipNextToken = true
end
else
flagValue = true
end

parsedArgs[flagName] = flagValue
else
error(`something went wrong: {token}`)
end
end

return parsedArgs
end

return parseArgs
11 changes: 11 additions & 0 deletions .lune/lib/rmrf.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local fs = require("@lune/fs")

local function rmrf(path: string)
if fs.isDir(path) then
fs.removeDir(path)
else
fs.removeFile(path)
end
end

return rmrf
Loading

0 comments on commit 47c0f7b

Please sign in to comment.