-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
119 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"prologue": { | ||
"address": "", | ||
"port": 8080, | ||
"debug": true, | ||
"reusePort": true, | ||
"appName": "", | ||
"secretKey": "Set by yourself", | ||
"bufSize": 40960 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"prologue": { | ||
"address": "", | ||
"port": 8080, | ||
"debug": true, | ||
"reusePort": true, | ||
"appName": "", | ||
"secretKey": "Set by yourself", | ||
"bufSize": 40960 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"prologue": { | ||
"address": "", | ||
"port": 8080, | ||
"debug": false, | ||
"reusePort": true, | ||
"appName": "", | ||
"secretKey": "Set by yourself", | ||
"bufSize": 40960 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import prologue | ||
|
||
import ./urls | ||
|
||
|
||
var app = newAppQueryEnv() | ||
# Be careful with the routes. | ||
app.addRoute(urls.urlPatterns, "") | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import prologue | ||
|
||
import ./views | ||
|
||
|
||
let urlPatterns* = @[ | ||
pattern("/", hello) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,75 @@ | ||
import os, strformat | ||
import tml / [app, urls, views] | ||
import std / [os, strformat, json] | ||
import tml / [app, urls, views, appconf] | ||
|
||
|
||
proc getEnvContent(appName: string): string = | ||
let | ||
defaultConfig = %* {"prologue": { | ||
"address": "", | ||
"port": 8080, | ||
"debug": true, | ||
"reusePort": true, | ||
"appName": "", | ||
"secretKey": "Set by yourself", | ||
"bufSize": 40960 | ||
} | ||
} | ||
|
||
defaultDebugConfig = %* {"prologue": { | ||
"address": "", | ||
"port": 8080, | ||
"debug": true, | ||
"reusePort": true, | ||
"appName": "", | ||
"secretKey": "Set by yourself", | ||
"bufSize": 40960 | ||
} | ||
} | ||
|
||
defaultProductionConfig = %* {"prologue": { | ||
"address": "", | ||
"port": 8080, | ||
"debug": false, | ||
"reusePort": true, | ||
"appName": "", | ||
"secretKey": "Set by yourself", | ||
"bufSize": 40960 | ||
} | ||
} | ||
|
||
|
||
func 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. | ||
# If you want to release you programs, make sure set debug=false. | ||
debug=true | ||
port=8080 | ||
appName={appName} | ||
secretKey=Pr435ol67ogue | ||
""" | ||
|
||
|
||
proc initProject(projName: string) = | ||
proc initProject(projName: string, useConfig: bool) = | ||
createDir(projName) | ||
let | ||
appFile = projName / "app.nim" | ||
urlsFile = projName / "urls.nim" | ||
viewsFile = projName / "views.nim" | ||
envFile = projName / ".env" | ||
writeFile(projName / "urls.nim", urlsStr) | ||
writeFile(projName / "views.nim", viewsStr) | ||
|
||
# let path = currentSourcePath().splitPath.head | ||
if not useConfig: | ||
writeFile(projName / "app.nim", appStr) | ||
writeFile(projName / ".env", getEnvContent(projName)) | ||
else: | ||
writeFile(projName / "app.nim", appConfStr) | ||
createDir(projName / ".config") | ||
writeFile(projName / ".config" / "config.json", pretty defaultConfig) | ||
writeFile(projName / ".config" / "config.debug.json", pretty defaultDebugConfig) | ||
writeFile(projName / ".config" / "config.production.json", pretty defaultProductionConfig) | ||
|
||
writeFile(appFile, appStr) | ||
writeFile(urlsFile, urlsStr) | ||
writeFile(viewsFile, viewsStr) | ||
writeFile(envFile, getEnvContent(projName)) | ||
|
||
proc init*(name: seq[string]) = | ||
proc init*(name: seq[string], useConfig = false) = | ||
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: | ||
initProject(projName) | ||
initProject(projName, useConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const appConfStr* = """ | ||
import prologue | ||
import ./urls | ||
var app = newAppQueryEnv() | ||
# Be careful with the routes. | ||
app.addRoute(urls.urlPatterns, "") | ||
app.run() | ||
""" |