github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/utils/npm/config.go (about) 1 package npm 2 3 import ( 4 "io" 5 "io/ioutil" 6 7 gofrogcmd "github.com/jfrog/gofrog/io" 8 "github.com/jfrog/jfrog-client-go/utils/errorutils" 9 ) 10 11 // This method runs "npm config list --json" command and returns the json object that contains the current configurations of npm 12 // For more info see https://docs.npmjs.com/cli/config 13 func GetConfigList(npmFlags []string, executablePath string) ([]byte, error) { 14 pipeReader, pipeWriter := io.Pipe() 15 defer pipeReader.Close() 16 17 configListCmdConfig := createConfigListCmdConfig(executablePath, npmFlags, pipeWriter) 18 var npmError error 19 go func() { 20 npmError = gofrogcmd.RunCmd(configListCmdConfig) 21 }() 22 23 data, err := ioutil.ReadAll(pipeReader) 24 if err != nil { 25 return nil, errorutils.CheckError(err) 26 } 27 28 if npmError != nil { 29 return nil, errorutils.CheckError(npmError) 30 } 31 return data, nil 32 } 33 34 func createConfigListCmdConfig(executablePath string, splitFlags []string, pipeWriter *io.PipeWriter) *NpmConfig { 35 return &NpmConfig{ 36 Npm: executablePath, 37 Command: []string{"c", "ls"}, 38 CommandFlags: append(splitFlags, "--json"), 39 StrWriter: pipeWriter, 40 ErrWriter: nil, 41 } 42 }