1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/npm/ignore.go
Christopher Fenner f78777f784
feat(npm): allow to publish artifact to registry (#2871)
* 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
2021-07-15 14:46:04 +02:00

57 lines
1.1 KiB
Go

package npm
import (
"bufio"
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/pkg/errors"
)
const (
ignoreFilename = ".npmignore"
)
func NewNPMIgnore(path string) NPMIgnore {
if !strings.HasSuffix(path, ignoreFilename) {
path = filepath.Join(path, ignoreFilename)
}
return NPMIgnore{filepath: path, values: []string{}}
}
type NPMIgnore struct {
filepath string
values []string
}
func (ignorefile *NPMIgnore) Write() error {
content := strings.Join(ignorefile.values, "\n")
if err := ioutil.WriteFile(ignorefile.filepath, []byte(content+"\n"), 0644); err != nil {
return errors.Wrapf(err, "failed to write %s", ignorefile.filepath)
}
return nil
}
func (ignorefile *NPMIgnore) Load() error {
file, err := os.Open(ignorefile.filepath)
if err != nil {
return err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
ignorefile.values = lines
return scanner.Err()
}
func (ignorefile *NPMIgnore) Add(value string) {
ignorefile.values = append(ignorefile.values, value)
}