/
platform.go
87 lines (69 loc) · 2.09 KB
/
platform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package project
import (
"encoding/json"
"fmt"
"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/shop"
"github.com/spf13/cobra"
"os"
"path"
"path/filepath"
"strings"
)
func findClosestShopwareProject() (string, error) {
currentDir, err := os.Getwd()
if err != nil {
return "", err
}
for {
files := []string{
fmt.Sprintf("%s/composer.json", currentDir),
fmt.Sprintf("%s/composer.lock", currentDir),
}
for _, file := range files {
if _, err := os.Stat(file); err == nil {
content, err := os.ReadFile(file)
if err != nil {
return "", err
}
contentString := string(content)
if strings.Contains(contentString, "shopware/core") {
if _, err := os.Stat(fmt.Sprintf("%s/bin/console", currentDir)); err == nil {
return currentDir, nil
}
}
}
}
currentDir = filepath.Dir(currentDir)
if currentDir == filepath.Dir(currentDir) {
break
}
}
return "", fmt.Errorf("cannot find Shopware project in current directory")
}
func filterAndWritePluginJson(cmd *cobra.Command, projectRoot string, shopCfg *shop.Config) error {
sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)
cfgs := extension.BuildAssetConfigFromExtensions(cmd.Context(), sources, extension.AssetBuildConfig{})
onlyExtensions, _ := cmd.PersistentFlags().GetString("only-extensions")
skipExtensions, _ := cmd.PersistentFlags().GetString("skip-extensions")
if onlyExtensions != "" && skipExtensions != "" {
return fmt.Errorf("only-extensions and skip-extensions cannot be used together")
}
if onlyExtensions != "" {
cfgs = cfgs.Only(strings.Split(onlyExtensions, ","))
}
if skipExtensions != "" {
cfgs = cfgs.Not(strings.Split(skipExtensions, ","))
}
if _, err := extension.InstallNodeModulesOfConfigs(cmd.Context(), cfgs, false); err != nil {
return err
}
pluginJson, err := json.MarshalIndent(cfgs, "", " ")
if err != nil {
return err
}
if err := os.WriteFile(path.Join(projectRoot, "var", "plugins.json"), pluginJson, os.ModePerm); err != nil {
return err
}
return nil
}