Add VERBOSE option to tools/build and generate.go

VERBOSE will be set by TRAVIS (but can also be set by user to diagnose slow
builds). Using an env var so that it automatically propagates to all the
sub-scripts and tools without having to pass it through tools/build explicitly.
This commit is contained in:
Eli Bendersky 2019-06-05 10:15:13 -07:00
parent 9027bb86cd
commit 5487e88919
3 changed files with 25 additions and 2 deletions

View File

@ -12,4 +12,7 @@ install:
- go get -u github.com/russross/blackfriday
script:
- 'tools/build'
- tools/build
env:
- VERBOSE=1

View File

@ -2,7 +2,16 @@
set -e
verbose() [[ -v VERBOSE ]]
verbose && echo "Running tests..."
tools/test
verbose && echo "Formatting code..."
tools/format
verbose && echo "Measuring line lengths..."
tools/measure
verbose && echo "Generating HTML..."
tools/generate

View File

@ -19,6 +19,10 @@ var cacheDir = "/tmp/gobyexample-cache"
var siteDir = "./public"
var pygmentizeBin = "./vendor/pygments/pygmentize"
func verbose() bool {
return len(os.Getenv("VERBOSE")) > 0
}
func check(err error) {
if err != nil {
panic(err)
@ -221,6 +225,7 @@ func parseAndRenderSegs(sourcePath string) ([]*Seg, string) {
}
func parseExamples() []*Example {
fmt.Println("Parsing examples")
exampleNames := readLines("examples.txt")
examples := make([]*Example, 0)
for _, exampleName := range exampleNames {
@ -261,6 +266,9 @@ func parseExamples() []*Example {
}
func renderIndex(examples []*Example) {
if verbose() {
fmt.Println("Rendering index")
}
indexTmpl := template.New("index")
_, err := indexTmpl.Parse(mustReadFile("templates/index.tmpl"))
check(err)
@ -274,7 +282,10 @@ func renderExamples(examples []*Example) {
exampleTmpl := template.New("example")
_, err := exampleTmpl.Parse(mustReadFile("templates/example.tmpl"))
check(err)
for _, example := range examples {
for i, example := range examples {
if verbose() {
fmt.Printf("Rendering %s [%d/%d]\n", example.Name, i, len(examples))
}
exampleF, err := os.Create(siteDir + "/" + example.ID)
check(err)
exampleTmpl.Execute(exampleF, example)