@@ -2,12 +2,8 @@ package cmd
22
33import (
44 cfg "codacy/cli-v2/config"
5- toolutils "codacy/cli-v2/tool-utils"
6- "codacy/cli-v2/utils"
75 "github.com/spf13/cobra"
86 "log"
9- "os"
10- "path/filepath"
117)
128
139func init () {
@@ -16,38 +12,21 @@ func init() {
1612
1713var installCmd = & cobra.Command {
1814 Use : "install" ,
19- Short : "Installs the tools specified in the project's config." ,
20- Long : "Installs all runtimes and tools specified in the project's config file." ,
15+ Short : "Installs the tools specified in the project's config-file ." ,
16+ Long : "Installs all runtimes and tools specified in the project's config-file file." ,
2117 Run : func (cmd * cobra.Command , args []string ) {
2218 // install runtimes
23- fetchRuntimes (cfg .Config . Runtimes (), cfg . Config . RuntimesDirectory () )
19+ fetchRuntimes (& cfg .Config )
2420 // install tools
25- for _ , r := range cfg .Config .Runtimes () {
26- fetchTools (r , cfg .Config .RuntimesDirectory (), cfg .Config .ToolsDirectory ())
27- }
21+ fetchTools (& cfg .Config )
2822 },
2923}
3024
31- func fetchRuntimes (runtimes map [ string ] * cfg.Runtime , runtimesDirectory string ) {
32- for _ , r := range runtimes {
25+ func fetchRuntimes (config * cfg.ConfigType ) {
26+ for _ , r := range config . Runtimes () {
3327 switch r .Name () {
3428 case "node" :
35- // TODO should delete downloaded archive
36- // TODO check for deflated archive
37- log .Println ("Fetching node..." )
38- downloadNodeURL := cfg .GetNodeDownloadURL (r )
39- nodeTar , err := utils .DownloadFile (downloadNodeURL , runtimesDirectory )
40- if err != nil {
41- log .Fatal (err )
42- }
43-
44- // deflate node archive
45- t , err := os .Open (nodeTar )
46- defer t .Close ()
47- if err != nil {
48- log .Fatal (err )
49- }
50- err = utils .ExtractTarGz (t , runtimesDirectory )
29+ err := cfg .InstallNode (r )
5130 if err != nil {
5231 log .Fatal (err )
5332 }
@@ -57,13 +36,16 @@ func fetchRuntimes(runtimes map[string]*cfg.Runtime, runtimesDirectory string) {
5736 }
5837}
5938
60- func fetchTools (runtime * cfg.Runtime , runtimesDirectory string , toolsDirectory string ) {
61- for _ , tool := range runtime .Tools () {
39+ func fetchTools (config * cfg.ConfigType ) {
40+ for _ , tool := range config .Tools () {
6241 switch tool .Name () {
6342 case "eslint" :
64- npmPath := filepath .Join (runtimesDirectory , cfg .GetNodeFileName (runtime ),
65- "bin" , "npm" )
66- toolutils .InstallESLint (npmPath , "eslint@" + tool .Version (), toolsDirectory )
43+ // eslint needs node runtime
44+ nodeRuntime := config .Runtimes ()["node" ]
45+ err := cfg .InstallEslint (nodeRuntime , tool )
46+ if err != nil {
47+ log .Fatal (err )
48+ }
6749 default :
6850 log .Fatal ("Unknown tool:" , tool .Name ())
6951 }
0 commit comments