-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
146 lines (134 loc) · 4.3 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// THTML is a static website generator based on text/template package.
//
// Includes a development webserver to help creating HTML websites and components
// compiling the templates on the fight, allowing a edit-save-refresh development process.
//
// Usage:
// thtml [OPTIONS] [COMMAND]
//
// [COMMAND] can be the following:
//
// -build
// Build the assets from the [-public] directory to the [-output] directory by parsing the [-templates] directory.
//
// -run
// Run development webserver listening to [-listen] to build pages on-the-fly.
//
// [OPTIONS] are:
//
// -exts string
// Provides a comma separated filename extensions list to support when parsing templates. (default ".thtml,.html,.css,.js")
//
// -listen string
// Run the dev server listening on the provided host:port. (default ":5500")
//
// -minify
// Minify the build output. (default true)
//
// -output string
// Sets the path for the build output. (default "build")
//
// -public string
// Sets the path for the web root. (default "public")
//
// -templates string
// Sets the path for the template files. (default "templates")
//
//
//
// Getting started
//
// By running `thtml -run` on a directory, the tool will use the default options that assume the following directory structure:
//
// ./public
// ./templates
// ./build
//
// The `public` directory and all its sub-directories will contain the source files for the template website structure,
// including assets that have to be included during the static website compilation.
// It works as the "web root" directory of the development webserver and contains the desired final structure.
//
// The `templates` directory and all its sub-directories is where all the reusable templates have to be placed
// so they can be used from the pages in the `public` directory and from other templates.
//
// The `build` directory will be used to write the output of the static website compilation and then deploy it.
//
// Check the `_example` directory on the repository to see a simple layout: https://github.com/leonelquinteros/thtml/tree/master/_example
//
// After creating the website using the development webserver, it can be built running `thtml -build`
// and the content of the `build` directory can be deployed to any static web server on production.
//
//
//
// Template syntax
//
// THTML uses pure Go's text/template package to render the templates together.
// Check the package documentation for details about the syntax: https://golang.org/pkg/text/template/
//
//
package main
import (
"flag"
"fmt"
"os"
)
const version = "1.1.0"
// Configuration options
var (
// Actions
_version bool
_build bool
_run bool
_init bool
// Configuration
_publicPath string
_templatesPath string
_outputPath string
_exts string
_minify bool
_httpListen string
)
func init() {
// Parse config flags
flag.BoolVar(&_version, "version", false, "Prints version number.")
flag.BoolVar(&_build, "build", false, "Build the assets from the -public directory to the -output directory by parsing the -templates directory.")
flag.BoolVar(&_run, "run", false, "Run a dev web server serving the public directory.")
flag.BoolVar(&_init, "init", false, "Creates a new project structure into the current directory.")
flag.BoolVar(&_minify, "minify", true, "Minify the build output.")
flag.StringVar(&_publicPath, "public", "public", "Sets the path for the web root.")
flag.StringVar(&_templatesPath, "templates", "templates", "Sets the path for the template files.")
flag.StringVar(&_httpListen, "listen", "localhost:5500", "Run the dev server listening on the provided host:port.")
flag.StringVar(&_outputPath, "output", "build", "Sets the path for the build output.")
flag.StringVar(&_exts, "exts", ".html", "Provides a comma separated filename extensions list to support when parsing templates.")
}
func printVersion() {
fmt.Printf("thtml version %s \n", version)
}
func main() {
flag.Parse()
if !_run && !_build && !_init && !_version {
fmt.Println("")
fmt.Println("Run:")
fmt.Println(" ", os.Args[0], "-h")
fmt.Println("")
fmt.Println("To view help")
fmt.Println("")
return
}
// Print version
if _version {
printVersion()
}
// Init
if _init {
create()
}
// Build if requested
if _build {
build()
}
// Run
if _run {
runServer()
}
}