github.com/osievert/jfrog-cli-core@v1.2.7/artifactory/utils/npm/version.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 func Version(executablePath string) ([]byte, error) { 12 13 pipeReader, pipeWriter := io.Pipe() 14 defer pipeReader.Close() 15 defer pipeWriter.Close() 16 var npmError error 17 18 configListCmdConfig := createVersionCmdConfig(executablePath, pipeWriter) 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 32 return data, nil 33 } 34 35 func createVersionCmdConfig(executablePath string, pipeWriter *io.PipeWriter) *NpmConfig { 36 return &NpmConfig{ 37 Npm: executablePath, 38 Command: []string{"-version"}, 39 StrWriter: pipeWriter, 40 ErrWriter: nil, 41 } 42 }