Skip to content

Commit

Permalink
feat: add browserslist support in project settings
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Sep 24, 2023
1 parent 23d2458 commit 80dd0b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/project/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var projectCI = &cobra.Command{
CleanupNodeModules: true,
ShopwareRoot: args[0],
ShopwareVersion: constraint,
Browserslist: shopCfg.Build.Browserslist,
}

if err := extension.BuildAssetsForExtensions(cmd.Context(), sources, assetCfg); err != nil {
Expand Down
24 changes: 21 additions & 3 deletions extension/asset_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type AssetBuildConfig struct {
DisableStorefrontBuild bool
ShopwareRoot string
ShopwareVersion *version.Constraints
Browserslist string
}

func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, assetConfig AssetBuildConfig) error { // nolint:gocyclo
Expand Down Expand Up @@ -113,7 +114,6 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset
continue
}

// @todo: fix me later
options := esbuild.NewAssetCompileOptionsAdmin(source.Name, source.Path)

if _, err := esbuild.CompileExtensionAsset(ctx, options); err != nil {
Expand Down Expand Up @@ -146,18 +146,36 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset
continue
}

// @todo: fix me later
options := esbuild.NewAssetCompileOptionsStorefront(source.Name, source.Path)
if _, err := esbuild.CompileExtensionAsset(ctx, options); err != nil {
return err
}
}
} else {
storefrontRoot := PlatformPath(shopwareRoot, "Storefront", "Resources/app/storefront")

envList := []string{
fmt.Sprintf("PROJECT_ROOT=%s", shopwareRoot),
fmt.Sprintf("STOREFRONT_ROOT=%s", storefrontRoot),
}

if assetConfig.Browserslist != "" {
npx := exec.CommandContext(ctx, "npx", "--yes", "update-browserslist-db", "--quiet")
npx.Stdout = os.Stdout
npx.Stderr = os.Stderr
npx.Dir = storefrontRoot

if err := npx.Run(); err != nil {
return err
}

envList = append(envList, fmt.Sprintf("BROWSERSLIST=%s", assetConfig.Browserslist))
}

err := npmRunBuild(
storefrontRoot,
"production",
[]string{fmt.Sprintf("PROJECT_ROOT=%s", shopwareRoot), fmt.Sprintf("STOREFRONT_ROOT=%s", storefrontRoot)},
envList,
)

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

type ConfigAdminApi struct {
Expand Down
4 changes: 4 additions & 0 deletions shop/shopware-project-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"type": "array",
"items": {"type": "string"},
"description": "Paths to delete for the final build"
},
"browserslist": {
"type": "string",
"description": "Browserslist configuration for the Storefront build"
}
}
},
Expand Down

0 comments on commit 80dd0b8

Please sign in to comment.