(staticDir, pathToReplace, newPath, subpath string)
| 139 | } |
| 140 | |
| 141 | func updateManifestAndCSSFiles(staticDir, pathToReplace, newPath, subpath string) error { |
| 142 | if pathToReplace == newPath { |
| 143 | mlog.Debug("No need to rewrite unmodified manifest.json and *.css files", mlog.String("from_subpath", pathToReplace), mlog.String("to_subpath", newPath)) |
| 144 | return nil |
| 145 | } |
| 146 | |
| 147 | mlog.Debug("Rewriting manifest.json and *.css files", mlog.String("from_subpath", pathToReplace), mlog.String("to_subpath", newPath)) |
| 148 | // Rewrite the manifest.json and *.css references to `/static/*` (or a previously rewritten subpath). |
| 149 | err := filepath.Walk(staticDir, func(walkPath string, info os.FileInfo, err error) error { |
| 150 | if filepath.Base(walkPath) == "manifest.json" || filepath.Ext(walkPath) == ".css" { |
| 151 | old, err := os.ReadFile(walkPath) |
| 152 | if err != nil { |
| 153 | return errors.Wrapf(err, "failed to open %s", walkPath) |
| 154 | } |
| 155 | n := strings.Replace(string(old), pathToReplace, newPath, -1) |
| 156 | if err = os.WriteFile(walkPath, []byte(n), 0); err != nil { |
| 157 | return errors.Wrapf(err, "failed to update %s with subpath %s", walkPath, subpath) |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return nil |
| 162 | }) |
| 163 | if err != nil { |
| 164 | return errors.Wrapf(err, "error walking %s", staticDir) |
| 165 | } |
| 166 | |
| 167 | return nil |
| 168 | } |
| 169 | |
| 170 | // UpdateAssetsSubpath rewrites assets in the /client directory to assume the application is hosted |
| 171 | // at the given subpath instead of at the root. No changes are written unless necessary. |
no test coverage detected
searching dependent graphs…