Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Aug 7, 2020
1 parent 00fc92a commit a4800b6
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# logue
Command tools for Prologue in Nim.

## Usage
Use `logue init yourprojectname` to initialize your project.
15 changes: 15 additions & 0 deletions logue.nimble
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions src/logue.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import cligen

import loguepkg/create


proc main*() =
dispatchMulti([init])

when isMainModule:
main()
42 changes: 42 additions & 0 deletions src/loguepkg/create.nim
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions src/loguepkg/tml/.env
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions src/loguepkg/tml/app.nim
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions src/loguepkg/tml/urls.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import prologue

import ./views


let urlPatterns* = @[
# strip latter
pattern("/", hello)
]
5 changes: 5 additions & 0 deletions src/loguepkg/tml/views.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import prologue


proc hello*(ctx: Context) {.async.} =
resp "<h1>Hello, Prologue!</h1>"

0 comments on commit a4800b6

Please sign in to comment.