mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
f78777f784
* add new paraeters * update generated sources * run npm publish * add repositoryUrl parameter * handle registry credentials * rename parameter * handle base64encoding * remove vault reference * make username secret * add publish method * use publish method * use dedicated registry * use dry run * fix * prepend path * fix workdir * move code to npm package * do changes * update dependencies * correct property init * remomve dry-run * regenerate * add mock * add logging * add debug log * dry-run * remove try run * remove append * add debug outut * change * add debug output * changes * cleanup * use different auth property * add credential utils * add debug log outputs * remove auth handling & reuse writeFile * rename * fix debug output * remove comments * update comment * rename function * update docs * update generated files * handle npm ignore * remove commented code * add debug output
51 lines
927 B
Go
51 lines
927 B
Go
package npm
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/magiconair/properties"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const (
|
|
configFilename = ".npmrc"
|
|
)
|
|
|
|
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)
|
|
}
|