Skip to content

Commit

Permalink
feat(apply): add ability to call multiple functions to one file
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Sep 8, 2024
1 parent 2acdc4a commit d1fc089
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,35 @@ type Flag struct {

// AdditionalOptions .
func AdditionalOptions(appsFolderPath string, flags Flag) {
filesToModified := map[string]func(path string, flags Flag){
filepath.Join(appsFolderPath, "xpui", "index.html"): htmlMod,
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertCustomApp,
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertExpFeatures,
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertSidebarConfig,
filepath.Join(appsFolderPath, "xpui", "xpui.js"): insertHomeConfig,
filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js"): insertExpFeatures,
filepath.Join(appsFolderPath, "xpui", "home-v2.js"): insertHomeConfig,
filepath.Join(appsFolderPath, "xpui", "xpui-desktop-modals.js"): insertVersionInfo,
filesToModified := map[string][]func(path string, flags Flag){
filepath.Join(appsFolderPath, "xpui", "index.html"): {
htmlMod,
},
filepath.Join(appsFolderPath, "xpui", "xpui.js"): {
insertCustomApp,
insertExpFeatures,
insertSidebarConfig,
insertHomeConfig,
},
filepath.Join(appsFolderPath, "xpui", "vendor~xpui.js"): {
insertExpFeatures,
},
filepath.Join(appsFolderPath, "xpui", "home-v2.js"): {
insertHomeConfig,
},
filepath.Join(appsFolderPath, "xpui", "xpui-desktop-modals.js"): {
insertVersionInfo,
},
}

for file, call := range filesToModified {
for file, calls := range filesToModified {
if _, err := os.Stat(file); os.IsNotExist(err) {
continue
}

call(file, flags)
for _, call := range calls {
call(file, flags)
}
}

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

0 comments on commit d1fc089

Please sign in to comment.