-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwafflemaker
51 lines (49 loc) · 1.52 KB
/
wafflemaker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env luajit
require 'torch'
local cmd = torch.CmdLine()
cmd:text()
cmd:text('wafflemaker Command Line')
cmd:text()
cmd:text('Options:')
cmd:option('--create', '', 'project name')
cmd:option('--serve', false, 'run a simple http server')
cmd:option('--port', 8080, 'Host Port on which to recieve requests')
cmd:text()
local opt = cmd:parse(arg or {})
local project = opt.create
if opt.serve then
local cwd = paths.cwd()
local cwdl = #cwd
local app = require('waffle')
local nroutes = 0
for file in paths.gwalk(cwd) do
local route = file:sub(cwdl + 1)
print(route)
app.get(route, function(req, res) res.sendFile(file) end)
nroutes = nroutes + 1
if route == '/index.html' then
route = '/'
print(route)
app.get(route, function(req, res) res.sendFile(file) end)
nroutes = nroutes + 1
end
end
app{
debug = true,
cachesize = nroutes
}.listen{
port = tostring(opt.port)
}
elseif #project > 0 then
os.execute('mkdir ' .. project)
os.execute('mkdir ' .. project .. '/public')
os.execute('mkdir ' .. project .. '/public/js')
os.execute('mkdir ' .. project .. '/public/css')
os.execute('mkdir ' .. project .. '/public/imgs')
os.execute('mkdir ' .. project .. '/templates')
os.execute('mkdir ' .. project .. '/api')
os.execute('mkdir ' .. project .. '/lib')
os.execute('mkdir ' .. project .. '/bin')
local s = [[local app = require 'waffle']]
os.execute('echo "' .. s .. '" > ' .. project .. '/init.lua')
end