Add bundler

This commit is contained in:
Dmitry Shulyak 2018-03-26 13:29:36 +03:00
parent 85508ec613
commit 753374c148
1 changed files with 46 additions and 0 deletions

46
cmd/bundler.go Normal file
View File

@ -0,0 +1,46 @@
package main
import (
"bytes"
"flag"
"fmt"
"io"
"io/ioutil"
"os"
)
var (
src = flag.String("src", "web3.js", "web3.js source file")
dst = flag.String("dst", "", "destination file. leave empty to print into stdout")
pkg = flag.String("pkg", "web3js", "package of the destionation file")
)
func main() {
flag.Parse()
data, err := ioutil.ReadFile(*src)
must(err)
b := bytes.NewBuffer([]byte{})
fmt.Fprintf(b, "// Code is generated. DO NOT EDIT.\n\n")
fmt.Fprintf(b, "package %s\n\n", *pkg)
fmt.Fprintf(b, "// Web3CODE is a binary representation of web3js mini.\n")
fmt.Fprintf(b, "var Web3CODE = []byte{")
last := len(data) - 1
for i, byt := range data {
fmt.Fprint(b, byt)
if i != last {
fmt.Fprint(b, ", ")
}
}
fmt.Fprintf(b, "}\n")
if *dst == "" {
io.Copy(os.Stdout, b)
} else {
must(ioutil.WriteFile(*dst, b.Bytes(), 0644))
}
}
func must(err error) {
if err != nil {
panic(err)
}
}