Add makefile and use protobufjs

This commit is contained in:
Ryan Dahl 2018-05-14 01:11:56 -04:00
parent 04df88912d
commit be7828684b
4 changed files with 34 additions and 4 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ dist/
deno deno
assets.go assets.go
msg.pb.go msg.pb.go
msg.pb.js
msg.pb.d.ts

29
Makefile Normal file
View File

@ -0,0 +1,29 @@
deno: assets.go msg.pb.go main.go
go build -o deno
assets.go: dist/main.js
go-bindata -pkg main -o assets.go dist/
msg.pb.go: msg.proto
protoc --go_out=. msg.proto
msg.pb.js: msg.proto node_modules
./node_modules/.bin/pbjs -t static-module -w commonjs -o msg.pb.js msg.proto
msg.pb.d.ts: msg.pb.js node_modules
./node_modules/.bin/pbts -o msg.pb.d.ts msg.pb.js
dist/main.js: main.ts msg.pb.js msg.pb.d.ts node_modules
./node_modules/.bin/parcel build --out-dir=dist/ --no-minify main.ts
node_modules:
yarn
clean:
-rm -f deno assets.go msg.pb.go msg.pb.js msg.pb.d.ts
-rm -rf dist/
distclean: clean
-rm -rf node_modules/
.PHONY: clean distclean

View File

@ -1,9 +1,5 @@
package main package main
//go:generate protoc --go_out=. msg.proto
//go:generate ./node_modules/.bin/parcel build --out-dir=dist/ --no-minify main.ts
//go:generate go-bindata -pkg $GOPACKAGE -o assets.go dist/
import ( import (
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/ry/v8worker2" "github.com/ry/v8worker2"

View File

@ -1,7 +1,10 @@
import * as ts from "typescript"; import * as ts from "typescript";
import { main as pb } from "./msg.pb"
V8Worker2.recv((ab: ArrayBuffer) { V8Worker2.recv((ab: ArrayBuffer) {
let msg = pb.Msg.decode(new Uint8Array(ab));
V8Worker2.print("Got array buffer", ab.byteLength); V8Worker2.print("Got array buffer", ab.byteLength);
V8Worker2.print("msg.argv", msg.argv);
}); });
V8Worker2.print("Hello"); V8Worker2.print("Hello");