WatchCustomApp .
(appName []string, liveUpdate bool)
| 148 | |
| 149 | // WatchCustomApp . |
| 150 | func WatchCustomApp(appName []string, liveUpdate bool) { |
| 151 | if !isValidForWatching() { |
| 152 | os.Exit(1) |
| 153 | } |
| 154 | |
| 155 | if liveUpdate { |
| 156 | startDebugger() |
| 157 | } |
| 158 | |
| 159 | var appNameList []string |
| 160 | if len(appName) > 0 { |
| 161 | appNameList = appName |
| 162 | } else { |
| 163 | appNameList = featureSection.Key("custom_apps").Strings("|") |
| 164 | } |
| 165 | |
| 166 | threadCount := 0 |
| 167 | for _, v := range appNameList { |
| 168 | appPath, err := utils.GetCustomAppPath(v) |
| 169 | if err != nil { |
| 170 | utils.PrintError(`Custom app "` + v + `" not found`) |
| 171 | continue |
| 172 | } |
| 173 | |
| 174 | var appFileList []string |
| 175 | jsFilePath := filepath.Join(appPath, "index.js") |
| 176 | if _, err := os.Stat(jsFilePath); err != nil { |
| 177 | utils.PrintError(`Custom app "` + v + `" does not contain index.js`) |
| 178 | continue |
| 179 | } |
| 180 | appFileList = append(appFileList, jsFilePath) |
| 181 | cssFilePath := filepath.Join(appPath, "style.css") |
| 182 | if _, err := os.Stat(cssFilePath); err == nil { |
| 183 | appFileList = append(appFileList, cssFilePath) |
| 184 | } |
| 185 | |
| 186 | manifestPath := filepath.Join(appPath, "manifest.json") |
| 187 | manifestFileContent, err := os.ReadFile(manifestPath) |
| 188 | if err == nil { |
| 189 | var manifestJson utils.AppManifest |
| 190 | if err = json.Unmarshal(manifestFileContent, &manifestJson); err == nil { |
| 191 | for _, subfile := range manifestJson.Files { |
| 192 | subfilePath := filepath.Join(appPath, subfile) |
| 193 | appFileList = append(appFileList, subfilePath) |
| 194 | } |
| 195 | for _, subfile := range manifestJson.ExtensionFiles { |
| 196 | subfilePath := filepath.Join(appPath, subfile) |
| 197 | appFileList = append(appFileList, subfilePath) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | } |
| 202 | |
| 203 | threadCount += 1 |
| 204 | var appName = v |
| 205 | go utils.Watch(appFileList, func(filePath string, err error) { |
| 206 | if err != nil { |
| 207 | utils.PrintError(err.Error()) |
no test coverage detected