Watch .
(liveUpdate bool)
| 20 | |
| 21 | // Watch . |
| 22 | func Watch(liveUpdate bool) { |
| 23 | if !isValidForWatching() { |
| 24 | os.Exit(1) |
| 25 | } |
| 26 | |
| 27 | InitSetting() |
| 28 | |
| 29 | if liveUpdate { |
| 30 | startDebugger() |
| 31 | } |
| 32 | |
| 33 | if len(themeFolder) == 0 { |
| 34 | utils.PrintError(`Config "current_theme" is blank. No theme asset to watch`) |
| 35 | os.Exit(1) |
| 36 | } |
| 37 | |
| 38 | colorPath := filepath.Join(themeFolder, "color.ini") |
| 39 | cssPath := filepath.Join(themeFolder, "user.css") |
| 40 | |
| 41 | fileList := []string{} |
| 42 | if replaceColors { |
| 43 | fileList = append(fileList, colorPath) |
| 44 | } |
| 45 | |
| 46 | if injectCSS { |
| 47 | fileList = append(fileList, cssPath) |
| 48 | } |
| 49 | |
| 50 | if injectJS { |
| 51 | jsPath := filepath.Join(themeFolder, "theme.js") |
| 52 | pathArr := []string{jsPath} |
| 53 | |
| 54 | if _, err := os.Stat(jsPath); err == nil { |
| 55 | go utils.Watch(pathArr, func(_ string, err error) { |
| 56 | if err != nil { |
| 57 | utils.Fatal(err) |
| 58 | } |
| 59 | |
| 60 | enqueueWatchJob(func() { |
| 61 | refreshThemeJS() |
| 62 | if autoReloadFunc != nil { |
| 63 | autoReloadFunc() |
| 64 | } |
| 65 | }) |
| 66 | }, nil) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | if overwriteAssets { |
| 71 | assetPath := filepath.Join(themeFolder, "assets") |
| 72 | |
| 73 | if _, err := os.Stat(assetPath); err == nil { |
| 74 | go utils.WatchRecursive(assetPath, func(_ string, err error) { |
| 75 | if err != nil { |
| 76 | utils.Fatal(err) |
| 77 | } |
| 78 | |
| 79 | enqueueWatchJob(func() { |
no test coverage detected