diff --git a/README.md b/README.md index a5efad1..f61af67 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # logue Command tools for Prologue in Nim. + +## Usage +Use `logue init yourprojectname` to initialize your project. diff --git a/logue.nimble b/logue.nimble new file mode 100644 index 0000000..6b4b50e --- /dev/null +++ b/logue.nimble @@ -0,0 +1,15 @@ +# Package + +version = "0.1.0" +author = "flywind" +description = "Command line tools for Prologue." +license = "Apache-2.0" +srcDir = "src" +bin = @["logue"] + + + +# Dependencies + +requires "nim >= 1.2.0" +requires "cligen >= 1.1.0" diff --git a/src/logue.nim b/src/logue.nim new file mode 100644 index 0000000..85bccf5 --- /dev/null +++ b/src/logue.nim @@ -0,0 +1,10 @@ +import cligen + +import loguepkg/create + + +proc main*() = + dispatchMulti([init]) + +when isMainModule: + main() diff --git a/src/loguepkg/create.nim b/src/loguepkg/create.nim new file mode 100644 index 0000000..e3147c8 --- /dev/null +++ b/src/loguepkg/create.nim @@ -0,0 +1,42 @@ +import os, strformat + + +proc getEnvContent(appName: string): string = + result = fmt"""# Don't commit this to source control. +# Eg. Make sure ".env" in your ".gitignore" file. +# If you want to release you programs, make sure debug=false. +debug=true +port=8080 +appName={appName} +staticDir=/static +secretKey=Pr435ol67ogue +""" + + +proc initProject(projName: string) = + createDir(projName) + let + appFile = projName / "app.nim" + urlsFile = projName / "urls.nim" + viewsFile = projName / "views.nim" + envFile = projName / ".env" + + let path = currentSourcePath().splitPath.head + + copyFile(path / "tml" / "app.nim", appFile) + copyFile(path / "tml" / "urls.nim", urlsFile) + copyFile(path / "tml" / "views.nim", viewsFile) + writeFile(envFile, getEnvContent(projName)) + + + +proc init*(name: seq[string]) = + if name.len == 0: + echo "Please give the name of your project!" + else: + let projName = name[0] + if dirExists(projName): + echo fmt"{projName} already exists!" + else: + createDir(projName) + initProject(projName) diff --git a/src/loguepkg/tml/.env b/src/loguepkg/tml/.env new file mode 100644 index 0000000..d83c354 --- /dev/null +++ b/src/loguepkg/tml/.env @@ -0,0 +1,9 @@ +# Don't commit this to source control. +# Eg. Make sure ".env" in your ".gitignore" file. +# If you want to release you programs, make sure debug=false. +debug=true +address=127.0.0.2 +port=8787 +appName=HelloWorld +staticDir=/static +secretKey=Pr435ol67ogue \ No newline at end of file diff --git a/src/loguepkg/tml/app.nim b/src/loguepkg/tml/app.nim new file mode 100644 index 0000000..9ebf8ea --- /dev/null +++ b/src/loguepkg/tml/app.nim @@ -0,0 +1,17 @@ +import prologue + +import ./urls + +let + env = loadPrologueEnv(".env") + settings = newSettings(appName = env.getOrDefault("appName", "Prologue"), + debug = env.getOrDefault("debug", true), + port = Port(env.getOrDefault("port", 8080)), + staticDirs = [env.get("staticDir")], + secretKey = env.getOrDefault("secretKey", "") + ) + + +var app = newApp(settings = settings) +app.addRoute(urls.urlPatterns, "/") +app.run() diff --git a/src/loguepkg/tml/urls.nim b/src/loguepkg/tml/urls.nim new file mode 100644 index 0000000..1cb6a08 --- /dev/null +++ b/src/loguepkg/tml/urls.nim @@ -0,0 +1,9 @@ +import prologue + +import ./views + + +let urlPatterns* = @[ + # strip latter + pattern("/", hello) +] diff --git a/src/loguepkg/tml/views.nim b/src/loguepkg/tml/views.nim new file mode 100644 index 0000000..d9cee4f --- /dev/null +++ b/src/loguepkg/tml/views.nim @@ -0,0 +1,5 @@ +import prologue + + +proc hello*(ctx: Context) {.async.} = + resp "