Skip to content

Commit 8108a69

Browse files
committed
feat: add functionality to read and parse composer.json for project configuration
1 parent f934410 commit 8108a69

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

internal/tool/project.go

+48-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/shopware/shopware-cli/extension"
13+
"github.com/shopware/shopware-cli/logging"
1314
"github.com/shopware/shopware-cli/shop"
1415
"github.com/shyim/go-version"
1516
)
@@ -89,7 +90,7 @@ func GetConfigFromProject(root string) (*ToolConfig, error) {
8990
return nil, err
9091
}
9192

92-
extensions := extension.FindExtensionsFromProject(context.Background(), root)
93+
extensions := extension.FindExtensionsFromProject(logging.DisableLogger(context.Background()), root)
9394

9495
sourceDirectories := []string{}
9596
adminDirectories := []string{}
@@ -128,6 +129,41 @@ func GetConfigFromProject(root string) (*ToolConfig, error) {
128129
storefrontDirectories = append(storefrontDirectories, getStorefrontFolders(ext)...)
129130
}
130131

132+
var rootComposerJsonData rootComposerJson
133+
134+
rootComposerJsonPath := path.Join(root, "composer.json")
135+
136+
file, err := os.Open(rootComposerJsonPath)
137+
138+
if err != nil {
139+
return nil, err
140+
}
141+
142+
defer func() {
143+
if closeErr := file.Close(); closeErr != nil {
144+
err = fmt.Errorf("failed to close composer.json: %w", closeErr)
145+
}
146+
}()
147+
148+
if err := json.NewDecoder(file).Decode(&rootComposerJsonData); err != nil {
149+
return nil, err
150+
}
151+
152+
for bundlePath, _ := range rootComposerJsonData.Extra.Bundles {
153+
sourceDirectories = append(sourceDirectories, path.Join(root, bundlePath))
154+
155+
expectedAdminPath := path.Join(root, bundlePath, "Resources", "app", "administration")
156+
expectedStorefrontPath := path.Join(root, bundlePath, "Resources", "app", "storefront")
157+
158+
if _, err := os.Stat(expectedAdminPath); err == nil {
159+
adminDirectories = append(adminDirectories, expectedAdminPath)
160+
}
161+
162+
if _, err := os.Stat(expectedStorefrontPath); err == nil {
163+
storefrontDirectories = append(storefrontDirectories, expectedStorefrontPath)
164+
}
165+
}
166+
131167
var validationIgnores []ToolConfigIgnore
132168

133169
if shopCfg.Validation != nil {
@@ -154,3 +190,14 @@ func GetConfigFromProject(root string) (*ToolConfig, error) {
154190

155191
return toolCfg, nil
156192
}
193+
194+
type rootComposerJson struct {
195+
Require map[string]string `json:"require"`
196+
Extra struct {
197+
Bundles map[string]rootShopwareBundle `json:"shopware-bundles"`
198+
}
199+
}
200+
201+
type rootShopwareBundle struct {
202+
Name string `json:"name"`
203+
}

0 commit comments

Comments
 (0)