Run npm commands for building in build.rs
This commit is contained in:
parent
41a8514c00
commit
c99a41bcbd
39
build.rs
39
build.rs
|
@ -1,8 +1,39 @@
|
|||
use std::process::Command;
|
||||
|
||||
fn js_protos() {
|
||||
let output = Command::new("npm")
|
||||
.arg("run")
|
||||
.arg("build:protobuf")
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
if output.status.success() {
|
||||
return;
|
||||
} else {
|
||||
let err = String::from_utf8(output.stderr).unwrap();
|
||||
panic!("JS Protobuf build failure:\n {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
fn webpack() {
|
||||
let output = Command::new("npm")
|
||||
.arg("run")
|
||||
.arg("build:webpack")
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
if output.status.success() {
|
||||
return;
|
||||
} else {
|
||||
let err = String::from_utf8(output.stderr).unwrap();
|
||||
panic!("Webpack build failure:\n {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
//TODO
|
||||
// - invoke npm install?
|
||||
// - invoke protoc to build ts/js protos
|
||||
// - invoke npm run webpack from ts directory
|
||||
println!("cargo:rerun-if-changed=static/scripts/webpack.config.js");
|
||||
js_protos();
|
||||
webpack();
|
||||
|
||||
let mut config = prost_build::Config::new();
|
||||
config.btree_map(&["."]);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"webpack-dev": "cd static/scripts && webpack serve --watch --inline --port 8081 --host 0.0.0.0 --output-path=./build",
|
||||
"build:protobuf": "mkdir -p static/scripts/_proto && protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts -I ./proto --js_out=import_style=commonjs,binary:./static/scripts/ts/_proto --ts_out=service=grpc-web:./static/scripts/ts/_proto ./proto/*.proto",
|
||||
"build:protobuf": "mkdir -p static/scripts/_proto && protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts -I ./proto --js_out=import_style=commonjs,binary:./static/scripts/_proto --ts_out=service=grpc-web:./static/scripts/_proto ./proto/*.proto",
|
||||
"build:webpack": "cd static/scripts && webpack"
|
||||
},
|
||||
"repository": {
|
||||
|
|
Loading…
Reference in New Issue