|
|
@ -1,6 +1,7 @@
|
|
1
|
1
|
package detect
|
|
2
|
2
|
|
|
3
|
3
|
import (
|
|
|
4
|
"errors"
|
|
4
|
5
|
"path"
|
|
5
|
6
|
|
|
6
|
7
|
"../fileutil"
|
|
|
@ -18,24 +19,48 @@ type Project struct {
|
|
18
|
19
|
|
|
19
|
20
|
type Commands map[string]string
|
|
20
|
21
|
|
|
21
|
|
var ProjectTypes = []Project{
|
|
22
|
|
Project{"clojure/leiningen", Commands{"run": "lein run", "test": "lein test"}, clojureLeiningen},
|
|
23
|
|
Project{"docker/fig", Commands{"run": "fig up"}, dockerFig},
|
|
24
|
|
Project{"docker/default", Commands{}, dockerDefault},
|
|
25
|
|
Project{"executable/default", Commands{"run": "{file}"}, executableDefault},
|
|
26
|
|
Project{"go/default", Commands{"build": "go build {file}", "run": "go build {file} && $(basename {file} .go)"},
|
|
|
22
|
var ProjectTypes = []*Project{
|
|
|
23
|
&Project{"clojure/leiningen", Commands{"run": "lein run", "test": "lein test"}, clojureLeiningen},
|
|
|
24
|
&Project{"docker/fig", Commands{"run": "fig up"}, dockerFig},
|
|
|
25
|
&Project{"docker/default", Commands{}, dockerDefault},
|
|
|
26
|
&Project{"executable/default", Commands{"run": "{file}"}, executableDefault},
|
|
|
27
|
&Project{"go/default", Commands{"build": "go build {file}", "run": "go build {file} && $(basename {file} .go)"},
|
|
27
|
28
|
goDefault},
|
|
28
|
|
Project{"java/maven", Commands{"build": "mvn compile", "test": "mvn compile test"}, javaMaven},
|
|
29
|
|
Project{"javascript/npm", Commands{}, javascriptNpm},
|
|
30
|
|
Project{"javascript/meteor", Commands{"run": "meteor"}, javascriptMeteor},
|
|
31
|
|
Project{"javascript/default", Commands{"run": "node {file}"}, javascriptDefault},
|
|
32
|
|
Project{"make/default", Commands{"run": "make"}, makeDefault},
|
|
33
|
|
Project{"procfile/default", Commands{}, procfileDefault},
|
|
34
|
|
Project{"python/django", Commands{}, pythonDjango},
|
|
35
|
|
Project{"python/default", Commands{"run": "python {file}"}, pythonDefault},
|
|
36
|
|
Project{"ruby/rails", Commands{"run": "rails server", "test": "bundle exec rake test"}, rubyRails},
|
|
37
|
|
Project{"ruby/rake", Commands{"run": "rake"}, rubyRake},
|
|
38
|
|
Project{"ruby/default", Commands{"run": "ruby {file}"}, rubyDefault},
|
|
|
29
|
&Project{"java/maven", Commands{"build": "mvn compile", "test": "mvn compile test"}, javaMaven},
|
|
|
30
|
&Project{"javascript/npm", Commands{}, javascriptNpm},
|
|
|
31
|
&Project{"javascript/meteor", Commands{"run": "meteor"}, javascriptMeteor},
|
|
|
32
|
&Project{"javascript/default", Commands{"run": "node {file}"}, javascriptDefault},
|
|
|
33
|
&Project{"make/default", Commands{"run": "make"}, makeDefault},
|
|
|
34
|
&Project{"procfile/default", Commands{}, procfileDefault},
|
|
|
35
|
&Project{"python/django", Commands{}, pythonDjango},
|
|
|
36
|
&Project{"python/default", Commands{"run": "python {file}"}, pythonDefault},
|
|
|
37
|
&Project{"ruby/rails", Commands{"run": "rails server", "test": "bundle exec rake test"}, rubyRails},
|
|
|
38
|
&Project{"ruby/rake", Commands{"run": "rake"}, rubyRake},
|
|
|
39
|
&Project{"ruby/default", Commands{"run": "ruby {file}"}, rubyDefault},
|
|
|
40
|
}
|
|
|
41
|
|
|
|
42
|
func Detect(file string) (*Project, error) {
|
|
|
43
|
for _, project := range ProjectTypes {
|
|
|
44
|
if project.Detect(file) {
|
|
|
45
|
return project, nil
|
|
|
46
|
}
|
|
|
47
|
}
|
|
|
48
|
|
|
|
49
|
return nil, errors.New("no project matches")
|
|
|
50
|
}
|
|
|
51
|
|
|
|
52
|
func DetectAll(file string) []*Project {
|
|
|
53
|
projects := make([]*Project, 0, len(ProjectTypes))
|
|
|
54
|
|
|
|
55
|
for _, project := range ProjectTypes {
|
|
|
56
|
if project.Detect(file) {
|
|
|
57
|
n := len(projects)
|
|
|
58
|
projects = projects[0 : n+1]
|
|
|
59
|
projects[n] = project
|
|
|
60
|
}
|
|
|
61
|
}
|
|
|
62
|
|
|
|
63
|
return projects
|
|
39
|
64
|
}
|
|
40
|
65
|
|
|
41
|
66
|
func matchingFileOrDir(file string, pattern string) bool {
|