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 (
|
2017-04-19 09:24:01 +00:00
|
|
|
// languages info file
|
|
|
|
languagesYAML = ".linguist/lib/linguist/languages.yml"
|
|
|
|
|
2017-05-29 08:05:16 +00:00
|
|
|
// extension.go generation
|
|
|
|
extensionsFile = "extension.go"
|
2017-04-19 09:24:01 +00:00
|
|
|
extensionsTmplPath = "internal/code-generator/assets/extensions.go.tmpl"
|
|
|
|
extensionsTmpl = "extensions.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"
|
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-05-29 08:05:16 +00:00
|
|
|
// vendor.go generation
|
2017-04-07 07:25:49 +00:00
|
|
|
vendorYAML = ".linguist/lib/linguist/vendor.yml"
|
2017-05-29 08:05:16 +00:00
|
|
|
vendorFile = "vendor.go"
|
2017-04-07 07:25:49 +00:00
|
|
|
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
|
2017-04-10 09:30:23 +00:00
|
|
|
documentationYAML = ".linguist/lib/linguist/documentation.yml"
|
2017-05-29 08:05:16 +00:00
|
|
|
documentationFile = "documentation.go"
|
2017-04-10 09:30:23 +00:00
|
|
|
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-05-04 13:03:54 +00:00
|
|
|
typeTmplPath = "internal/code-generator/assets/types.go.tmpl"
|
|
|
|
typeTmpl = "types.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-04-17 06:14:46 +00:00
|
|
|
interpretersTmplPath = "internal/code-generator/assets/interpreters.go.tmpl"
|
|
|
|
interpretersTmpl = "interpreters.go.tmpl"
|
|
|
|
|
2017-05-29 08:05:16 +00:00
|
|
|
// filename.go generation
|
|
|
|
filenamesFile = "filename.go"
|
2017-04-19 08:22:46 +00:00
|
|
|
filenamesTmplPath = "internal/code-generator/assets/filenames.go.tmpl"
|
|
|
|
filenamesTmpl = "filenames.go.tmpl"
|
|
|
|
|
2017-05-29 08:05:16 +00:00
|
|
|
// alias.go generation
|
|
|
|
aliasesFile = "alias.go"
|
2017-05-04 13:03:54 +00:00
|
|
|
aliasesTmplPath = "internal/code-generator/assets/aliases.go.tmpl"
|
|
|
|
aliasesTmpl = "aliases.go.tmpl"
|
|
|
|
|
2017-05-25 10:33:26 +00:00
|
|
|
// frequencies.go generation
|
|
|
|
samplesDir = ".linguist/samples"
|
|
|
|
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-04-11 09:26:23 +00:00
|
|
|
type generatorArgs struct {
|
|
|
|
fileToParse string
|
|
|
|
outPath string
|
|
|
|
tmplPath string
|
|
|
|
tmplName string
|
|
|
|
commit string
|
|
|
|
generate generator.Func
|
|
|
|
}
|
|
|
|
|
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-04-11 09:26:23 +00:00
|
|
|
argsList := []*generatorArgs{
|
2017-04-19 09:24:01 +00:00
|
|
|
&generatorArgs{languagesYAML, extensionsFile, extensionsTmplPath, extensionsTmpl, commit, generator.Extensions},
|
2017-04-11 09:26:23 +00:00
|
|
|
&generatorArgs{heuristicsRuby, contentFile, contentTmplPath, contentTmpl, commit, generator.Heuristics},
|
|
|
|
&generatorArgs{vendorYAML, vendorFile, vendorTmplPath, vendorTmpl, commit, generator.Vendor},
|
|
|
|
&generatorArgs{documentationYAML, documentationFile, documentationTmplPath, documentationTmpl, commit, generator.Documentation},
|
|
|
|
&generatorArgs{languagesYAML, typeFile, typeTmplPath, typeTmpl, commit, generator.Types},
|
2017-04-17 06:19:53 +00:00
|
|
|
&generatorArgs{languagesYAML, interpretersFile, interpretersTmplPath, interpretersTmpl, commit, generator.Interpreters},
|
2017-04-19 08:22:46 +00:00
|
|
|
&generatorArgs{languagesYAML, filenamesFile, filenamesTmplPath, filenamesTmpl, commit, generator.Filenames},
|
2017-05-04 13:03:54 +00:00
|
|
|
&generatorArgs{languagesYAML, aliasesFile, aliasesTmplPath, aliasesTmpl, commit, generator.Aliases},
|
2017-04-06 15:31:17 +00:00
|
|
|
}
|
2017-04-10 09:30:23 +00:00
|
|
|
|
2017-04-11 09:26:23 +00:00
|
|
|
for _, args := range argsList {
|
|
|
|
if err := generator.FromFile(args.fileToParse, args.outPath, args.tmplPath, args.tmplName, args.commit, args.generate); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2017-04-10 09:30:23 +00:00
|
|
|
}
|
2017-05-25 10:33:26 +00:00
|
|
|
|
|
|
|
if err := generator.Frequencies(samplesDir, frequenciesTmplPath, frequenciesTmpl, commit, frequenciesFile); err != nil {
|
|
|
|
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
|
|
|
|
}
|