2014-11-16 20:13:20 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 19:43:32 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU General Public License as published by the Free
|
|
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
// more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-06-01 20:50:14 +00:00
|
|
|
|
2014-07-31 10:30:19 +00:00
|
|
|
// +build ignore
|
|
|
|
|
2014-03-17 21:56:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"compress/gzip"
|
2014-09-01 16:19:19 +00:00
|
|
|
"encoding/base64"
|
2014-03-17 21:56:07 +00:00
|
|
|
"flag"
|
|
|
|
"go/format"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2014-12-06 12:46:02 +00:00
|
|
|
"strings"
|
2014-03-17 21:56:07 +00:00
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
var tpl = template.Must(template.New("assets").Parse(`package auto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"compress/gzip"
|
2014-09-01 16:19:19 +00:00
|
|
|
"encoding/base64"
|
2014-03-17 21:56:07 +00:00
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
2014-09-02 11:07:33 +00:00
|
|
|
func Assets() map[string][]byte {
|
|
|
|
var assets = make(map[string][]byte, {{.assets | len}})
|
2014-03-17 21:56:07 +00:00
|
|
|
var bs []byte
|
|
|
|
var gr *gzip.Reader
|
|
|
|
{{range $asset := .assets}}
|
2014-09-01 16:19:19 +00:00
|
|
|
bs, _ = base64.StdEncoding.DecodeString("{{$asset.Data}}")
|
2014-03-17 21:56:07 +00:00
|
|
|
gr, _ = gzip.NewReader(bytes.NewBuffer(bs))
|
|
|
|
bs, _ = ioutil.ReadAll(gr)
|
2014-09-02 11:07:33 +00:00
|
|
|
assets["{{$asset.Name}}"] = bs
|
2014-03-17 21:56:07 +00:00
|
|
|
{{end}}
|
2014-09-02 11:07:33 +00:00
|
|
|
return assets
|
2014-03-17 21:56:07 +00:00
|
|
|
}
|
|
|
|
`))
|
|
|
|
|
|
|
|
type asset struct {
|
2014-09-01 16:19:19 +00:00
|
|
|
Name string
|
|
|
|
Data string
|
2014-03-17 21:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var assets []asset
|
|
|
|
|
|
|
|
func walkerFor(basePath string) filepath.WalkFunc {
|
|
|
|
return func(name string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-12-06 12:46:02 +00:00
|
|
|
if strings.HasPrefix(filepath.Base(name), ".") {
|
|
|
|
// Skip dotfiles
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-03-17 21:56:07 +00:00
|
|
|
if info.Mode().IsRegular() {
|
|
|
|
fd, err := os.Open(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
gw := gzip.NewWriter(&buf)
|
|
|
|
io.Copy(gw, fd)
|
|
|
|
fd.Close()
|
|
|
|
gw.Flush()
|
|
|
|
gw.Close()
|
|
|
|
|
|
|
|
name, _ = filepath.Rel(basePath, name)
|
|
|
|
assets = append(assets, asset{
|
2014-09-01 16:19:19 +00:00
|
|
|
Name: filepath.ToSlash(name),
|
|
|
|
Data: base64.StdEncoding.EncodeToString(buf.Bytes()),
|
2014-03-17 21:56:07 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
filepath.Walk(flag.Arg(0), walkerFor(flag.Arg(0)))
|
|
|
|
var buf bytes.Buffer
|
|
|
|
tpl.Execute(&buf, map[string][]asset{"assets": assets})
|
|
|
|
bs, err := format.Source(buf.Bytes())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
os.Stdout.Write(bs)
|
|
|
|
}
|