aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.go4
-rw-r--r--compiled.go5
-rw-r--r--interactive.go7
3 files changed, 6 insertions, 10 deletions
diff --git a/common.go b/common.go
index 56bffd1..d8e2d28 100644
--- a/common.go
+++ b/common.go
@@ -84,7 +84,6 @@ func parse(dirPath string, elements map[string][]byte, exts []string, overwrite
84} 84}
85 85
86func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, saveAs string, exts []string, recursive bool) { 86func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, saveAs string, exts []string, recursive bool) {
87 wait.Add(1)
88 defer wait.Done() 87 defer wait.Done()
89 88
90 if strings.HasPrefix(dirPath, outputDir) { 89 if strings.HasPrefix(dirPath, outputDir) {
@@ -96,6 +95,7 @@ func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, s
96 if recursive { 95 if recursive {
97 dirs, _ := fcmd.Ls(dirPath) 96 dirs, _ := fcmd.Ls(dirPath)
98 for _, dir := range dirs { 97 for _, dir := range dirs {
98 wait.Add(1)
99 go compile(path.Join(dirPath, dir), elements, sourceDir, outputDir, saveAs, exts, recursive) 99 go compile(path.Join(dirPath, dir), elements, sourceDir, outputDir, saveAs, exts, recursive)
100 } 100 }
101 } 101 }
@@ -111,7 +111,6 @@ func compile(dirPath string, elements map[string][]byte, sourceDir, outputDir, s
111} 111}
112 112
113func copyFiles(dirPath, sourceDir, outputDir string, exts []string, recursive bool) { 113func copyFiles(dirPath, sourceDir, outputDir string, exts []string, recursive bool) {
114 wait.Add(1)
115 defer wait.Done() 114 defer wait.Done()
116 115
117 if strings.HasPrefix(dirPath, outputDir) { 116 if strings.HasPrefix(dirPath, outputDir) {
@@ -130,6 +129,7 @@ func copyFiles(dirPath, sourceDir, outputDir string, exts []string, recursive bo
130 129
131 if recursive { 130 if recursive {
132 for _, dir := range dirs { 131 for _, dir := range dirs {
132 wait.Add(1)
133 go copyFiles(path.Join(dirPath, dir), sourceDir, outputDir, exts, recursive) 133 go copyFiles(path.Join(dirPath, dir), sourceDir, outputDir, exts, recursive)
134 } 134 }
135 } 135 }
diff --git a/compiled.go b/compiled.go
index 1cd391e..e7b7d0b 100644
--- a/compiled.go
+++ b/compiled.go
@@ -22,7 +22,6 @@ package main
22import ( 22import (
23 "fmt" 23 "fmt"
24 "os" 24 "os"
25 "time"
26) 25)
27 26
28func compiled(sourceDir, outputDir string, exts []string, saveAs string) { 27func compiled(sourceDir, outputDir string, exts []string, saveAs string) {
@@ -34,12 +33,10 @@ func compiled(sourceDir, outputDir string, exts []string, saveAs string) {
34 } 33 }
35 34
36 // compile everything 35 // compile everything
36 wait.Add(2)
37 go compile(sourceDir, make(map[string][]byte), sourceDir, outputDir, saveAs, exts, true) 37 go compile(sourceDir, make(map[string][]byte), sourceDir, outputDir, saveAs, exts, true)
38 go copyFiles(sourceDir, sourceDir, outputDir, exts, true) 38 go copyFiles(sourceDir, sourceDir, outputDir, exts, true)
39 39
40 // sleep some milliseconds to prevent early exit
41 time.Sleep(time.Millisecond * 100)
42
43 // wait until all tasks are completed 40 // wait until all tasks are completed
44 wait.Wait() 41 wait.Wait()
45 fmt.Println("Compilation done.") 42 fmt.Println("Compilation done.")
diff --git a/interactive.go b/interactive.go
index 1c9ca71..1baa4cc 100644
--- a/interactive.go
+++ b/interactive.go
@@ -26,7 +26,6 @@ import (
26 "os" 26 "os"
27 "path" 27 "path"
28 "strings" 28 "strings"
29 "time"
30) 29)
31 30
32func watch(dirPath string, watcher *fsnotify.Watcher) *fsnotify.Watcher { 31func watch(dirPath string, watcher *fsnotify.Watcher) *fsnotify.Watcher {
@@ -107,21 +106,21 @@ func interactive(sourceDir, outputDir string, exts []string, saveAs string) {
107 if fcmd.IsDir(ev.Name) { 106 if fcmd.IsDir(ev.Name) {
108 elements := parseParents(ev.Name, sourceDir, exts) 107 elements := parseParents(ev.Name, sourceDir, exts)
109 dirPath := path.Join(sourceDir, strings.TrimPrefix(ev.Name, sourceDir)) 108 dirPath := path.Join(sourceDir, strings.TrimPrefix(ev.Name, sourceDir))
109 wait.Add(2)
110 go compile(dirPath, elements, sourceDir, outputDir, saveAs, exts, true) 110 go compile(dirPath, elements, sourceDir, outputDir, saveAs, exts, true)
111 go copyFiles(dirPath, sourceDir, outputDir, exts, true) 111 go copyFiles(dirPath, sourceDir, outputDir, exts, true)
112 } else { 112 } else {
113 dirPath := path.Join(sourceDir, strings.TrimPrefix(dir, sourceDir)) 113 dirPath := path.Join(sourceDir, strings.TrimPrefix(dir, sourceDir))
114 if isParsable(path.Ext(ev.Name), exts) { 114 if isParsable(path.Ext(ev.Name), exts) {
115 elements := parseParents(dir, sourceDir, exts) 115 elements := parseParents(dir, sourceDir, exts)
116 wait.Add(1)
116 go compile(dirPath, elements, sourceDir, outputDir, saveAs, exts, true) 117 go compile(dirPath, elements, sourceDir, outputDir, saveAs, exts, true)
117 } 118 }
119 wait.Add(1)
118 go copyFiles(dirPath, sourceDir, outputDir, exts, false) 120 go copyFiles(dirPath, sourceDir, outputDir, exts, false)
119 } 121 }
120 } 122 }
121 123
122 // sleep some milliseconds to prevent early exit
123 time.Sleep(time.Millisecond * 100)
124
125 // wait until all tasks are completed 124 // wait until all tasks are completed
126 wait.Wait() 125 wait.Wait()
127 126