77 lines
1.3 KiB
Go
77 lines
1.3 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
"strings"
|
||
|
"text/template"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
dir := os.Args[1]
|
||
|
|
||
|
files, err := ioutil.ReadDir(dir)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
var str strings.Builder
|
||
|
|
||
|
for _, file := range files {
|
||
|
if name := file.Name(); filepath.Ext(name) == ".gots" {
|
||
|
str.WriteString("\n" + `{{define "`)
|
||
|
str.WriteString(strings.TrimSuffix(name, ".gots"))
|
||
|
str.WriteString(`"}}<script>`)
|
||
|
|
||
|
func() {
|
||
|
in, err := os.Open(filepath.Join(dir, name))
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
defer in.Close()
|
||
|
|
||
|
scanner := bufio.NewScanner(in)
|
||
|
for scanner.Scan() {
|
||
|
line := strings.TrimSpace(scanner.Text())
|
||
|
if line != "" {
|
||
|
str.WriteString(line)
|
||
|
str.WriteRune('\n')
|
||
|
}
|
||
|
}
|
||
|
if err := scanner.Err(); err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
str.WriteString("</script>{{end}}")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
out, err := os.Create("osa_gen_darwin.go")
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
err = generator.Execute(out, str.String())
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
err = out.Close()
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var generator = template.Must(template.New("").Parse(`// Code generated by zenity; DO NOT EDIT.
|
||
|
|
||
|
package zenity
|
||
|
|
||
|
import "html/template"
|
||
|
|
||
|
var osaScripts = template.Must(template.New("").Parse(` + "`{{.}}`" + `))
|
||
|
`))
|