Skip to content

Commit 4e5643b

Browse files
amenkshyim
andauthored
feat: Add only-custom-static-extensions (#528)
* feat: Add only-custom-static-extensions closes #524 * chore: cleanup code --------- Co-authored-by: Soner Sayakci <[email protected]>
1 parent 44924bd commit 4e5643b

4 files changed

Lines changed: 50 additions & 8 deletions

File tree

cmd/project/platform.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,57 @@ func filterAndGetSources(cmd *cobra.Command, projectRoot string, shopCfg *shop.C
112112

113113
onlyExtensions, _ := cmd.PersistentFlags().GetString("only-extensions")
114114
skipExtensions, _ := cmd.PersistentFlags().GetString("skip-extensions")
115+
onlyCustomStatic, _ := cmd.PersistentFlags().GetBool("only-custom-static-extensions")
115116

116117
if onlyExtensions != "" && skipExtensions != "" {
117118
return nil, fmt.Errorf("only-extensions and skip-extensions cannot be used together")
118119
}
119120

120-
if onlyExtensions == "" && skipExtensions == "" {
121+
if onlyCustomStatic {
122+
logging.FromContext(cmd.Context()).Infof("Only including extensions from custom/static-plugins directory")
123+
logging.FromContext(cmd.Context()).Debugf("Found %d total extensions before filtering", len(sources))
124+
for _, s := range sources {
125+
logging.FromContext(cmd.Context()).Debugf("Extension: %s, Path: %s", s.Name, s.Path)
126+
}
127+
128+
sources = slices.DeleteFunc(sources, func(s asset.Source) bool {
129+
// First try to resolve any symlinks
130+
resolvedPath, err := filepath.EvalSymlinks(s.Path)
131+
if err != nil {
132+
logging.FromContext(cmd.Context()).Errorf("Failed to resolve symlink for %s: %v", s.Path, err)
133+
return true
134+
}
135+
136+
absPath, err := filepath.Abs(resolvedPath)
137+
if err != nil {
138+
logging.FromContext(cmd.Context()).Errorf("Failed to get absolute path for %s: %v", resolvedPath, err)
139+
return true
140+
}
141+
142+
logging.FromContext(cmd.Context()).Debugf("Extension %s: Original path: %s, Resolved absolute path: %s", s.Name, s.Path, absPath)
143+
144+
customStaticDir := filepath.Join("custom", "static-plugins")
145+
146+
isCustomStatic := strings.Contains(absPath, customStaticDir) || strings.HasSuffix(absPath, customStaticDir)
147+
148+
if !isCustomStatic {
149+
logging.FromContext(cmd.Context()).Debugf("Excluding %s as it's not in custom/static-plugins", s.Name)
150+
}
151+
return !isCustomStatic
152+
})
153+
154+
logging.FromContext(cmd.Context()).Debugf("Found %d custom/static extensions after filtering", len(sources))
155+
for _, s := range sources {
156+
logging.FromContext(cmd.Context()).Debugf("Included extension: %s, Path: %s", s.Name, s.Path)
157+
}
158+
159+
logging.FromContext(cmd.Context()).Debugf("Included extensions:")
160+
for _, s := range sources {
161+
logging.FromContext(cmd.Context()).Debugf(" - %s", s.Name)
162+
}
163+
}
164+
165+
if onlyExtensions == "" && skipExtensions == "" && !onlyCustomStatic {
121166
logging.FromContext(cmd.Context()).Infof("Excluding extensions based on project config: %s", strings.Join(shopCfg.Build.ExcludeExtensions, ", "))
122167
sources = slices.DeleteFunc(sources, func(s asset.Source) bool {
123168
return slices.Contains(shopCfg.Build.ExcludeExtensions, s.Name)

cmd/project/project_admin_build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ func init() {
7878
projectAdminBuildCmd.PersistentFlags().Bool("force-install-dependencies", false, "Force install NPM dependencies")
7979
projectAdminBuildCmd.PersistentFlags().String("only-extensions", "", "Only watch the given extensions (comma separated)")
8080
projectAdminBuildCmd.PersistentFlags().String("skip-extensions", "", "Skips the given extensions (comma separated)")
81+
projectAdminBuildCmd.PersistentFlags().Bool("only-custom-static-extensions", false, "Only build extensions from custom/static-plugins directory")
8182
}

cmd/project/project_storefront_build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ func init() {
7878
projectStorefrontBuildCmd.PersistentFlags().Bool("force-install-dependencies", false, "Force install NPM dependencies")
7979
projectStorefrontBuildCmd.PersistentFlags().String("only-extensions", "", "Only watch the given extensions (comma separated)")
8080
projectStorefrontBuildCmd.PersistentFlags().String("skip-extensions", "", "Skips the given extensions (comma separated)")
81+
projectStorefrontBuildCmd.PersistentFlags().Bool("only-custom-static-extensions", false, "Only build extensions from custom/static-plugins directory")
8182
}

cmd/root.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"context"
55
"os"
6+
"slices"
67

78
"github.com/spf13/cobra"
89

@@ -27,13 +28,7 @@ var rootCmd = &cobra.Command{
2728
}
2829

2930
func Execute(ctx context.Context) {
30-
verbose := false
31-
32-
if err := rootCmd.ParseFlags(os.Args); err == nil {
33-
verbose, _ = rootCmd.PersistentFlags().GetBool("verbose")
34-
}
35-
36-
ctx = logging.WithLogger(ctx, logging.NewLogger(verbose))
31+
ctx = logging.WithLogger(ctx, logging.NewLogger(slices.Contains(os.Args, "--verbose")))
3732
accountApi.SetUserAgent("shopware-cli/" + version)
3833

3934
if err := rootCmd.ExecuteContext(ctx); err != nil {

0 commit comments

Comments
 (0)