From 7265d23f12f47dfcc764d61ac370027b4c95b310 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Sun, 11 Feb 2024 18:52:55 +0100 Subject: [PATCH] fix: storefront-watch install dependencies --- cmd/project/project_storefront_watch.go | 6 ++++++ extension/asset_platform.go | 20 ++++++++++---------- extension/bun_helper.go | 4 ++-- extension/util.go | 3 ++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cmd/project/project_storefront_watch.go b/cmd/project/project_storefront_watch.go index f9169620..c37d652e 100644 --- a/cmd/project/project_storefront_watch.go +++ b/cmd/project/project_storefront_watch.go @@ -61,6 +61,12 @@ var projectStorefrontWatchCmd = &cobra.Command{ return err } + if _, err := os.Stat(extension.PlatformPath(projectRoot, "Storefront", "Resources/app/storefront/node_modules/webpack-dev-server")); os.IsNotExist(err) { + if err := extension.InstallNPMDependencies(extension.PlatformPath(projectRoot, "Storefront", "Resources/app/storefront"), extension.NpmPackage{Dependencies: map[string]string{"not-empty": "not-empty"}}); err != nil { + return err + } + } + return runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "npm", "run-script", "hot-proxy"), extension.PlatformPath(projectRoot, "Storefront", "Resources/app/storefront"))) }, } diff --git a/extension/asset_platform.go b/extension/asset_platform.go index e6d73dd3..0aac9208 100644 --- a/extension/asset_platform.go +++ b/extension/asset_platform.go @@ -104,7 +104,7 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset additionalNpmParameters = []string{"--production"} } - if err := installDependencies(administrationRoot, npmPackage, additionalNpmParameters...); err != nil { + if err := InstallNPMDependencies(administrationRoot, npmPackage, additionalNpmParameters...); err != nil { return err } } @@ -193,7 +193,7 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset additionalNpmParameters = append(additionalNpmParameters, "--production") } - if err := installDependencies(storefrontRoot, npmPackage, additionalNpmParameters...); err != nil { + if err := InstallNPMDependencies(storefrontRoot, npmPackage, additionalNpmParameters...); err != nil { return err } } @@ -281,7 +281,7 @@ func InstallNodeModulesOfConfigs(ctx context.Context, cfgs ExtensionAssetConfig, logging.FromContext(ctx).Infof("Installing npm dependencies in %s %s\n", npmPath, additionalText) - if err := installDependencies(npmPath, npmPackage, additionalNpmParameters...); err != nil { + if err := InstallNPMDependencies(npmPath, npmPackage, additionalNpmParameters...); err != nil { return nil, err } @@ -316,7 +316,7 @@ func npmRunBuild(path string, buildCmd string, buildEnvVariables []string) error return nil } -func getInstallCommand(root string, isProductionMode bool, npmPackage npmPackage) *exec.Cmd { +func getInstallCommand(root string, isProductionMode bool, npmPackage NpmPackage) *exec.Cmd { if _, err := os.Stat(path.Join(root, "pnpm-lock.yaml")); err == nil { return exec.Command("pnpm", "install") } @@ -340,7 +340,7 @@ func getInstallCommand(root string, isProductionMode bool, npmPackage npmPackage return exec.Command("npm", "install", "--no-audit", "--no-fund", "--prefer-offline") } -func installDependencies(path string, packageJsonData npmPackage, additionalParams ...string) error { +func InstallNPMDependencies(path string, packageJsonData NpmPackage, additionalParams ...string) error { isProductionMode := false for _, param := range additionalParams { @@ -368,15 +368,15 @@ func installDependencies(path string, packageJsonData npmPackage, additionalPara return nil } -func getNpmPackage(root string) (npmPackage, error) { +func getNpmPackage(root string) (NpmPackage, error) { packageJsonFile, err := os.ReadFile(path.Join(root, "package.json")) if err != nil { - return npmPackage{}, err + return NpmPackage{}, err } - var packageJsonData npmPackage + var packageJsonData NpmPackage if err := json.Unmarshal(packageJsonFile, &packageJsonData); err != nil { - return npmPackage{}, err + return NpmPackage{}, err } return packageJsonData, nil } @@ -667,7 +667,7 @@ type ExtensionAssetConfigStorefront struct { StyleFiles []string `json:"styleFiles"` } -func doesPackageJsonContainsPackageInDev(packageJsonData npmPackage, packageName string) bool { +func doesPackageJsonContainsPackageInDev(packageJsonData NpmPackage, packageName string) bool { if _, ok := packageJsonData.DevDependencies[packageName]; ok { return true } diff --git a/extension/bun_helper.go b/extension/bun_helper.go index 099e321a..ca3feb39 100644 --- a/extension/bun_helper.go +++ b/extension/bun_helper.go @@ -1,12 +1,12 @@ package extension -type npmPackage struct { +type NpmPackage struct { Dependencies map[string]string `json:"dependencies"` DevDependencies map[string]string `json:"devDependencies"` } // When a package is defined in both dependencies and devDependencies, bun will crash. -func canRunBunOnPackage(npmPackage npmPackage) bool { +func canRunBunOnPackage(npmPackage NpmPackage) bool { for name := range npmPackage.Dependencies { if _, ok := npmPackage.DevDependencies[name]; ok { return false diff --git a/extension/util.go b/extension/util.go index 8dd6b452..8cb2a7eb 100644 --- a/extension/util.go +++ b/extension/util.go @@ -18,7 +18,7 @@ func PlatformPath(projectRoot, component, path string) string { return filepath.Join(projectRoot, "vendor", "shopware", strings.ToLower(component), path) } -// IsContributeProject checks if the project is a contribution project aka shopware/shopware +// IsContributeProject checks if the project is a contribution project aka shopware/shopware. func IsContributeProject(projectRoot string) bool { if _, err := os.Stat(filepath.Join(projectRoot, "src", "Core", "composer.json")); err == nil { return true @@ -27,6 +27,7 @@ func IsContributeProject(projectRoot string) bool { return false } +// LoadSymfonyEnvFile loads the Symfony .env file from the project root. func LoadSymfonyEnvFile(projectRoot string) error { currentEnv := os.Getenv("APP_ENV") if currentEnv == "" {