Run npm commands for building in build.rs

This commit is contained in:
jeff 2021-01-03 14:07:11 +00:00
parent 41a8514c00
commit c99a41bcbd
2 changed files with 36 additions and 5 deletions

View File

@ -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() { fn main() {
//TODO println!("cargo:rerun-if-changed=static/scripts/webpack.config.js");
// - invoke npm install? js_protos();
// - invoke protoc to build ts/js protos webpack();
// - invoke npm run webpack from ts directory
let mut config = prost_build::Config::new(); let mut config = prost_build::Config::new();
config.btree_map(&["."]); config.btree_map(&["."]);

View File

@ -6,7 +6,7 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "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", "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" "build:webpack": "cd static/scripts && webpack"
}, },
"repository": { "repository": {