diff --git a/src/tim.nim b/src/tim.nim index 503d084..302506e 100755 --- a/src/tim.nim +++ b/src/tim.nim @@ -381,7 +381,8 @@ when defined napibuild: return %*(x) elif not isMainModule: - # Expose Tim Engine API for Nim development (as a Nimble librayr) + # Expose Tim Engine API for Nim development + # as a Nimble library import std/enumutils import tim/engine/ast @@ -389,7 +390,7 @@ elif not isMainModule: export meta except TimEngine export localModule, SourceCode, Arg, NodeType - proc initModule(modules: NimNode): NimNode = + proc initLocalModule(modules: NimNode): NimNode = result = newStmtList() var functions: seq[string] modules.expectKind nnkArgList @@ -456,17 +457,43 @@ elif not isMainModule: ) macro initModule*(x: varargs[untyped]): untyped = - initModule(x) + initLocalModule(x) else: # Build Tim Engine as a standalone CLI application - discard # todo -# import pkg/kapsis -# import ./tim/app/[runCommand] - -# App: -# about: -# "Tim Engine CLI application" -# commands: -# --- "Main Commands" -# $ run \ No newline at end of file + import std/[os, strutils] + import pkg/[kapsis, flatty] + import pkg/kapsis/[runtime, cli] + import tim/engine/ast + # todo move commands + proc cCommand(v: Values) = + ## Transpiles a `.timl` file to a target source + let fpath = v.get("timl").getPath.path + let p = parseSnippet(fpath, readFile(getCurrentDir() / fpath)) + if likely(not p.hasErrors): + let c = newCompiler(parser.getAst(p), false) + display(c.getHtml().strip) + + proc astCommand(v: Values) = + ## Build binary AST from a `timl` file + let fpath = v.get("timl").getPath.path + let opath = normalizedPath(getCurrentDir() / v.get("output").getFilename) + let p = parseSnippet(fpath, readFile(getCurrentDir() / fpath)) + if likely(not p.hasErrors): + writeFile(opath, flatty.toFlatty(parser.getAst(p))) + + proc reprCommand(v: Values) = + ## Read a binary AST to target source + let fpath = v.get("ast").getPath.path + let c = newCompiler(flatty.fromFlatty(readFile(fpath), Ast), false) + if likely(not c.hasErrors): + display(c.getHtml().strip) + + commands: + -- "Main Commands" + c path(`timl`): + ## Transpile `.timl` file to a target source + ast path(`timl`), filename(`output`): + ## Build binary AST for a `timl` file + repr path(`ast`): + ## Read from a binary AST to target source \ No newline at end of file diff --git a/src/tim.nims b/src/tim.nims index 5054523..7be0861 100755 --- a/src/tim.nims +++ b/src/tim.nims @@ -5,4 +5,14 @@ when defined napibuild: --define:napiOrWasm --noMain:on - --passC:"-I/usr/include/node -I/usr/local/include/node" \ No newline at end of file + --passC:"-I/usr/include/node -I/usr/local/include/node" + +when isMainModule: + when defined release: + --opt:speed + --define:useMalloc + --define:danger + --checks:off + --passC:"-flto" + --passL:"-flto" + --define:nimAllocPagesViaMalloc \ No newline at end of file diff --git a/tim.nimble b/tim.nimble index 2ec0b95..7cf4716 100755 --- a/tim.nimble +++ b/tim.nimble @@ -1,14 +1,14 @@ # Package version = "0.1.0" -author = "George Lemon" +author = "OpenPeeps" description = "A super fast template engine for cool kids!" license = "MIT" srcDir = "src" skipDirs = @["example", "editors"] -# installExt = @["nim"] -# bin = @["tim"] - +installExt = @["nim"] +bin = @["tim"] +binDir = "bin" # Dependencies @@ -23,6 +23,7 @@ requires "checksums" requires "flatty#head" requires "malebolgia" requires "nyml" +requires "kapsis" # requires "bro" task node, "Build a NODE addon": @@ -41,3 +42,9 @@ task example, "example httpbeast + tim": task bench, "run some benchmarks": exec "nim c --threads:on -d:danger --opt:speed --mm:arc -o:./bin/bench example/benchmark.nim" + +task dev, "build a dev cli": + exec "nimble build" + +task prod, "build a prod cli": + exec "nimble build -d:release"