2017-04-04 11:10:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
|
2017-04-05 16:26:58 +00:00
|
|
|
"gopkg.in/src-d/simple-linguist.v1/internal/code-generator/generator"
|
2017-04-04 11:10:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
languagesYAML = ".linguist/lib/linguist/languages.yml"
|
|
|
|
langFile = "languages.go"
|
2017-04-05 15:49:58 +00:00
|
|
|
languagesTmplPath = "internal/code-generator/assets/languages.go.tmpl"
|
2017-04-04 11:10:35 +00:00
|
|
|
languagesTmpl = "languages.go.tmpl"
|
|
|
|
|
|
|
|
heuristicsRuby = ".linguist/lib/linguist/heuristics.rb"
|
|
|
|
contentFile = "content.go"
|
2017-04-05 15:49:58 +00:00
|
|
|
contentTmplPath = "internal/code-generator/assets/content.go.tmpl"
|
2017-04-04 11:10:35 +00:00
|
|
|
contentTmpl = "content.go.tmpl"
|
|
|
|
|
2017-04-07 07:25:49 +00:00
|
|
|
vendorYAML = ".linguist/lib/linguist/vendor.yml"
|
|
|
|
vendorFile = "vendor_matchers.go"
|
|
|
|
vendorTmplPath = "internal/code-generator/assets/vendor.go.tmpl"
|
|
|
|
vendorTmpl = "vendor.go.tmpl"
|
2017-04-06 15:31:17 +00:00
|
|
|
|
2017-04-04 11:10:35 +00:00
|
|
|
commitPath = ".git/refs/heads/master"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
commit, err := getCommit(commitPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("couldn't find commit: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := generator.FromFile(languagesYAML, langFile, languagesTmplPath, languagesTmpl, commit, generator.Languages); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2017-04-05 14:01:31 +00:00
|
|
|
|
|
|
|
if err := generator.FromFile(heuristicsRuby, contentFile, contentTmplPath, contentTmpl, commit, generator.Heuristics); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2017-04-06 15:31:17 +00:00
|
|
|
|
2017-04-07 07:25:49 +00:00
|
|
|
if err := generator.FromFile(vendorYAML, vendorFile, vendorTmplPath, vendorTmpl, commit, generator.Vendor); err != nil {
|
2017-04-06 15:31:17 +00:00
|
|
|
log.Println(err)
|
|
|
|
}
|
2017-04-04 11:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getCommit(path string) (string, error) {
|
|
|
|
commit, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(commit), nil
|
|
|
|
}
|