diff --git a/cmd/project/project_debug.go b/cmd/project/project_debug.go new file mode 100644 index 00000000..cf7c8f89 --- /dev/null +++ b/cmd/project/project_debug.go @@ -0,0 +1,61 @@ +package project + +import ( + "fmt" + "github.com/FriendsOfShopware/shopware-cli/extension" + "github.com/FriendsOfShopware/shopware-cli/logging" + "github.com/FriendsOfShopware/shopware-cli/shop" + "github.com/olekukonko/tablewriter" + "github.com/spf13/cobra" + "os" + "path/filepath" +) + +var projectDebug = &cobra.Command{ + Use: "debug", + Short: "Shows detected Shopware version and detected extensions for further debugging", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + var err error + args[0], err = filepath.Abs(args[0]) + if err != nil { + return err + } + + shopCfg, err := shop.ReadConfig(projectConfigPath, true) + if err != nil { + return err + } + + shopwareConstraint, err := extension.GetShopwareProjectConstraint(args[0]) + if err != nil { + return err + } + + if shopCfg.IsFallback() { + fmt.Printf("Could not find a %s, using fallback config\n", projectConfigPath) + } else { + fmt.Printf("Found config: Yes\n") + } + fmt.Printf("Detected following Shopware version: %s\n", shopwareConstraint.String()) + + sources := extension.FindAssetSourcesOfProject(logging.DisableLogger(cmd.Context()), args[0], shopCfg) + + fmt.Println("Following extensions/bundles has been detected") + table := tablewriter.NewWriter(os.Stdout) + table.SetColWidth(100) + table.SetHeader([]string{"Name", "Path"}) + + for _, source := range sources { + table.Append([]string{source.Name, source.Path}) + } + + table.Render() + + return nil + }, +} + +func init() { + projectRootCmd.AddCommand(projectDebug) +} diff --git a/extension/platform.go b/extension/platform.go index c2f7cd6d..e596688c 100644 --- a/extension/platform.go +++ b/extension/platform.go @@ -156,6 +156,7 @@ func (p PlatformPlugin) GetPath() string { func (p PlatformPlugin) GetMetaData() *extensionMetadata { return &extensionMetadata{ + Name: p.composer.Name, Label: extensionTranslated{ German: p.composer.Extra.Label["de-DE"], English: p.composer.Extra.Label["en-GB"], diff --git a/extension/project.go b/extension/project.go index f3e433fc..d81a93db 100644 --- a/extension/project.go +++ b/extension/project.go @@ -185,7 +185,7 @@ func FindExtensionsFromProject(ctx context.Context, project string) []Extension version, _ := ext.GetVersion() logging.FromContext(ctx).Infof("Found extension in custom/plugins: %s (%s)", name, version) - logging.FromContext(ctx).Errorf("Extension %s should be installed using Composer. Please remove the extension from custom/plugins.", name) + logging.FromContext(ctx).Warnf("Extension %s should be installed using Composer. Please run composer require %s.", name, ext.GetMetaData().Name) extensions[name] = ext } diff --git a/extension/root.go b/extension/root.go index 38f31122..f41f58cd 100644 --- a/extension/root.go +++ b/extension/root.go @@ -82,6 +82,7 @@ type extensionTranslated struct { } type extensionMetadata struct { + Name string Label extensionTranslated Description extensionTranslated } diff --git a/logging/logger.go b/logging/logger.go index 5c845397..acaf0973 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -52,3 +52,7 @@ func FromContext(ctx context.Context) *zap.SugaredLogger { return fallbackLogger } + +func DisableLogger(ctx context.Context) context.Context { + return WithLogger(ctx, zap.NewNop().Sugar()) +} diff --git a/shop/config.go b/shop/config.go index d1c919a3..87ff5477 100644 --- a/shop/config.go +++ b/shop/config.go @@ -20,6 +20,7 @@ type Config struct { AdminApi *ConfigAdminApi `yaml:"admin_api,omitempty"` ConfigDump *ConfigDump `yaml:"dump,omitempty"` Sync *ConfigSync `yaml:"sync,omitempty"` + foundConfig bool } type ConfigBuild struct { @@ -85,7 +86,7 @@ type MailTemplateTranslation struct { } func ReadConfig(fileName string, allowFallback bool) (*Config, error) { - config := &Config{} + config := &Config{foundConfig: false} _, err := os.Stat(fileName) @@ -106,6 +107,8 @@ func ReadConfig(fileName string, allowFallback bool) (*Config, error) { return nil, fmt.Errorf("ReadConfig: %v", err) } + config.foundConfig = true + substitutedConfig := os.ExpandEnv(string(fileHandle)) err = yaml.Unmarshal([]byte(substitutedConfig), &config) @@ -140,6 +143,10 @@ func fillEmptyConfig(c *Config) *Config { return c } +func (c Config) IsFallback() bool { + return !c.foundConfig +} + func NewUuid() string { return strings.ReplaceAll(uuid.New().String(), "-", "") }