mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 08:16:31 +00:00
Rename directories to remove "wasm-bindgen-" prefix in sub-crates
This commit is contained in:
69
crates/cli/src/bin/wasm-bindgen.rs
Normal file
69
crates/cli/src/bin/wasm-bindgen.rs
Normal file
@ -0,0 +1,69 @@
|
||||
extern crate wasm_bindgen_cli_support;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate docopt;
|
||||
extern crate wasm_bindgen_shared;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use docopt::Docopt;
|
||||
use wasm_bindgen_cli_support::Bindgen;
|
||||
|
||||
const USAGE: &'static str = "
|
||||
Generating JS bindings for a wasm file
|
||||
|
||||
Usage:
|
||||
wasm-bindgen [options] <input>
|
||||
wasm-bindgen -h | --help
|
||||
wasm-bindgen -V | --version
|
||||
|
||||
Options:
|
||||
-h --help Show this screen.
|
||||
--out-dir DIR Output directory
|
||||
--nodejs Generate output that only works in node.js
|
||||
--browser Generate output that only works in a browser
|
||||
--typescript Output a TypeScript definition file
|
||||
--debug Include otherwise-extraneous debug checks in output
|
||||
-V --version Print the version number of wasm-bindgen
|
||||
";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Args {
|
||||
flag_nodejs: bool,
|
||||
flag_browser: bool,
|
||||
flag_typescript: bool,
|
||||
flag_out_dir: Option<PathBuf>,
|
||||
flag_debug: bool,
|
||||
flag_version: bool,
|
||||
arg_input: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Args = Docopt::new(USAGE)
|
||||
.and_then(|d| d.deserialize())
|
||||
.unwrap_or_else(|e| e.exit());
|
||||
|
||||
if args.flag_version {
|
||||
println!("wasm-bindgen {}", wasm_bindgen_shared::version());
|
||||
return
|
||||
}
|
||||
|
||||
let input = match args.arg_input {
|
||||
Some(s) => s,
|
||||
None => panic!("input file expected"),
|
||||
};
|
||||
|
||||
let mut b = Bindgen::new();
|
||||
b.input_path(&input)
|
||||
.nodejs(args.flag_nodejs)
|
||||
.browser(args.flag_browser)
|
||||
.debug(args.flag_debug)
|
||||
.typescript(args.flag_typescript);
|
||||
|
||||
let out_dir = match args.flag_out_dir {
|
||||
Some(ref p) => p,
|
||||
None => panic!("the `--out-dir` argument is now required"),
|
||||
};
|
||||
|
||||
b.generate(out_dir).expect("failed to generate bindings");
|
||||
}
|
76
crates/cli/src/bin/wasm2es6js.rs
Normal file
76
crates/cli/src/bin/wasm2es6js.rs
Normal file
@ -0,0 +1,76 @@
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate docopt;
|
||||
extern crate parity_wasm;
|
||||
extern crate wasm_bindgen_cli_support;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{Write, Read};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use docopt::Docopt;
|
||||
|
||||
const USAGE: &'static str = "
|
||||
Converts a wasm file to an ES6 JS module
|
||||
|
||||
Usage:
|
||||
wasm2es6js [options] <input>
|
||||
wasm2es6js -h | --help
|
||||
|
||||
Options:
|
||||
-h --help Show this screen.
|
||||
-o --output FILE File to place output in
|
||||
--typescript Output a `*.d.ts` file next to the JS output
|
||||
--base64 Inline the wasm module using base64 encoding
|
||||
|
||||
Note that this is not intended to produce a production-ready output module
|
||||
but rather is intended purely as a temporary \"hack\" until it's standard in
|
||||
bundlers for working with wasm. Use this program with care!
|
||||
";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Args {
|
||||
flag_output: Option<PathBuf>,
|
||||
flag_typescript: bool,
|
||||
flag_base64: bool,
|
||||
arg_input: PathBuf,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Args = Docopt::new(USAGE)
|
||||
.and_then(|d| d.deserialize())
|
||||
.unwrap_or_else(|e| e.exit());
|
||||
|
||||
if !args.flag_base64 {
|
||||
panic!("unfortunately only works right now with base64");
|
||||
}
|
||||
|
||||
let mut wasm = Vec::new();
|
||||
File::open(&args.arg_input).expect("failed to open input")
|
||||
.read_to_end(&mut wasm).expect("failed to read input");
|
||||
|
||||
let object = wasm_bindgen_cli_support::wasm2es6js::Config::new()
|
||||
.base64(args.flag_base64)
|
||||
.generate(&wasm)
|
||||
.expect("failed to parse wasm");
|
||||
|
||||
if args.flag_typescript {
|
||||
if let Some(ref p) = args.flag_output {
|
||||
let dst = p.with_extension("d.ts");
|
||||
File::create(dst).expect("failed to create output")
|
||||
.write_all(object.typescript().as_bytes()).expect("failed to write output");
|
||||
}
|
||||
}
|
||||
|
||||
let js = object.js();
|
||||
|
||||
match args.flag_output {
|
||||
Some(ref p) => {
|
||||
File::create(p).expect("failed to create output")
|
||||
.write_all(js.as_bytes()).expect("failed to write output");
|
||||
}
|
||||
None => {
|
||||
println!("{}", js);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user