1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-16 11:09:33 +02:00
sap-jenkins-library/pkg/npm/config.go
Anil Keshav f3b65ae43b
feat (npmExecuteScripts) create seperate npmrc file for publish to private repo (#3422)
* creating new npm rc file

* publishing to registry staging

* exposing base64 version of env variables

* changing encoding param

* fixing unit test for the new path

* debugging env var

* remove debug message

* update docu

* changing new npmrc file name

* adding new npmrc to ignore

* adding new npmrc to ignore

Co-authored-by: anilkeshav27 <you@example.com>
2022-01-13 13:08:19 +01:00

51 lines
932 B
Go

package npm
import (
"io/ioutil"
"path/filepath"
"strings"
"github.com/magiconair/properties"
"github.com/pkg/errors"
)
const (
configFilename = ".piperNpmrc"
)
var (
propertiesLoadFile = properties.LoadFile
)
func NewNPMRC(path string) NPMRC {
if !strings.HasSuffix(path, configFilename) {
path = filepath.Join(path, configFilename)
}
return NPMRC{filepath: path, values: properties.NewProperties()}
}
type NPMRC struct {
filepath string
values *properties.Properties
}
func (rc *NPMRC) Write() error {
if err := ioutil.WriteFile(rc.filepath, []byte(rc.values.String()), 0644); err != nil {
return errors.Wrapf(err, "failed to write %s", rc.filepath)
}
return nil
}
func (rc *NPMRC) Load() error {
values, err := propertiesLoadFile(rc.filepath, properties.UTF8)
if err != nil {
return err
}
rc.values = values
return nil
}
func (rc *NPMRC) Set(key, value string) {
rc.values.Set(key, value)
}