Cleanup readme, add APIs to it

This commit is contained in:
Filip Tibell 2023-01-19 14:57:39 -05:00
parent ebcbde8825
commit c21dfb997e
No known key found for this signature in database
3 changed files with 89 additions and 19 deletions

105
README.md
View file

@ -1,3 +1,5 @@
<!-- markdownlint-disable MD033 -->
# Lune 🌙 # Lune 🌙
[![CI](https://github.com/filiptibell/lune/actions/workflows/ci.yaml/badge.svg)](https://github.com/filiptibell/lune/actions/workflows/ci.yaml) [![CI](https://github.com/filiptibell/lune/actions/workflows/ci.yaml/badge.svg)](https://github.com/filiptibell/lune/actions/workflows/ci.yaml)
@ -11,9 +13,74 @@ A [Luau](https://luau-lang.org) script runner
[Full example & walkthrough](.lune/hello_lune.luau) [Full example & walkthrough](.lune/hello_lune.luau)
<!-- markdownlint-disable MD033 --> ## ⚙️ Installation
### Using [Aftman](https://github.com/lpghatguy/aftman)
The preferred way of installing Lune.
This will add `lune` to an `aftman.toml` file in the current directory, or create one if it does not exist.
```sh
$ aftman add filiptibell/lune
```
### From [GitHub Releases](https://github.com/filiptibell/lune/releases)
You can also download pre-built binaries for most systems directly from the linked GitHub Releases page.
## ✏️ Writing Lune Scripts
Check out the examples of how to write a script in the [.lune](.lune) folder !
<details> <details>
<summary>Example translation from Bash to Luau</summary> <summary><b>🔎 Full list of APIs</b></summary>
### **`fs`** - Filesystem
```lua
type fs = {
readFile: (path: string) -> string,
readDir: (path: string) -> { string },
writeFile: (path: string, contents: string) -> (),
writeDir: (path: string) -> (),
removeFile: (path: string) -> (),
removeDir: (path: string) -> (),
isFile: (path: string) -> boolean,
isDir: (path: string) -> boolean,
}
```
### **`json`** - JSON
```lua
type json = {
encode: (value: any, pretty: boolean?) -> string,
decode: (encoded: string) -> any,
}
```
### **`process`** - Current process & child processes
```lua
type process = {
getEnvVars: () -> { string },
getEnvVar: (key: string) -> string?,
setEnvVar: (key: string, value: string) -> (),
exit: (code: number?) -> (),
spawn: (program: string, params: { string }?) -> {
ok: boolean,
code: number,
stdout: string,
stderr: string,
},
}
```
</details>
<details>
<summary><b>🔀 Example translation from Bash to Luau</b></summary>
**_Before:_** **_Before:_**
@ -48,29 +115,30 @@ end
</details> </details>
## ⚙️ Installation <details>
<summary><b>🧑‍💻 Configuring VSCode for Lune</b></summary>
### Using [Aftman](https://github.com/lpghatguy/aftman) Lune puts developer experience first, and as such provides type definitions and configurations for several tools out of the box.
The preferred way of installing Lune. <details>
<summary>Luau LSP</summary>
This will add `lune` to an `aftman.toml` file in the 1. Use `lune --download-luau-types` to download Luau types (`luneTypes.d.luau`) to the current directory
current directory, or create one if it does not exist. 2. Set your definition files setting to include `luneTypes.d.luau`, an example can be found in the [.vscode](.vscode) folder in this repository
```sh </details>
$ aftman add filiptibell/lune
```
### From [GitHub Releases](https://github.com/filiptibell/lune/releases) <details>
<summary>Selene</summary>
You can also download pre-built binaries for most 1. Use `lune --download-selene-types` to download Selene types (`lune.yml`) to the current directory
systems directly from the linked GitHub Releases page. 2. Use either `std = "roblox-lune"` or `std = "luau+lune"` in your `selene.toml` configuration file
## ✏️ Writing Lune Scripts </details>
First things first, check out the examples of how to write a script in the [.lune](.lune) folder! <br> **_NOTE:_** _It is highly recommended to add any type definition files to your `.gitignore` and to only download them using these commands, since this guarantees that you have type definitions compatible with your installed version of Lune._
Lune has many useful built-in globals and APIs to use to interact with your system, and can do things
such as read/write files, run external programs, serialize & deserialize json, and much more. </details>
## 🏃 Running Lune Scripts ## 🏃 Running Lune Scripts
@ -86,5 +154,4 @@ This will look for the script `script_name` in a few locations:
- The folder `lune` in the current directory, if it exists - The folder `lune` in the current directory, if it exists
- The folder `.lune` in the current directory, if it exists - The folder `.lune` in the current directory, if it exists
If you don't want Lune to look in sub-directories you can provide a full If you don't want Lune to look in sub-directories you can provide a full file path with the file extension included, instead of only the file name.
file path with the file extension included, instead of only the file name.

View file

@ -1,3 +1,4 @@
# Lune v0.0.1
--- ---
globals: globals:
# FS (filesystem) # FS (filesystem)

View file

@ -1,3 +1,5 @@
-- Lune v0.0.1
declare fs: { declare fs: {
readFile: (path: string) -> string, readFile: (path: string) -> string,
readDir: (path: string) -> { string }, readDir: (path: string) -> { string },