Skip to content

Commit d1fc089

Browse files
committed
feat(apply): add ability to call multiple functions to one file
1 parent 2acdc4a commit d1fc089

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/apply/apply.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,35 @@ type Flag struct {
2626

2727
// AdditionalOptions .
2828
func AdditionalOptions(appsFolderPath string, flags Flag) {
29-
filesToModified := map[string]func(path string, flags Flag){
30-
filepath.Join(appsFolderPath, "xpui", "index.html"): htmlMod,
31-
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertCustomApp,
32-
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertExpFeatures,
33-
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertSidebarConfig,
34-
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertHomeConfig,
35-
filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js"): insertExpFeatures,
36-
filepath.Join(appsFolderPath, "xpui", "home-v2.js"): insertHomeConfig,
37-
filepath.Join(appsFolderPath, "xpui", "xpui-desktop-modals.js"): insertVersionInfo,
29+
filesToModified := map[string][]func(path string, flags Flag){
30+
filepath.Join(appsFolderPath, "xpui", "index.html"): {
31+
htmlMod,
32+
},
33+
filepath.Join(appsFolderPath, "xpui", "xpui.js"): {
34+
insertCustomApp,
35+
insertExpFeatures,
36+
insertSidebarConfig,
37+
insertHomeConfig,
38+
},
39+
filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js"): {
40+
insertExpFeatures,
41+
},
42+
filepath.Join(appsFolderPath, "xpui", "home-v2.js"): {
43+
insertHomeConfig,
44+
},
45+
filepath.Join(appsFolderPath, "xpui", "xpui-desktop-modals.js"): {
46+
insertVersionInfo,
47+
},
3848
}
3949

40-
for file, call := range filesToModified {
50+
for file, calls := range filesToModified {
4151
if _, err := os.Stat(file); os.IsNotExist(err) {
4252
continue
4353
}
4454

45-
call(file, flags)
55+
for _, call := range calls {
56+
call(file, flags)
57+
}
4658
}
4759

4860
if flags.SidebarConfig {
@@ -397,6 +409,7 @@ func insertExpFeatures(jsPath string, flags Flag) {
397409
&content,
398410
`(([\w$.]+\.fromJSON)\(\w+\)+;)(return ?[\w{}().,]+[\w$]+\.Provider,)(\{value:\{localConfiguration)`,
399411
func(submatches ...string) string {
412+
fmt.Println(submatches)
400413
return fmt.Sprintf("%sSpicetify.createInternalMap=%s;%sSpicetify.RemoteConfigResolver=%s", submatches[1], submatches[2], submatches[3], submatches[4])
401414
})
402415
return content

0 commit comments

Comments
 (0)