diff --git a/.gitignore b/.gitignore index 0e2d3df..ef93989 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ .wax-tmp # Compiled outputs -terracotta.luau \ No newline at end of file +dist/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..172e058 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "clap"] + path = clap + url = https://github.com/0x5eal/clap.luau.git diff --git a/.lune/make.luau b/.lune/make.luau index 89a134a..56f10e1 100644 --- a/.lune/make.luau +++ b/.lune/make.luau @@ -51,6 +51,10 @@ local BoxifyOutput = function(msg: string) end end +if not fs.isDir("dist/") then + fs.writeDir("dist/") +end + print(`{WAX_PREFIX_FORMAT("info", "[codegen]")} Generating darklua config file at darklua.config.json`) fs.writeFile( ".darklua.json5", @@ -85,10 +89,15 @@ local loader = task.spawn(function() end) task.spawn(function() - local child = spawn( - "lune", - { "wax", "bundle", "input=default.project.json", "verbose=true", "minify=true", "output=terracotta.luau" } - ) + local child = spawn("lune", { + "wax", + "bundle", + "input=default.project.json", + "verbose=true", + "minify=true", + "ci-mode=true", + "output=dist/terracotta.luau", + }) task.cancel(loader) print("\b \n") diff --git a/.vscode/settings.json b/.vscode/settings.json index a0f94ce..40b0e56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "luau-lsp.require.mode": "relativeToFile", "luau-lsp.require.directoryAliases": { - "@lune/": "~/.lune/.typedefs/0.7.7/" + "@lune/": "~/.lune/.typedefs/0.7.8/" }, "editor.formatOnSave": true } \ No newline at end of file diff --git a/clap b/clap new file mode 160000 index 0000000..be0dd88 --- /dev/null +++ b/clap @@ -0,0 +1 @@ +Subproject commit be0dd886262ad7df5e06edc11daa38a19e98a1dd diff --git a/cmd/init.luau b/cmd/init.luau new file mode 100644 index 0000000..f37bdcd --- /dev/null +++ b/cmd/init.luau @@ -0,0 +1,10 @@ +--> Placeholder file! + +local clap = require("../clap/src/clap") + +local Command = clap.Command +local Opt = clap.Opt + +Command.new("terracotta", true) + :afterHelp("For more help, refer to the documentation.") + :author("Seal Gang (0x5eal), Erica Marigold (DevComp)") diff --git a/darklua/bundler.luau b/darklua/bundler.luau index 97d5f6b..5300843 100644 --- a/darklua/bundler.luau +++ b/darklua/bundler.luau @@ -5,9 +5,12 @@ local FsUtils = require("../utils/fs") local Codegen = require("codegen") local Bundler = {} -type BundlerExtended = - typeof(Bundler.Prototype) - & { darkluaPath: string?, darklua: Darklua.Darklua?, config: { contents: string, path: string? } } +export type BundlerExtended = typeof(Bundler.Prototype) & { + darkluaPath: string?, + darklua: Darklua.Darklua?, + config: { contents: string, path: string? }, +} +export type DarkluaRules = Codegen.Rules Bundler.Prototype = {} Bundler.Interface = {} @@ -17,11 +20,11 @@ function Bundler.Prototype.Bundle( self: BundlerExtended, sourceKind: "code" | "path", sourceInner: string -): { error: string?, bundled: string? } +): { error: string?, processed: string? } self.darklua = Darklua.new(self.darkluaPath) if self.darklua:IsOk() then - return self.darklua:Process("code", sourceInner, self.config.path or (function() + return self.darklua:Process(sourceKind, sourceInner, self.config.path or (function() local _, path = FsUtils.MakeTemp() Fs.writeFile( path, diff --git a/darklua/init.luau b/darklua/init.luau new file mode 100644 index 0000000..ba5c474 --- /dev/null +++ b/darklua/init.luau @@ -0,0 +1,13 @@ +local Bundler = require("bundler") +local Minifier = require("minifier") + +export type Bundler = Bundler.BundlerExtended +export type Minifier = Minifier.MinfierExtended + +local Darklua = { + bundler = Bundler, + minifier = Minifier, + __cmd = require("cmd"), +} + +return Darklua diff --git a/darklua/minifier.luau b/darklua/minifier.luau index c52713a..03da5fd 100644 --- a/darklua/minifier.luau +++ b/darklua/minifier.luau @@ -1,7 +1,7 @@ local Darklua = require("cmd") local Minifier = {} -type MinfierExtended = typeof(Minifier.Prototype) & { darkluaPath: string?, darklua: Darklua.Darklua? } +export type MinfierExtended = typeof(Minifier.Prototype) & { darkluaPath: string?, darklua: Darklua.Darklua? } Minifier.Prototype = {} Minifier.Interface = {} diff --git a/default.project.json b/default.project.json index aaf4e9e..245459d 100644 --- a/default.project.json +++ b/default.project.json @@ -1,12 +1,12 @@ { - "name": "terracotta", - "tree": { - "$className": "Folder", - "terracotta": { - "$path": "src/" - }, - "darklua": { - "$path": "darklua/" - } + "name": "terracotta", + "tree": { + "$className": "Folder", + "terracotta": { + "$path": "src/" + }, + "darklua": { + "$path": "darklua/" } -} \ No newline at end of file + } +} diff --git a/sourcemap.json b/sourcemap.json index 9f2a036..ca6d7b3 100644 --- a/sourcemap.json +++ b/sourcemap.json @@ -1 +1,46 @@ -{"name":"terracotta","className":"Folder","filePaths":["default.project.json"],"children":[{"name":"darklua","className":"Folder","children":[{"name":"bundler","className":"ModuleScript","filePaths":["darklua/bundler.luau"]},{"name":"cmd","className":"ModuleScript","filePaths":["darklua/cmd.luau"]},{"name":"codegen","className":"ModuleScript","filePaths":["darklua/codegen.luau"]},{"name":"minifier","className":"ModuleScript","filePaths":["darklua/minifier.luau"]}]},{"name":"terracotta","className":"Folder"}]} \ No newline at end of file +{ + "name": "terracotta", + "className": "Folder", + "filePaths": ["default.project.json"], + "children": [ + { + "name": "darklua", + "className": "ModuleScript", + "filePaths": ["darklua/init.luau"], + "children": [ + { + "name": "bundler", + "className": "ModuleScript", + "filePaths": ["darklua/bundler.luau"] + }, + { + "name": "cmd", + "className": "ModuleScript", + "filePaths": ["darklua/cmd.luau"] + }, + { + "name": "codegen", + "className": "ModuleScript", + "filePaths": ["darklua/codegen.luau"] + }, + { + "name": "minifier", + "className": "ModuleScript", + "filePaths": ["darklua/minifier.luau"] + } + ] + }, + { + "name": "terracotta", + "className": "ModuleScript", + "filePaths": ["src/init.luau"], + "children": [ + { + "name": "terracotta", + "className": "ModuleScript", + "filePaths": ["src/terracotta.luau"] + } + ] + } + ] +} diff --git a/src/init.luau b/src/init.luau new file mode 100644 index 0000000..ca684af --- /dev/null +++ b/src/init.luau @@ -0,0 +1,19 @@ +local Fs = require("@lune/fs") + +local Terracotta = require("terracotta") + +Terracotta.Build({ + entryPoints = { "utils/fs.luau", "darklua/cmd.luau" }, + bundle = true, +}) + +-- OR -- + +local terracotta = Terracotta.new() + +local outputs = terracotta:Build({ + entryPoints = { "utils/fs.luau", "darklua/cmd.luau" }, + bundle = true, +}) + +Fs.writeFile("darklua.luau", outputs["darklua/cmd.luau"]) diff --git a/src/terracotta.luau b/src/terracotta.luau new file mode 100644 index 0000000..b497aad --- /dev/null +++ b/src/terracotta.luau @@ -0,0 +1,70 @@ +local Darklua = require("../darklua") +local Codegen = require("../darklua/codegen") + +local Terracotta = {} +Terracotta.Interface = {} +Terracotta.Prototype = {} + +type DarkluaRules = Codegen.Rules + +export type Terracotta = typeof(Terracotta) & { + bundler: Darklua.Bundler, + minifier: Darklua.Minifier, +} + +function Terracotta.Prototype.Build( + self: Terracotta?, + opts: { + entryPoints: { string }, + bundle: boolean?, + outFile: string?, + rules: { DarkluaRules }?, + } +) + local bundler: Darklua.Bundler + + if self ~= nil and self.bundler ~= nil then + bundler = self.bundler + else + bundler = Darklua.bundler.new(nil, { + generator = "dense", + sources = opts.entryPoints, + outFile = opts.outFile, + requireMode = (opts.bundle and "path") or nil, + rules = opts.rules or { + "remove_comments", + "rename_variables", + "remove_spaces", + }, + }) + end + + local builtOuts = {} + + for _, path in opts.entryPoints do + local out = bundler:Bundle("path", path) + + if out.error ~= nil then + error(out.error) + end + + builtOuts[path] = out.processed + end + + return builtOuts +end + +function Terracotta.Interface.new() + return setmetatable({ + minifier = nil, + bundler = nil, + }, { + __index = Terracotta.Prototype, + }) +end + +function Terracotta.Interface.Build(opts: { bundle: boolean?, entryPoints: { string }, outFile: string? }) + return Terracotta.Prototype.Build(nil, opts) +end + +return Terracotta.Interface