From 71f5d8bf849c1d48358e151fa2a8d3f8ac0f789d Mon Sep 17 00:00:00 2001 From: Marin Minnerly Date: Sat, 7 Sep 2024 11:17:52 -0700 Subject: [PATCH] Fix Lune script type errors --- .lune/build.luau | 1 + .lune/lib/findClientSettings.luau | 2 +- .lune/lib/parseArgs.luau | 13 ++++++------- .lune/lib/setFlags.luau | 6 ++++-- .lune/lib/watcher/watch.luau | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.lune/build.luau b/.lune/build.luau index 32cba50..6251a99 100644 --- a/.lune/build.luau +++ b/.lune/build.luau @@ -8,6 +8,7 @@ local watch = require("./lib/watcher/watch") local args = parseArgs(process.args) local target = if args.target then args.target else "prod" +assert(target == "dev" or target == "prod", `bad value for target (must be one of "dev" or "prod", got "{target}")`) local function build() run("rm", { "-rf", project.BUILD_PATH }) diff --git a/.lune/lib/findClientSettings.luau b/.lune/lib/findClientSettings.luau index ebc36bb..52b13ad 100644 --- a/.lune/lib/findClientSettings.luau +++ b/.lune/lib/findClientSettings.luau @@ -1,6 +1,6 @@ local run = require("./run") -local function findClientSettings(os: string) +local function findClientSettings(os: string): string? if os == "macos" then return "/Applications/RobloxStudio.app/Contents/MacOS/ClientSettings" elseif os == "windows" then diff --git a/.lune/lib/parseArgs.luau b/.lune/lib/parseArgs.luau index 97359ac..a506f99 100644 --- a/.lune/lib/parseArgs.luau +++ b/.lune/lib/parseArgs.luau @@ -1,8 +1,9 @@ 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 function parseArgs(args: { string }) + local parsedArgs: { [string]: string | boolean | number } = {} + local skipNextToken = false for index, token in args do @@ -28,16 +29,14 @@ local function parseArgs(args: { string }): { [string]: string | boolean | numbe if nextToken then -- When processing `--foo` in `--foo --bar` treat it like a boolean if nextToken:match(FLAG_PATTERN) then - flagValue = true + parsedArgs[flagName] = true else - flagValue = nextToken + parsedArgs[flagName] = nextToken skipNextToken = true end else - flagValue = true + parsedArgs[flagName] = true end - - parsedArgs[flagName] = flagValue else error(`something went wrong: {token}`) end diff --git a/.lune/lib/setFlags.luau b/.lune/lib/setFlags.luau index 3942fa7..646d964 100644 --- a/.lune/lib/setFlags.luau +++ b/.lune/lib/setFlags.luau @@ -3,8 +3,10 @@ local run = require("./run") local function setFlags(os: string) local clientSettings = findClientSettings(os) - run("mkdir", { "-p", clientSettings }) - run("cp", { "-R", "tests/ClientAppSettings.json", clientSettings }) + if clientSettings then + run("mkdir", { "-p", clientSettings }) + run("cp", { "-R", "tests/ClientAppSettings.json", clientSettings }) + end end return setFlags diff --git a/.lune/lib/watcher/watch.luau b/.lune/lib/watcher/watch.luau index 6e7dcab..96ceb5f 100644 --- a/.lune/lib/watcher/watch.luau +++ b/.lune/lib/watcher/watch.luau @@ -16,7 +16,7 @@ type Options = { } local function watch(options: Options) - local prevWatchedFileMetadata: { [string]: string } = {} + local prevWatchedFileMetadata: { [string]: fs.Metadata } = {} local watchedFiles = getWatchedFiles(options.filePatterns) local prevWatchedFiles