github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/utils/npm/version.go (about) 1 package npm 2 3 import ( 4 gofrogcmd "github.com/jfrog/gofrog/io" 5 "github.com/jfrog/jfrog-client-go/utils/errorutils" 6 "io" 7 "io/ioutil" 8 ) 9 10 func Version(executablePath string) ([]byte, error) { 11 12 pipeReader, pipeWriter := io.Pipe() 13 defer pipeReader.Close() 14 defer pipeWriter.Close() 15 var npmError error 16 17 configListCmdConfig := createVersionCmdConfig(executablePath, pipeWriter) 18 go func() { 19 npmError = gofrogcmd.RunCmd(configListCmdConfig) 20 }() 21 22 data, err := ioutil.ReadAll(pipeReader) 23 if err != nil { 24 return nil, errorutils.CheckError(err) 25 } 26 27 if npmError != nil { 28 return nil, errorutils.CheckError(npmError) 29 } 30 31 return data, nil 32 } 33 34 func createVersionCmdConfig(executablePath string, pipeWriter *io.PipeWriter) *NpmConfig { 35 return &NpmConfig{ 36 Npm: executablePath, 37 Command: []string{"-version"}, 38 StrWriter: pipeWriter, 39 ErrWriter: nil, 40 } 41 }