MCPcopy
hub / github.com/spicetify/cli / pushExtensions

Function pushExtensions

src/cmd/apply.go:232–280  ·  view source on GitHub ↗
(destExt string, list ...string)

Source from the content-addressed store, hash-verified

230}
231
232func pushExtensions(destExt string, list ...string) {
233 var err error
234 var dest string
235 if len(destExt) > 0 {
236 dest = filepath.Join(appDestPath, "xpui", "extensions", destExt)
237 } else {
238 dest = filepath.Join(appDestPath, "xpui", "extensions")
239 }
240
241 for _, v := range list {
242 var extName, extPath string
243
244 if filepath.IsAbs(v) {
245 extName = filepath.Base(v)
246 extPath = v
247 } else {
248 extName = v
249 if !strings.Contains(extName, ".js") && !strings.Contains(extName, ".mjs") {
250 extName += ".js"
251 }
252 extPath, err = utils.GetExtensionPath(extName)
253 if err != nil {
254 utils.PrintError(`Extension "` + extName + `" not found`)
255 continue
256 }
257 }
258
259 if err = utils.CopyFile(extPath, dest); err != nil {
260 utils.PrintError(err.Error())
261 continue
262 }
263
264 if strings.HasSuffix(extName, ".mjs") {
265 utils.ModifyFile(filepath.Join(dest, extName), func(content string) string {
266 lines := strings.Split(content, "\n")
267 for i := 0; i < len(lines); i++ {
268 mapping := utils.FindSymbol("", lines[i], []string{
269 `//\s*spicetify_map\{(.+?)\}\{(.+?)\}`,
270 })
271 if len(mapping) > 0 {
272 lines[i+1] = strings.Replace(lines[i+1], mapping[0], mapping[1], 1)
273 }
274 }
275
276 return strings.Join(lines, "\n")
277 })
278 }
279 }
280}
281
282func RefreshApps(list ...string) {
283 spinner, _ := utils.Spinner.Start("Refreshing custom apps")

Callers 3

RefreshExtensionsFunction · 0.85
RefreshAppsFunction · 0.85
WatchExtensionsFunction · 0.85

Calls 5

GetExtensionPathFunction · 0.92
PrintErrorFunction · 0.92
CopyFileFunction · 0.92
ModifyFileFunction · 0.92
FindSymbolFunction · 0.92

Tested by

no test coverage detected