Skip to content

Commit

Permalink
feat: allow excluding extensions from building assets, fixes #286
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jan 14, 2024
1 parent 9a2c0eb commit 071c9c7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 5 deletions.
8 changes: 7 additions & 1 deletion cmd/extension/extension_admin_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"encoding/json"
"fmt"
"github.com/FriendsOfShopware/shopware-cli/shop"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -57,7 +58,12 @@ var extensionAdminWatchCmd = &cobra.Command{
for _, extensionPath := range args[:len(args)-1] {
ext, err := extension.GetExtensionByFolder(extensionPath)
if err != nil {
sources = append(sources, extension.FindAssetSourcesOfProject(cmd.Context(), extensionPath)...)
shopCfg, err := shop.ReadConfig(path.Join(extensionPath, ".shopware-project.yml"), true)
if err != nil {
return err
}

sources = append(sources, extension.FindAssetSourcesOfProject(cmd.Context(), extensionPath, shopCfg)...)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/project/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var projectCI = &cobra.Command{

logging.FromContext(cmd.Context()).Infof("Looking for extensions to build assets in project")

sources := extension.FindAssetSourcesOfProject(cmd.Context(), args[0])
sources := extension.FindAssetSourcesOfProject(cmd.Context(), args[0], shopCfg)

assetCfg := extension.AssetBuildConfig{
CleanupNodeModules: true,
Expand Down
8 changes: 7 additions & 1 deletion cmd/project/project_admin_build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package project

import (
"github.com/FriendsOfShopware/shopware-cli/shop"
"os/exec"

"github.com/FriendsOfShopware/shopware-cli/extension"
Expand All @@ -21,9 +22,14 @@ var projectAdminBuildCmd = &cobra.Command{
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)
sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)

assetCfg := extension.AssetBuildConfig{
DisableStorefrontBuild: true,
Expand Down
8 changes: 7 additions & 1 deletion cmd/project/project_storefront_build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package project

import (
"github.com/FriendsOfShopware/shopware-cli/shop"
"os/exec"

"github.com/FriendsOfShopware/shopware-cli/extension"
Expand All @@ -21,9 +22,14 @@ var projectStorefrontBuildCmd = &cobra.Command{
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)
sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)

assetCfg := extension.AssetBuildConfig{
DisableAdminBuild: true,
Expand Down
14 changes: 13 additions & 1 deletion extension/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/FriendsOfShopware/shopware-cli/shop"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -40,7 +41,7 @@ func GetShopwareProjectConstraint(project string) (*version.Constraints, error)
return &c, nil
}

func FindAssetSourcesOfProject(ctx context.Context, project string) []asset.Source {
func FindAssetSourcesOfProject(ctx context.Context, project string, shopCfg *shop.Config) []asset.Source {
extensions := FindExtensionsFromProject(ctx, project)
sources := ConvertExtensionsToSources(ctx, extensions)

Expand Down Expand Up @@ -81,6 +82,17 @@ func FindAssetSourcesOfProject(ctx context.Context, project string) []asset.Sour
})
}

if len(shopCfg.Build.ExcludeExtensions) > 0 {
logging.FromContext(ctx).Infof("Excluded extensions in project: %s", shopCfg.Build.ExcludeExtensions)
for _, excludedExtension := range shopCfg.Build.ExcludeExtensions {
for i, source := range sources {
if source.Name == excludedExtension {
sources = append(sources[:i], sources[i+1:]...)
}
}
}
}

return sources
}

Expand Down
1 change: 1 addition & 0 deletions shop/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ConfigBuild struct {
KeepExtensionSource bool `yaml:"keep_extension_source,omitempty"`
CleanupPaths []string `yaml:"cleanup_paths,omitempty"`
Browserslist string `yaml:"browserslist,omitempty"`
ExcludeExtensions []string `yaml:"exclude_extensions,omitempty"`
}

type ConfigAdminApi struct {
Expand Down
5 changes: 5 additions & 0 deletions shop/shopware-project-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"browserslist": {
"type": "string",
"description": "Browserslist configuration for the Storefront build"
},
"exclude_extensions": {
"type": "array",
"items": {"type": "string"},
"description": "Extensions to exclude from the build"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions wiki/docs/shopware-project-yml-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ build:
- path
# change the browserslist of the storefront build, see https://browsersl.ist for the syntax as string (example: defaults, not dead)
browserslist: ''
# exclude extensions to be built by shopware-cli, only their PHP code will be shipped without any css/js
exclude_extensions:
- name

# used for mysql dump creation
dump:
Expand Down

0 comments on commit 071c9c7

Please sign in to comment.