diff --git a/fs.go b/fs.go index 5ed7376..54f38e8 100644 --- a/fs.go +++ b/fs.go @@ -3,6 +3,7 @@ package cblib import ( "bytes" "encoding/json" + "errors" "fmt" "io/ioutil" "os" @@ -809,6 +810,13 @@ func writeService(name string, data map[string]interface{}) error { return err } + sourceMap, ok := data["source_map"].(string) + if ok && sourceMap != "" { + if err := ioutil.WriteFile(mySvcDir+"/"+name+".js.map", []byte(data["source_map"].(string)), 0666); err != nil { + return err + } + } + omitServiceFields(data) return writeEntity(mySvcDir, name, data) } @@ -935,6 +943,12 @@ func writeLibrary(name string, data map[string]interface{}) error { if err := ioutil.WriteFile(myLibDir+"/"+name+".js", []byte(data["code"].(string)), 0666); err != nil { return err } + sourceMap, ok := data["source_map"].(string) + if ok && sourceMap != "" { + if err := ioutil.WriteFile(myLibDir+"/"+name+".js.map", []byte(data["source_map"].(string)), 0666); err != nil { + return err + } + } return writeEntity(myLibDir, name, whitelistLibrary(data)) } @@ -1154,6 +1168,18 @@ func getCodeStuff(dirName string) ([]map[string]interface{}, error) { fmt.Printf("ioutil.ReadFile failed: %s\n", err) return nil, err } + _, err = os.Stat(myRootDir + "/" + realDirName + ".js.map") + if err == nil { + bytsMap, err := ioutil.ReadFile(myRootDir + "/" + realDirName + ".js.map") + if err != nil { + fmt.Printf("ioutil.ReadFile for source map failed: %s\n", err) + return nil, err + } + myObj["source_map"] = string(bytsMap) + } else if !errors.Is(err, os.ErrNotExist) { + fmt.Printf("os.Stat for source map failed: %s\n", err) + return nil, err + } myObj["code"] = string(byts) delete(myObj, "source") rval = append(rval, myObj) @@ -1428,6 +1454,7 @@ func getCollection(name string) (map[string]interface{}, error) { func getService(name string) (map[string]interface{}, error) { svcRootDir := svcDir + "/" + name codeFile := name + ".js" + sourceMapFile := name + ".js.map" schemaFile := name + ".json" svcMap, err := getObject(svcRootDir, schemaFile) @@ -1438,6 +1465,17 @@ func getService(name string) (map[string]interface{}, error) { if err != nil { return nil, err } + _, err = os.Stat(svcRootDir + "/" + sourceMapFile) + if err == nil { + bytsMap, err := ioutil.ReadFile(svcRootDir + "/" + sourceMapFile) + if err != nil { + return nil, err + } + svcMap["source_map"] = string(bytsMap) + } else if !errors.Is(err, os.ErrNotExist) { + fmt.Printf("os.Stat for source map failed: %s\n", err) + return nil, err + } svcMap["code"] = string(byts) return svcMap, nil } @@ -1445,6 +1483,7 @@ func getService(name string) (map[string]interface{}, error) { func getLibrary(name string) (map[string]interface{}, error) { libRootDir := libDir + "/" + name codeFile := name + ".js" + sourceMapFile := name + ".js.map" schemaFile := name + ".json" libMap, err := getObject(libRootDir, schemaFile) @@ -1455,6 +1494,17 @@ func getLibrary(name string) (map[string]interface{}, error) { if err != nil { return nil, err } + _, err = os.Stat(libRootDir + "/" + sourceMapFile) + if err == nil { + bytsMap, err := ioutil.ReadFile(libRootDir + "/" + sourceMapFile) + if err != nil { + return nil, err + } + libMap["source_map"] = string(bytsMap) + } else if !errors.Is(err, os.ErrNotExist) { + fmt.Printf("os.Stat for source map failed: %s\n", err) + return nil, err + } libMap["code"] = string(byts) return libMap, nil } diff --git a/push.go b/push.go index da1b650..0d2ac32 100644 --- a/push.go +++ b/push.go @@ -168,7 +168,7 @@ func pushSystemZip(systemInfo *types.System_meta, client *cb.DevClient, options } if dryRun.HasErrors() { - return fmt.Errorf(dryRun.String()) + return fmt.Errorf("%s", dryRun.String()) } if !dryRun.HasChanges() { diff --git a/syspath/code_path.go b/syspath/code_path.go index d96c38c..08aacd6 100644 --- a/syspath/code_path.go +++ b/syspath/code_path.go @@ -6,8 +6,8 @@ import ( ) const ( - servicePathRegexStr = `^code\/services\/([^\/]+)\/([^\/]+)\.(?:js|json)$` - libraryPathRegexStr = `^code\/libraries\/([^\/]+)\/([^\/]+)\.(?:js|json)$` + servicePathRegexStr = `^code\/services\/([^\/]+)\/([^\/]+)\.(?:js|json|js\.map)$` + libraryPathRegexStr = `^code\/libraries\/([^\/]+)\/([^\/]+)\.(?:js|json|js\.map)$` ) var ( diff --git a/syspath/syspath.go b/syspath/syspath.go index e034711..2662c51 100644 --- a/syspath/syspath.go +++ b/syspath/syspath.go @@ -27,6 +27,10 @@ func IsJsonFile(path string) bool { return getFileExtension(path) == "json" } +func IsJsMapFile(path string) bool { + return getFileExtension(path) == "map" +} + func GetFileName(path string) string { _, fileName := pth.Split(path) return fileName