Skip to content

Commit

Permalink
feat: use resolved apps/plugins from php, fixes #427
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Nov 12, 2024
1 parent f791f9d commit e602f67
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/project/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ func findClosestShopwareProject() (string, error) {
}

func filterAndWritePluginJson(cmd *cobra.Command, projectRoot string, shopCfg *shop.Config) error {
sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)
sources, err := extension.DumpAndLoadAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)

if err != nil {
return err
}

cfgs := extension.BuildAssetConfigFromExtensions(cmd.Context(), sources, extension.AssetBuildConfig{})

Expand Down
10 changes: 9 additions & 1 deletion cmd/project/project_admin_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ var projectAdminBuildCmd = &cobra.Command{

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

sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "feature:dump"), projectRoot)); err != nil {
return err
}

sources, err := extension.DumpAndLoadAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)

if err != nil {
return err
}

forceInstall, _ := cmd.PersistentFlags().GetBool("force-install-dependencies")

Expand Down
10 changes: 9 additions & 1 deletion cmd/project/project_storefront_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ var projectStorefrontBuildCmd = &cobra.Command{

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

sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "feature:dump"), projectRoot)); err != nil {
return err
}

sources, err := extension.DumpAndLoadAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)

if err != nil {
return err
}

forceInstall, _ := cmd.PersistentFlags().GetBool("force-install-dependencies")

Expand Down
47 changes: 47 additions & 0 deletions 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/internal/phpexec"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -98,6 +99,7 @@ func getProjectConstraintFromKernel(project string) (*version.Constraints, error
return &v, nil
}

// FindAssetSourcesOfProject This finds all assets without invoking any PHP function and thinks all plugins / apps are active. Optional for CI usage.
func FindAssetSourcesOfProject(ctx context.Context, project string, shopCfg *shop.Config) []asset.Source {
extensions := FindExtensionsFromProject(ctx, project)
sources := ConvertExtensionsToSources(ctx, extensions)
Expand Down Expand Up @@ -152,6 +154,51 @@ func FindAssetSourcesOfProject(ctx context.Context, project string, shopCfg *sho
return sources
}

func DumpAndLoadAssetSourcesOfProject(ctx context.Context, project string, shopCfg *shop.Config) ([]asset.Source, error) {
dumpExec := phpexec.ConsoleCommand(ctx, "bundle:dump")
dumpExec.Dir = project
dumpExec.Stdin = os.Stdin
dumpExec.Stdout = os.Stdout
dumpExec.Stderr = os.Stderr

if err := dumpExec.Run(); err != nil {
return nil, fmt.Errorf("could not bundle features: %w", err)
}

var pluginsJson map[string]ExtensionAssetConfigEntry

pluginJsonBytes, err := os.ReadFile(path.Join(project, "var", "plugins.json"))

if err != nil {
return nil, fmt.Errorf("could not read plugins.json: %w", err)
}

if err := json.Unmarshal(pluginJsonBytes, &pluginsJson); err != nil {
return nil, fmt.Errorf("could not parse plugins.json: %w", err)
}

var sources []asset.Source

for name, entry := range pluginsJson {
if entry.Administration.EntryFilePath != nil || entry.Storefront.EntryFilePath != nil {
source := asset.Source{
Name: name,
Path: entry.BasePath,
}

if extensionCfg, err := readExtensionConfig(path.Join(project, entry.BasePath)); err == nil {
source.AdminEsbuildCompatible = extensionCfg.Build.Zip.Assets.EnableESBuildForAdmin
source.StorefrontEsbuildCompatible = extensionCfg.Build.Zip.Assets.EnableESBuildForStorefront
source.NpmStrict = extensionCfg.Build.Zip.Assets.NpmStrict
}

sources = append(sources, source)
}
}

return sources, nil
}

func FindExtensionsFromProject(ctx context.Context, project string) []Extension {
extensions := make(map[string]Extension)

Expand Down

0 comments on commit e602f67

Please sign in to comment.