Add an option to detect node at runtime

Sometimes builds are done once and used in both the browser and in node, so add
an option to do runtime detection if necessary
This commit is contained in:
Alex Crichton
2018-03-07 08:50:56 -08:00
parent 48c0f290f9
commit 8254d9f516
5 changed files with 59 additions and 14 deletions

View File

@ -15,6 +15,7 @@ pub struct Project {
files: Vec<(String, String)>,
debug: bool,
js: bool,
detect_node: bool,
}
pub fn project() -> Project {
@ -28,6 +29,7 @@ pub fn project() -> Project {
Project {
debug: true,
js: false,
detect_node: false,
files: vec![
("Cargo.toml".to_string(), format!(r#"
[package]
@ -130,6 +132,11 @@ impl Project {
self
}
pub fn detect_node(&mut self, detect_node: bool) -> &mut Project {
self.detect_node = detect_node;
self
}
pub fn js(&mut self, js: bool) -> &mut Project {
self.js = js;
self
@ -171,6 +178,7 @@ impl Project {
cli::Bindgen::new()
.input_path(&as_a_module)
.nodejs(true)
.nodejs_runtime_detect(self.detect_node)
.typescript(true)
.debug(self.debug)
.generate(&root)