Skip to content

Commit 45077af

Browse files
committed
added eslint installation, added script creation
1 parent 3d9a9ed commit 45077af

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

.codacy/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
runtimes
1+
runtimes
2+
tools

cli-v2.go

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"net/http"
1010
"os"
11+
"os/exec"
1112
"path/filepath"
1213
"runtime"
1314

@@ -110,23 +111,22 @@ func extract(t *os.File) {
110111

111112
fmt.Printf("Contents of %s:\n", f.NameInArchive)
112113

113-
// fmt.Printf("isDir: %s\n", f.IsDir())
114-
115-
f.Mode()
114+
path := ".codacy/runtimes/" + f.NameInArchive
116115

117116
switch f.IsDir() {
118117
case true:
119118
// create a directory
120119
fmt.Println("creating: " + f.NameInArchive)
121-
err := os.MkdirAll(f.NameInArchive, 0777)
120+
err := os.MkdirAll(path, 0777)
122121
if err != nil {
123122
log.Fatal(err)
124123
}
125124

126125
case false:
127126

128127
if f.LinkTarget != "" {
129-
err := os.Symlink(f.LinkTarget, f.NameInArchive)
128+
os.Remove(path)
129+
err := os.Symlink(f.LinkTarget, path)
130130
if err != nil {
131131
log.Fatal(err)
132132
}
@@ -137,7 +137,7 @@ func extract(t *os.File) {
137137
// write a file
138138
fmt.Println("extracting: " + f.NameInArchive)
139139
fmt.Println("targe link: " + f.LinkTarget)
140-
w, err := os.OpenFile(f.NameInArchive, os.O_RDWR|os.O_CREATE|os.O_TRUNC, f.Mode())
140+
w, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, f.Mode())
141141
if err != nil {
142142
log.Fatal(err)
143143
}
@@ -162,6 +162,52 @@ func extract(t *os.File) {
162162

163163
}
164164

165+
func installESLint(npmExecutablePath string, ESLintversion string) {
166+
167+
fmt.Println("Installing ESLint")
168+
169+
cmd := exec.Command(npmExecutablePath, "install", "--prefix", "./.codacy/tools/"+ESLintversion, ESLintversion)
170+
stdout, err := cmd.Output()
171+
172+
// Print the output
173+
fmt.Println(string(stdout))
174+
175+
if err != nil {
176+
fmt.Println(err.Error())
177+
return
178+
}
179+
180+
workingDirectory, _ := os.Getwd()
181+
182+
nodeVersion := "22.2.0-darwin-x64"
183+
184+
// TODO clean eslint version
185+
186+
scriptContent := fmt.Sprintf(`
187+
#!/bin/sh
188+
189+
export PATH="%s/.codacy/tools/%s/node_modules/.bin:%s/node-v%s/bin:${PATH}"
190+
export HOME="${HOME:-}"
191+
export NODE_PATH="%s/.codacy/tools/%s/node_modules"
192+
193+
194+
exec eslint "$@"
195+
196+
`, workingDirectory, ESLintversion, workingDirectory, nodeVersion, workingDirectory, ESLintversion)
197+
198+
w, err := os.OpenFile(".codacy/tools/"+ESLintversion+"/eslint.sh", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0770)
199+
defer w.Close()
200+
201+
if err != nil {
202+
log.Fatal(err)
203+
}
204+
205+
_, err = io.WriteString(w, scriptContent)
206+
if err != nil {
207+
log.Fatal(err)
208+
}
209+
}
210+
165211
func main() {
166212
content, err := os.ReadFile(".codacy/codacy.yaml")
167213
if err != nil {
@@ -174,14 +220,15 @@ func main() {
174220
}
175221

176222
fmt.Println(config)
177-
downloadURL := getNodeDownloadURL("v22.2.0")
178-
nodeTar, _ := downloadFile(downloadURL, ".codacy")
179-
fmt.Println(nodeTar)
223+
downloadNodeURL := getNodeDownloadURL("v22.2.0")
224+
nodeTar, _ := downloadFile(downloadNodeURL, ".codacy")
180225

181226
t, _ := os.Open(nodeTar)
182227
defer t.Close()
183228

184229
extract(t)
185230

231+
installESLint(".codacy/runtimes/node-v22.2.0-darwin-x64/bin/npm", "[email protected]")
232+
186233
cmd.Execute()
187234
}

0 commit comments

Comments
 (0)