/
project_admin_build.go
72 lines (57 loc) · 2.11 KB
/
project_admin_build.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
package project
import (
"path/filepath"
"github.com/FriendsOfShopware/shopware-cli/internal/phpexec"
"github.com/FriendsOfShopware/shopware-cli/shop"
"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/logging"
"github.com/spf13/cobra"
)
var projectAdminBuildCmd = &cobra.Command{
Use: "admin-build [project-dir]",
Short: "Builds the Administration",
RunE: func(cmd *cobra.Command, args []string) error {
var projectRoot string
var err error
if len(args) == 1 {
// We need an absolute path for webpack
projectRoot, err = filepath.Abs(args[0])
if err != nil {
return err
}
} else if projectRoot, err = findClosestShopwareProject(); err != nil {
return err
}
shopCfg, err := shop.ReadConfig(projectConfigPath, true)
if err != nil {
return err
}
logging.FromContext(cmd.Context()).Infof("Looking for extensions to build assets in project")
sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)
forceInstall, _ := cmd.PersistentFlags().GetBool("force-install-dependencies")
shopwareConstraint, err := extension.GetShopwareProjectConstraint(projectRoot)
if err != nil {
return err
}
assetCfg := extension.AssetBuildConfig{
DisableStorefrontBuild: true,
ShopwareRoot: projectRoot,
ShopwareVersion: shopwareConstraint,
NPMForceInstall: forceInstall,
ContributeProject: extension.IsContributeProject(projectRoot),
}
if err := extension.BuildAssetsForExtensions(cmd.Context(), sources, assetCfg); err != nil {
return err
}
skipAssetsInstall, _ := cmd.PersistentFlags().GetBool("skip-assets-install")
if skipAssetsInstall {
return nil
}
return runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "assets:install"), projectRoot))
},
}
func init() {
projectRootCmd.AddCommand(projectAdminBuildCmd)
projectAdminBuildCmd.PersistentFlags().Bool("skip-assets-install", false, "Skips the assets installation")
projectAdminBuildCmd.PersistentFlags().Bool("force-install-dependencies", false, "Force install NPM dependencies")
}