tartrazine/internal/code-generator/main.go

111 lines
3.7 KiB
Go
Raw Normal View History

2017-04-04 11:10:35 +00:00
package main
import (
"io/ioutil"
"log"
2017-06-08 07:27:27 +00:00
"gopkg.in/src-d/enry.v1/internal/code-generator/generator"
2017-04-04 11:10:35 +00:00
)
const (
// languages info file
languagesYAML = ".linguist/lib/linguist/languages.yml"
2017-06-13 11:56:07 +00:00
// linguist's samples directory
samplesDir = ".linguist/samples"
2017-05-29 08:05:16 +00:00
// extension.go generation
extensionsFile = "extension.go"
2017-06-12 11:42:20 +00:00
extensionsTmplPath = "internal/code-generator/assets/extension.go.tmpl"
extensionsTmpl = "extension.go.tmpl"
2017-04-04 11:10:35 +00:00
2017-04-11 10:10:05 +00:00
// content.go generation
2017-04-04 11:10:35 +00:00
heuristicsRuby = ".linguist/lib/linguist/heuristics.rb"
contentFile = "content.go"
contentTmplPath = "internal/code-generator/assets/content.go.tmpl"
2017-04-04 11:10:35 +00:00
contentTmpl = "content.go.tmpl"
2017-05-29 08:05:16 +00:00
// vendor.go generation
vendorYAML = ".linguist/lib/linguist/vendor.yml"
2017-05-29 08:05:16 +00:00
vendorFile = "vendor.go"
vendorTmplPath = "internal/code-generator/assets/vendor.go.tmpl"
vendorTmpl = "vendor.go.tmpl"
2017-04-06 15:31:17 +00:00
2017-05-29 08:05:16 +00:00
// documentation.go generation
documentationYAML = ".linguist/lib/linguist/documentation.yml"
2017-05-29 08:05:16 +00:00
documentationFile = "documentation.go"
documentationTmplPath = "internal/code-generator/assets/documentation.go.tmpl"
documentationTmpl = "documentation.go.tmpl"
2017-04-11 10:10:05 +00:00
// type.go generation
2017-05-29 08:05:16 +00:00
typeFile = "type.go"
2017-06-12 11:42:20 +00:00
typeTmplPath = "internal/code-generator/assets/type.go.tmpl"
typeTmpl = "type.go.tmpl"
2017-04-11 09:26:23 +00:00
2017-05-29 08:05:16 +00:00
// interpreter.go generation
interpretersFile = "interpreter.go"
2017-06-12 11:42:20 +00:00
interpretersTmplPath = "internal/code-generator/assets/interpreter.go.tmpl"
interpretersTmpl = "interpreter.go.tmpl"
2017-05-29 08:05:16 +00:00
// filename.go generation
filenamesFile = "filename.go"
2017-06-12 11:42:20 +00:00
filenamesTmplPath = "internal/code-generator/assets/filename.go.tmpl"
filenamesTmpl = "filename.go.tmpl"
2017-05-29 08:05:16 +00:00
// alias.go generation
aliasesFile = "alias.go"
2017-06-12 11:42:20 +00:00
aliasesTmplPath = "internal/code-generator/assets/alias.go.tmpl"
aliasesTmpl = "alias.go.tmpl"
2017-05-25 10:33:26 +00:00
// frequencies.go generation
frequenciesFile = "frequencies.go"
frequenciesTmplPath = "internal/code-generator/assets/frequencies.go.tmpl"
frequenciesTmpl = "frequencies.go.tmpl"
commitPath = ".linguist/.git/refs/heads/master"
2017-04-04 11:10:35 +00:00
)
2017-06-13 11:56:07 +00:00
type generatorFiles struct {
generate generator.File
2017-04-11 09:26:23 +00:00
fileToParse string
2017-06-13 11:56:07 +00:00
samplesDir string
2017-04-11 09:26:23 +00:00
outPath string
tmplPath string
tmplName string
commit string
}
2017-04-04 11:10:35 +00:00
func main() {
commit, err := getCommit(commitPath)
if err != nil {
log.Printf("couldn't find commit: %v", err)
}
2017-06-13 11:56:07 +00:00
fileList := []*generatorFiles{
&generatorFiles{generator.Extensions, languagesYAML, "", extensionsFile, extensionsTmplPath, extensionsTmpl, commit},
&generatorFiles{generator.Heuristics, heuristicsRuby, "", contentFile, contentTmplPath, contentTmpl, commit},
&generatorFiles{generator.Vendor, vendorYAML, "", vendorFile, vendorTmplPath, vendorTmpl, commit},
&generatorFiles{generator.Documentation, documentationYAML, "", documentationFile, documentationTmplPath, documentationTmpl, commit},
&generatorFiles{generator.Types, languagesYAML, "", typeFile, typeTmplPath, typeTmpl, commit},
&generatorFiles{generator.Interpreters, languagesYAML, "", interpretersFile, interpretersTmplPath, interpretersTmpl, commit},
&generatorFiles{generator.Filenames, languagesYAML, samplesDir, filenamesFile, filenamesTmplPath, filenamesTmpl, commit},
&generatorFiles{generator.Aliases, languagesYAML, "", aliasesFile, aliasesTmplPath, aliasesTmpl, commit},
&generatorFiles{generator.Frequencies, "", samplesDir, frequenciesFile, frequenciesTmplPath, frequenciesTmpl, commit},
2017-04-06 15:31:17 +00:00
}
2017-06-13 11:56:07 +00:00
for _, file := range fileList {
if err := file.generate(file.fileToParse, file.samplesDir, file.outPath, file.tmplPath, file.tmplName, file.commit); err != nil {
2017-04-11 09:26:23 +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
}