diff --git a/.github/workflows/studio-docs.yaml b/.github/workflows/studio-docs.yaml new file mode 100644 index 0000000..7ed9d09 --- /dev/null +++ b/.github/workflows/studio-docs.yaml @@ -0,0 +1,22 @@ +on: + push: + +jobs: + studio-docs: + name: Build Studio Docs + runs-on: ubuntu-latest + steps: + - name: Checkout Project + uses: actions/checkout@v4 + + - name: Install Rokit + uses: CompeyDev/setup-rokit@v0.1.2 + + - name: Build Studio Docs + run: zune run scripts/build_studio_docs + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: studio_docs + path: studio_docs.rbxm diff --git a/.gitignore b/.gitignore index 5445cd0..c7f09a7 100755 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ genhtml.perl rokit.toml package-lock.json mirror.luau +studio_docs/ diff --git a/README.md b/README.md index 12a8e2b..d175d2b 100755 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ This repository includes a few subfolders that can help you get started with jec - examples: These are larger programs that showcase real use cases and can help you understand how everything fits together. + +If you wish to view the documentation inside Roblox Studio, you can find an importable model file [here](https://nightly.link/Mark-Marks/jecs/workflows/studio-docs/docs%2Fstudio/studio_docs.rbxm). ### Benchmarks diff --git a/rokit.toml b/rokit.toml index 907eb03..6df2554 100755 --- a/rokit.toml +++ b/rokit.toml @@ -2,3 +2,4 @@ wally = "upliftgames/wally@0.3.2" rojo = "rojo-rbx/rojo@7.4.4" luau = "luau-lang/luau@0.701" +zune = "scythe-technology/zune@0.5.1" diff --git a/scripts/build_studio_docs.luau b/scripts/build_studio_docs.luau new file mode 100644 index 0000000..6a420d1 --- /dev/null +++ b/scripts/build_studio_docs.luau @@ -0,0 +1,79 @@ +--!strict +-- Copies all docs related files into a dist folder where all `@jecs` aliases inside them are replaced with their relative require path to jecs source code +-- This script may break if there's ever a Luau module (`init.luau`) in the mix, as it just counts how deep the file is and prepends `../` to `jecs` that many times +local fs = zune.fs +local process = zune.process + +local text_files = { "README.md", "LICENSE" } +local extension_whitelist = { ".luau", ".json" } +local dirs = { "examples", "how_to", "modules" } +local dist = "studio_docs" + +local function traverse(dir: string, fn: (path: string, depth: number, metadata: Metadata) -> (), depth: number?) + depth = depth or 0 + for _, entry in fs.entries(dir) do + local path = `{dir}/{entry.name}` + local metadata = fs.metadata(path) + fn(path, depth, metadata) + if entry.kind == "directory" then + traverse(path, fn, depth + 1) + end + end +end + +local function relativify(depth: number): string + return string.rep("../", depth) .. "jecs" +end + +if fs.stat(dist).kind ~= "none" then + fs.deleteDir(dist, true) +end +fs.makeDir(dist) +fs.copy("src/jecs.luau", `{dist}/jecs.luau`) + +for _, file in text_files do + local source = fs.readFile(file) + local scriptified_source = `--[\[\n{source}\n]\]` + local stem = fs.path.stem(file) + fs.writeFile(`{dist}/{stem}.server.luau`, scriptified_source) + fs.writeFile( + `{dist}/{stem}.meta.json`, + -- stylua: ignore + [[ +{ + "properties": { + "Disabled": true + } +} + ]] + ) +end + +for _, dir in dirs do + fs.copy(dir, `{dist}/{dir}`) +end + +traverse(dist, function(path, depth, metadata) + if metadata.kind ~= "file" then + return + end + + -- whitelist instead of blacklist + local extension = fs.path.extension(path) + if not table.find(extension_whitelist, extension) then + fs.deleteFile(path) + return + end + + local source = fs.readFile(path) + local relative_jecs_path = relativify(depth) + source = string.gsub(source, "@jecs", relative_jecs_path) + fs.writeFile(path, source) +end) + +process.run( + "rojo", + { "build", "studio_docs.project.json", "-o", "studio_docs.rbxm" }, + -- Luau + { stdout = "inherit", stderr = "inherit" } :: any +) diff --git a/studio_docs.project.json b/studio_docs.project.json new file mode 100644 index 0000000..d5c68d4 --- /dev/null +++ b/studio_docs.project.json @@ -0,0 +1,6 @@ +{ + "name": "jecs_studio_docs", + "tree": { + "$path": "studio_docs" + } +}