2020-04-24 18:29:30 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
2020-05-20 13:41:23 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/npm"
|
2020-04-24 18:29:30 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
|
|
)
|
|
|
|
|
|
|
|
func npmExecuteScripts(config npmExecuteScriptsOptions, telemetryData *telemetry.CustomData) {
|
2020-08-11 15:58:39 +02:00
|
|
|
npmExecutorOptions := npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry}
|
2020-06-18 17:30:17 +02:00
|
|
|
npmExecutor := npm.NewExecutor(npmExecutorOptions)
|
2020-04-24 18:29:30 +02:00
|
|
|
|
2020-06-18 17:30:17 +02:00
|
|
|
err := runNpmExecuteScripts(npmExecutor, &config)
|
2020-04-24 18:29:30 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Entry().WithError(err).Fatal("step execution failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 17:30:17 +02:00
|
|
|
func runNpmExecuteScripts(npmExecutor npm.Executor, config *npmExecuteScriptsOptions) error {
|
|
|
|
if config.Install {
|
2020-07-16 17:16:55 +02:00
|
|
|
packageJSONFiles, err := npmExecutor.FindPackageJSONFilesWithExcludes(config.BuildDescriptorExcludeList)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = npmExecutor.InstallAllDependencies(packageJSONFiles)
|
2020-04-24 18:29:30 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:20:26 +02:00
|
|
|
return npmExecutor.RunScriptsInAllPackages(config.RunScripts, nil, config.ScriptOptions, config.VirtualFrameBuffer, config.BuildDescriptorExcludeList, config.BuildDescriptorList)
|
2020-04-24 18:29:30 +02:00
|
|
|
}
|