Lucas Stadler лет назад: 11
Родитель
Сommit
f4953030cd
2 измененных файлов с 50 добавлено и 0 удалено
  1. 40 0
      go/detect.go
  2. 10 0
      go/fileutil/fileutil.go

+ 40 - 0
go/detect.go

@ -26,9 +26,17 @@ type Detector struct {
26 26
27 27
var Detectors = []Detector{
28 28
	{Detection{"clojure", "leiningen"}, clojureLeiningen},
29
	{Detection{"docker", "fig"}, dockerFig},
30
	{Detection{"docker", "default"}, dockerDefault},
31
	{Detection{"executable", "default"}, executableDefault},
29 32
	{Detection{"go", "default"}, goDefault},
30 33
	{Detection{"java", "maven"}, javaMaven},
34
	{Detection{"javascript", "npm"}, javascriptNpm},
35
	{Detection{"javascript", "meteor"}, javascriptMeteor},
36
	{Detection{"javascript", "default"}, javascriptDefault},
31 37
	{Detection{"make", "default"}, makeDefault},
38
	{Detection{"procfile", "default"}, procfileDefault},
39
	{Detection{"python", "django"}, pythonDjango},
32 40
	{Detection{"python", "default"}, pythonDefault},
33 41
	{Detection{"ruby", "rails"}, rubyRails},
34 42
	{Detection{"ruby", "rake"}, rubyRake},
@ -66,6 +74,18 @@ func clojureLeiningen(file string) bool {
66 74
	return hasFile(file, "project.clj")
67 75
}
68 76
77
func dockerFig(file string) bool {
78
	return hasFile(file, "fig.yml")
79
}
80
81
func dockerDefault(file string) bool {
82
	return hasFile(file, "Dockerfile")
83
}
84
85
func executableDefault(file string) bool {
86
	return fileutil.IsExecutable(file)
87
}
88
69 89
func goDefault(file string) bool {
70 90
	return matchingFileOrDir(file, "*.go")
71 91
}
@ -74,10 +94,30 @@ func javaMaven(file string) bool {
74 94
	return hasFile(file, "pom.xml")
75 95
}
76 96
97
func javascriptNpm(file string) bool {
98
	return hasFile(file, "package.json")
99
}
100
101
func javascriptMeteor(file string) bool {
102
	return hasFile(file, ".meteor/.id")
103
}
104
105
func javascriptDefault(file string) bool {
106
	return matchingFileOrDir(file, "*.js")
107
}
108
77 109
func makeDefault(file string) bool {
78 110
	return hasFile(file, "Makefile")
79 111
}
80 112
113
func procfileDefault(file string) bool {
114
	return hasFile(file, "Procfile")
115
}
116
117
func pythonDjango(file string) bool {
118
	return hasFile(file, "manage.py")
119
}
120
81 121
func pythonDefault(file string) bool {
82 122
	return matchingFileOrDir(file, "*.py")
83 123
}

+ 10 - 0
go/fileutil/fileutil.go

@ -34,3 +34,13 @@ func Join(fileOrDir string, elem ...string) string {
34 34
	}
35 35
	return path.Join(dir, path.Join(elem...))
36 36
}
37
38
func IsExecutable(file string) bool {
39
	info, err := os.Stat(file)
40
	if err != nil {
41
		return false
42
	}
43
44
	isExecutable := info.Mode() & 0111
45
	return isExecutable != 0 && !info.IsDir()
46
}