/
cmd.go
74 lines (64 loc) · 1.24 KB
/
cmd.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package jadecmd
import (
"log"
"os"
"path/filepath"
"github.com/Joker/jade"
)
func reset() {
dict = make(map[string]string)
lib_name = ""
outdir = ""
basedir = ""
pkg_name = "views"
stdlib = false
stdbuf = false
writer = false
inline = false
format = false
ns_files = make(map[string]bool)
}
type CompileConfig struct {
OutDir string
BaseDir string
PkgName string
Stdlib bool
Stdbuf bool
Writer bool
Inline bool
Format bool
}
func CompilePaths(jadePaths []string, config CompileConfig) {
reset()
outdir = config.OutDir
basedir = config.BaseDir
pkg_name = config.PkgName
stdlib = config.Stdlib
stdbuf = config.Stdbuf
writer = config.Writer
inline = config.Inline
format = config.Format
jade.Config(golang)
if _, err := os.Stat(outdir); os.IsNotExist(err) {
os.MkdirAll(outdir, 0755)
}
outdir, _ = filepath.Abs(outdir)
if _, err := os.Stat(basedir); !os.IsNotExist(err) && basedir != "./" {
os.Chdir(basedir)
}
for _, jadePath := range jadePaths {
stat, err := os.Stat(jadePath)
if err != nil {
log.Fatalln(err)
}
absPath, _ := filepath.Abs(jadePath)
if stat.IsDir() {
genDir(absPath, outdir, pkg_name)
} else {
genFile(absPath, outdir, pkg_name)
}
if !stdlib {
makeJfile(stdbuf)
}
}
}