1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/npmExecuteScripts.go
Siarhei Pazdniakou cc66b7cabd
Added createBOM parameter to the npmExecuteScripts step (#2642)
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2021-03-04 10:16:59 +01:00

45 lines
1.3 KiB
Go

package cmd
import (
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/npm"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func npmExecuteScripts(config npmExecuteScriptsOptions, telemetryData *telemetry.CustomData) {
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry}
npmExecutor := npm.NewExecutor(npmExecutorOptions)
err := runNpmExecuteScripts(npmExecutor, &config)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runNpmExecuteScripts(npmExecutor npm.Executor, config *npmExecuteScriptsOptions) error {
if config.Install {
packageJSONFiles, err := npmExecutor.FindPackageJSONFilesWithExcludes(config.BuildDescriptorExcludeList)
if err != nil {
return err
}
err = npmExecutor.InstallAllDependencies(packageJSONFiles)
if err != nil {
return err
}
}
if config.CreateBOM {
packageJSONFiles, err := npmExecutor.FindPackageJSONFilesWithExcludes(config.BuildDescriptorExcludeList)
if err != nil {
return err
}
if err := npmExecutor.CreateBOM(packageJSONFiles); err != nil {
return err
}
}
return npmExecutor.RunScriptsInAllPackages(config.RunScripts, nil, config.ScriptOptions, config.VirtualFrameBuffer, config.BuildDescriptorExcludeList, config.BuildDescriptorList)
}