diff --git a/binaryen/.compilerc b/binaryen/.compilerc new file mode 100644 index 0000000..1ecba6f --- /dev/null +++ b/binaryen/.compilerc @@ -0,0 +1,42 @@ +{ + "env": { + "development": { + "application/javascript": { + "presets": [ + [ + "env", + { + "targets": { + "electron": 2 + } + } + ], + "react" + ], + "plugins": [ + "transform-async-to-generator" + ], + "sourceMaps": "inline" + } + }, + "production": { + "application/javascript": { + "presets": [ + [ + "env", + { + "targets": { + "electron": 2 + } + } + ], + "react" + ], + "plugins": [ + "transform-async-to-generator" + ], + "sourceMaps": "none" + } + } + } +} \ No newline at end of file diff --git a/binaryen/.eslintrc b/binaryen/.eslintrc new file mode 100644 index 0000000..64f1252 --- /dev/null +++ b/binaryen/.eslintrc @@ -0,0 +1,9 @@ +{ + "extends": "eslint-config-airbnb", + "rules": { + "import/extensions": 0, + "import/no-extraneous-dependencies": 0, + "import/no-unresolved": [2, { "ignore": ["electron"] }], + "linebreak-style": 0 + } +} diff --git a/binaryen/.gitignore b/binaryen/.gitignore new file mode 100644 index 0000000..1b732f8 --- /dev/null +++ b/binaryen/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +Cargo.lock +target/ +dist/ +binaryen/ \ No newline at end of file diff --git a/binaryen/Cargo.toml b/binaryen/Cargo.toml new file mode 100644 index 0000000..7bedb6c --- /dev/null +++ b/binaryen/Cargo.toml @@ -0,0 +1,15 @@ +[package] +authors = ["Bradlee Speice"] +categories = ["wasm"] +description = "A no-framework WASM Electron app" +license = "Apache-2.0/MIT" +name = "stdweb_electron" +readme = "./README.md" +repository = "https://github.com/rustwasm/rust-webpack-template" +version = "0.1.0" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +stdweb = "0.4" diff --git a/binaryen/build.sh b/binaryen/build.sh new file mode 100755 index 0000000..018412b --- /dev/null +++ b/binaryen/build.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +DIR="$(dirname $0)" +WASM_DIR="$DIR/target/wasm32-unknown-unknown" +WASM_NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')" +APP_DIR="$DIR/dist/" + +if [ ! -f "$DIR/binaryen/bin/wasm2js" ]; then + git clone "https://github.com/WebAssembly/binaryen" "$DIR/binaryen" + pushd "$DIR/binaryen" + cmake . && make -j8 + popd +fi + +if [ ! -d "$APP_DIR" ]; then + mkdir "$APP_DIR" +fi +cp "$DIR/static/"* "$APP_DIR" + +if [ -z "$(which cargo)" ]; then + echo 'Must install `cargo` before proceeding. Please see https://rustup.rs/ for more information.' + exit 1 +fi + +cargo +nightly build --target=wasm32-unknown-unknown && \ + "$DIR/binaryen/bin/wasm2js" --pedantic "$WASM_DIR/debug/stdweb_electron.wasm" -o "$APP_DIR/stdweb_electron.js" && \ + "$DIR/node_modules/webpack-cli/bin/cli.js" --mode=development "$APP_DIR/stdweb_electron.js" -o "$APP_DIR/bundle.js" diff --git a/binaryen/package.json b/binaryen/package.json new file mode 100644 index 0000000..410bc45 --- /dev/null +++ b/binaryen/package.json @@ -0,0 +1,66 @@ +{ + "name": "electron_percy_wasm", + "productName": "electron_percy_wasm", + "version": "1.0.0", + "description": "My Electron application description", + "main": "dist/index.js", + "scripts": { + "prestart": "./build.sh", + "start": "electron-forge start", + "package": "electron-forge package", + "make": "electron-forge make", + "lint": "eslint src" + }, + "keywords": [], + "author": "bspeice", + "license": "MIT", + "config": { + "forge": { + "make_targets": { + "win32": [ + "squirrel" + ], + "darwin": [ + "zip" + ], + "linux": [ + "deb", + "rpm" + ] + }, + "electronPackagerConfig": { + "packageManager": "yarn" + }, + "electronWinstallerConfig": { + "name": "electron_percy_wasm" + }, + "electronInstallerDebian": {}, + "electronInstallerRedhat": {}, + "github_repository": { + "owner": "", + "name": "" + }, + "windowsStoreConfig": { + "packageName": "", + "name": "electron_percy_wasm" + } + } + }, + "dependencies": { + "electron-compile": "^6.4.3", + "webpack": "^4.17.1", + "webpack-cli": "^3.1.0" + }, + "devDependencies": { + "babel-plugin-transform-async-to-generator": "^6.24.1", + "babel-preset-env": "^1.7.0", + "babel-preset-react": "^6.24.1", + "electron-forge": "^5.2.2", + "electron-prebuilt-compile": "2.0.7", + "eslint": "^3", + "eslint-config-airbnb": "^15", + "eslint-plugin-import": "^2", + "eslint-plugin-jsx-a11y": "^5", + "eslint-plugin-react": "^7" + } +} diff --git a/binaryen/src/lib.rs b/binaryen/src/lib.rs new file mode 100644 index 0000000..c942926 --- /dev/null +++ b/binaryen/src/lib.rs @@ -0,0 +1,16 @@ +extern crate stdweb; + +use stdweb::web::document; +use stdweb::web::INode; +use stdweb::web::IElement; + +pub fn run() { + stdweb::initialize(); + + let doc = document(); + let val = doc.create_element("p").unwrap(); + val.set_attribute("innerHTML", "IT IS ALIVE").unwrap(); + doc.body().unwrap().append_child(&val); + + stdweb::event_loop(); +} diff --git a/binaryen/static/app_loader.js b/binaryen/static/app_loader.js new file mode 100644 index 0000000..b3c1404 --- /dev/null +++ b/binaryen/static/app_loader.js @@ -0,0 +1,8 @@ +const app = import("./stdweb_electron") +app.then(module => { + console.log("Finished resolving application bundle") + module.run() +}, (e) => { + console.log("Unable to resolve application bundle: ") + console.log(e) +}) \ No newline at end of file diff --git a/binaryen/static/index.html b/binaryen/static/index.html new file mode 100644 index 0000000..2f354c0 --- /dev/null +++ b/binaryen/static/index.html @@ -0,0 +1,11 @@ + + + + + + + +

Loading...

+ +