github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/buildtools/yarn/yarn.go (about) 1 package yarn 2 3 import ( 4 "os" 5 6 "github.com/apex/log" 7 "github.com/fossas/fossa-cli/exec" 8 ) 9 10 type YarnTool interface { 11 // TODO: implement yarn list --production --frozen-lockfile. Skipping for now because the implementation relies 100% on yarn.lock 12 // List(dir string) error 13 Install(dir string) error 14 // Exists returns true if yarn is available 15 Exists() bool 16 } 17 18 type SystemYarn struct { 19 Cmd string 20 } 21 22 func New() (YarnTool, error) { 23 yarnCmd, _, yarnErr := exec.Which("-v", os.Getenv("FOSSA_NPM_CMD"), "yarn") 24 if yarnErr != nil { 25 log.Warnf("Could not find Yarn %s", yarnErr.Error()) 26 return SystemYarn{}, yarnErr 27 } 28 29 return SystemYarn{ 30 Cmd: yarnCmd, 31 }, nil 32 } 33 34 func (y SystemYarn) Exists() bool { 35 return y.Cmd != "" 36 } 37 38 func (y SystemYarn) Install(dir string) error { 39 _, _, err := exec.Run(exec.Cmd{ 40 Name: y.Cmd, 41 Argv: []string{"install", "--production", "--frozen-lockfile"}, 42 Dir: dir, 43 }) 44 45 return err 46 }