From 6edba3d3db89a476a6ab9bc0016753aae44de16d Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Mon, 8 Jul 2024 16:17:28 +0530 Subject: [PATCH] Initial, commit --- .luaurc | 11 +++++++++++ .lune/fmt.luau | 6 ++++++ .lune/lint.luau | 7 +++++++ .lune/typecheck.luau | 13 +++++++++++++ .lune/util/command.luau | 14 ++++++++++++++ .nvim.lua | 22 ++++++++++++++++++++++ .vscode/settings.json | 6 ++++++ LICENSE.md | 22 ++++++++++++++++++++++ README.md | 19 +++++++++++++++++++ aftman.toml | 5 +++++ lune.yml | 6 ++++++ selene.toml | 2 ++ src/init.luau | 8 ++++++++ stylua.toml | 11 +++++++++++ 14 files changed, 152 insertions(+) create mode 100644 .luaurc create mode 100755 .lune/fmt.luau create mode 100755 .lune/lint.luau create mode 100755 .lune/typecheck.luau create mode 100644 .lune/util/command.luau create mode 100644 .nvim.lua create mode 100644 .vscode/settings.json create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 aftman.toml create mode 100644 lune.yml create mode 100644 selene.toml create mode 100644 src/init.luau create mode 100644 stylua.toml diff --git a/.luaurc b/.luaurc new file mode 100644 index 0000000..3e8f1bc --- /dev/null +++ b/.luaurc @@ -0,0 +1,11 @@ +{ + "languageMode": "strict", + "lint": { + "*": true, + "FunctionUnused": false + }, + "lintErrors": true, + "globals": [ + "warn" + ] +} diff --git a/.lune/fmt.luau b/.lune/fmt.luau new file mode 100755 index 0000000..bb6e460 --- /dev/null +++ b/.lune/fmt.luau @@ -0,0 +1,6 @@ +--> Formats source code using stylua + +local command = require("util/command") +local process = require("@lune/process") + +command.run("stylua", "--verbose", process.args[1] or "src/") diff --git a/.lune/lint.luau b/.lune/lint.luau new file mode 100755 index 0000000..d68824c --- /dev/null +++ b/.lune/lint.luau @@ -0,0 +1,7 @@ +--> Lints source code using selene + +local command = require("util/command") +local process = require("@lune/process") + +local args = table.clone(process.args) +command.run("selene", table.remove(args, 1) or "src/", table.unpack(args)) diff --git a/.lune/typecheck.luau b/.lune/typecheck.luau new file mode 100755 index 0000000..1df9a5f --- /dev/null +++ b/.lune/typecheck.luau @@ -0,0 +1,13 @@ +--> Typechecks source code using luau-lsp + +local command = require("util/command") +local process = require("@lune/process") + +local args = table.clone(process.args) +command.run( + "luau-lsp", + "analyze", + "--settings=.vscode/settings.json", + table.remove(args, 1) or "src/", + table.unpack(args) +) diff --git a/.lune/util/command.luau b/.lune/util/command.luau new file mode 100644 index 0000000..5b9c36f --- /dev/null +++ b/.lune/util/command.luau @@ -0,0 +1,14 @@ +local process = require("@lune/process") + +return { + run = function(cmd: string, ...: string) + local child = process.spawn(cmd, table.pack(...), { + stdio = "forward", + shell = true, + }) + + if not child.ok then + process.exit(child.code) + end + end, +} diff --git a/.nvim.lua b/.nvim.lua new file mode 100644 index 0000000..91939df --- /dev/null +++ b/.nvim.lua @@ -0,0 +1,22 @@ +require("luau-lsp").config({ + server = { + settings = { + ["luau-lsp"] = { + require = { + mode = "relativeToFile", + directoryAliases = { + ["@lune"] = "~/.lune/.typedefs/0.8.6/", + }, + }, + completion = { + imports = { + enabled = true, + }, + }, + }, + }, + }, + platform = { + type = "standard", + }, +}) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1e34534 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "luau-lsp.require.mode": "relativeToFile", + "luau-lsp.require.directoryAliases": { + "@lune/": "~/.lune/.typedefs/0.8.6/" + } +} \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..bf9aac9 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2024 CompeyDev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..d6dae27 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# lune-luau-template + +This is a template for initializing a non-library [Luau](https://luau-lang.org) project with [Lune](https://lune-org.github.io/docs). + +## What is included in this template? + +- A barebones structure for an executable hello world Lune script (src/) +- A barebones structure for a library (lib/) -- TODO +- Configuration files for various tooling: + - aftman for toolchain management (aftman.toml) + - stylua for code formatting (stylua.toml, lune.yml) + - selene for linting (selene.toml) + - luau-lsp for code completion (.vscode/settings.json, .nvim.lua) +- Utility lune scripts (.lune/) + - Code-formatting + - Linting + - Typechecking +- Unit-testing setup (tests/) -- TODO +- GitHub Actions CI configuration to lints and tests (.github) -- TODO diff --git a/aftman.toml b/aftman.toml new file mode 100644 index 0000000..957dcd5 --- /dev/null +++ b/aftman.toml @@ -0,0 +1,5 @@ +[tools] +lune = "lune-org/lune@0.8.6" +selene = "kampfkarren/selene@0.27.1" +stylua = "JohnnyMorganz/stylua@0.20.0" +luau-lsp = "JohnnyMorganz/luau-lsp@1.31.0" diff --git a/lune.yml b/lune.yml new file mode 100644 index 0000000..0a2142a --- /dev/null +++ b/lune.yml @@ -0,0 +1,6 @@ +--- +base: luau +globals: + warn: + args: + - type: ... diff --git a/selene.toml b/selene.toml new file mode 100644 index 0000000..26c73d9 --- /dev/null +++ b/selene.toml @@ -0,0 +1,2 @@ +std = "lune" + diff --git a/src/init.luau b/src/init.luau new file mode 100644 index 0000000..56f6a5c --- /dev/null +++ b/src/init.luau @@ -0,0 +1,8 @@ +local process = require("@lune/process") + +function main(_args: { string }): number? + print("Hello, world!") + return 0 +end + +return process.exit(main(process.args)) diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..8743ff6 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,11 @@ +line_endings = "Unix" +quote_style = "AutoPreferDouble" +indent_type = "Spaces" +call_parentheses = "Always" + +indent_width = 4 +column_width = 80 + +[sort_requires] +enabled = true +