diff --git a/.gitignore b/.gitignore index 6d37f674..bd80201b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ dist/ /*.zip /FroshTools /result +/project dump.sql* # Devenv diff --git a/cmd/project/ci.go b/cmd/project/ci.go index 37cd3d3c..e8bf96de 100644 --- a/cmd/project/ci.go +++ b/cmd/project/ci.go @@ -74,12 +74,13 @@ var projectCI = &cobra.Command{ } assetCfg := extension.AssetBuildConfig{ - EnableESBuildForAdmin: false, - EnableESBuildForStorefront: false, - CleanupNodeModules: true, - ShopwareRoot: args[0], - ShopwareVersion: constraint, - Browserslist: shopCfg.Build.Browserslist, + EnableESBuildForAdmin: false, + EnableESBuildForStorefront: false, + CleanupNodeModules: true, + ShopwareRoot: args[0], + ShopwareVersion: constraint, + Browserslist: shopCfg.Build.Browserslist, + SkipExtensionsWithBuildFiles: true, } if err := extension.BuildAssetsForExtensions(cmd.Context(), sources, assetCfg); err != nil { diff --git a/extension/asset_platform.go b/extension/asset_platform.go index eca2997f..a747049c 100644 --- a/extension/asset_platform.go +++ b/extension/asset_platform.go @@ -27,18 +27,19 @@ const ( ) type AssetBuildConfig struct { - EnableESBuildForAdmin bool - EnableESBuildForStorefront bool - CleanupNodeModules bool - DisableAdminBuild bool - DisableStorefrontBuild bool - ShopwareRoot string - ShopwareVersion *version.Constraints - Browserslist string + EnableESBuildForAdmin bool + EnableESBuildForStorefront bool + CleanupNodeModules bool + DisableAdminBuild bool + DisableStorefrontBuild bool + ShopwareRoot string + ShopwareVersion *version.Constraints + Browserslist string + SkipExtensionsWithBuildFiles bool } func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, assetConfig AssetBuildConfig) error { // nolint:gocyclo - cfgs := buildAssetConfigFromExtensions(sources, assetConfig.ShopwareRoot) + cfgs := buildAssetConfigFromExtensions(ctx, sources, assetConfig) if len(cfgs) == 1 { return nil @@ -276,7 +277,7 @@ func prepareShopwareForAsset(shopwareRoot string, cfgs map[string]ExtensionAsset return nil } -func buildAssetConfigFromExtensions(sources []asset.Source, shopwareRoot string) ExtensionAssetConfig { +func buildAssetConfigFromExtensions(ctx context.Context, sources []asset.Source, assetCfg AssetBuildConfig) ExtensionAssetConfig { list := make(ExtensionAssetConfig) for _, source := range sources { @@ -290,15 +291,29 @@ func buildAssetConfigFromExtensions(sources []asset.Source, shopwareRoot string) continue } - list[source.Name] = createConfigFromPath(source.Name, source.Path) + sourceConfig := createConfigFromPath(source.Name, source.Path) + + if assetCfg.SkipExtensionsWithBuildFiles { + expectedAdminCompiledFile := path.Join(source.Path, "Resources", "public", "administration", "js", esbuild.ToKebabCase(source.Name)+".js") + + if _, err := os.Stat(expectedAdminCompiledFile); err == nil { + // clear out the entrypoint, so the admin does not build it + sourceConfig.Administration.EntryFilePath = nil + sourceConfig.Administration.Webpack = nil + + logging.FromContext(ctx).Infof("Skipping building administration assets for \"%s\" as compiled files are present", source.Name) + } + } + + list[source.Name] = sourceConfig } var basePath string - if shopwareRoot == "" { + if assetCfg.ShopwareRoot == "" { basePath = "src/Storefront/" } else { basePath = strings.TrimLeft( - strings.Replace(PlatformPath(shopwareRoot, "Storefront", ""), shopwareRoot, "", 1), + strings.Replace(PlatformPath(assetCfg.ShopwareRoot, "Storefront", ""), assetCfg.ShopwareRoot, "", 1), "/", ) + "/" } diff --git a/extension/asset_platform_test.go b/extension/asset_platform_test.go index d6aba847..786dff40 100644 --- a/extension/asset_platform_test.go +++ b/extension/asset_platform_test.go @@ -26,7 +26,7 @@ func TestGenerateConfigWithAdminAndStorefrontFiles(t *testing.T) { assert.NoError(t, os.MkdirAll(path.Join(dir, "Resources", "app", "storefront", "src"), os.ModePerm)) assert.NoError(t, os.WriteFile(path.Join(dir, "Resources", "app", "storefront", "src", "main.js"), []byte("test"), os.ModePerm)) - config := buildAssetConfigFromExtensions([]asset.Source{{Name: "FroshTools", Path: dir}}, "") + config := buildAssetConfigFromExtensions(getTestContext(), []asset.Source{{Name: "FroshTools", Path: dir}}, AssetBuildConfig{}) assert.True(t, config.Has("FroshTools")) assert.True(t, config.RequiresAdminBuild()) @@ -56,7 +56,7 @@ func TestGenerateConfigWithTypeScript(t *testing.T) { assert.NoError(t, os.WriteFile(path.Join(dir, "Resources", "app", "storefront", "src", "main.ts"), []byte("test"), os.ModePerm)) assert.NoError(t, os.WriteFile(path.Join(dir, "Resources", "app", "storefront", "build", "webpack.config.js"), []byte("test"), os.ModePerm)) - config := buildAssetConfigFromExtensions([]asset.Source{{Name: "FroshTools", Path: dir}}, "") + config := buildAssetConfigFromExtensions(getTestContext(), []asset.Source{{Name: "FroshTools", Path: dir}}, AssetBuildConfig{}) assert.True(t, config.Has("FroshTools")) assert.True(t, config.RequiresAdminBuild()) @@ -71,7 +71,7 @@ func TestGenerateConfigWithTypeScript(t *testing.T) { } func TestGenerateConfigAddsStorefrontAlwaysAsEntrypoint(t *testing.T) { - config := buildAssetConfigFromExtensions([]asset.Source{}, "") + config := buildAssetConfigFromExtensions(getTestContext(), []asset.Source{}, AssetBuildConfig{}) assert.False(t, config.RequiresStorefrontBuild()) assert.False(t, config.RequiresAdminBuild()) @@ -80,7 +80,7 @@ func TestGenerateConfigAddsStorefrontAlwaysAsEntrypoint(t *testing.T) { func TestGenerateConfigDoesNotAddExtensionWithoutConfig(t *testing.T) { dir := t.TempDir() - config := buildAssetConfigFromExtensions([]asset.Source{{Name: "FroshApp", Path: dir}}, "") + config := buildAssetConfigFromExtensions(getTestContext(), []asset.Source{{Name: "FroshApp", Path: dir}}, AssetBuildConfig{}) assert.False(t, config.Has("FroshApp")) } @@ -88,7 +88,7 @@ func TestGenerateConfigDoesNotAddExtensionWithoutConfig(t *testing.T) { func TestGenerateConfigDoesNotAddExtensionWithoutName(t *testing.T) { dir := t.TempDir() - config := buildAssetConfigFromExtensions([]asset.Source{{Name: "", Path: dir}}, "") + config := buildAssetConfigFromExtensions(getTestContext(), []asset.Source{{Name: "", Path: dir}}, AssetBuildConfig{}) assert.Len(t, config, 1) }