mirror of
https://github.com/speice-io/isomorphic-rust
synced 2024-12-21 22:38:09 -05:00
Get Electron/Percy/WASM running
This commit is contained in:
commit
e53a938d5a
42
electron_percy_wasm/.compilerc
Normal file
42
electron_percy_wasm/.compilerc
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
electron_percy_wasm/.eslintrc
Normal file
9
electron_percy_wasm/.eslintrc
Normal file
@ -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
|
||||
}
|
||||
}
|
3
electron_percy_wasm/.gitignore
vendored
Normal file
3
electron_percy_wasm/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
Cargo.lock
|
||||
target/
|
12
electron_percy_wasm/Cargo.toml
Normal file
12
electron_percy_wasm/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "electron_percy_wasm"
|
||||
version = "0.1.0"
|
||||
authors = ["Bradlee Speice <bradlee@speice.io>"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
percy-webapis = "0.0.1"
|
||||
virtual-dom-rs = "0.1"
|
||||
wasm-bindgen = "0.2"
|
4
electron_percy_wasm/app/.gitignore
vendored
Normal file
4
electron_percy_wasm/app/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*.wasm
|
||||
*.bundle.js
|
||||
bundle.js
|
||||
electron_percy_wasm.js
|
5
electron_percy_wasm/app/app.js
Normal file
5
electron_percy_wasm/app/app.js
Normal file
@ -0,0 +1,5 @@
|
||||
import { main } from "./electron_percy_wasm"
|
||||
|
||||
let rootNode = document.getElementById('root')
|
||||
rootNode.parentElement.replaceChild(main(), rootNode)
|
||||
rootNode = document.getElementById('root')
|
7
electron_percy_wasm/app/app_loader.js
Normal file
7
electron_percy_wasm/app/app_loader.js
Normal file
@ -0,0 +1,7 @@
|
||||
const app = import("./app")
|
||||
app.then(() => {
|
||||
console.log("Finished resolving application bundle")
|
||||
}, (e) => {
|
||||
console.log("Unable to resolve application bundle: ")
|
||||
console.log(e)
|
||||
})
|
11
electron_percy_wasm/app/index.html
Normal file
11
electron_percy_wasm/app/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root">Loading...</div>
|
||||
</body>
|
||||
<script src="./bundle.js"/>
|
||||
</html>
|
52
electron_percy_wasm/app/index.js
Normal file
52
electron_percy_wasm/app/index.js
Normal file
@ -0,0 +1,52 @@
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow;
|
||||
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
});
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||
|
||||
// Open the DevTools.
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', () => {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
};
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', createWindow);
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', () => {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (mainWindow === null) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and import them here.
|
25
electron_percy_wasm/build_wasm_bundle.sh
Executable file
25
electron_percy_wasm/build_wasm_bundle.sh
Executable file
@ -0,0 +1,25 @@
|
||||
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/app/"
|
||||
|
||||
if [ ! -d "$APP_DIR" ]; then
|
||||
mkdir "$APP_DIR"
|
||||
fi
|
||||
|
||||
if [ -z "$(which cargo)" ]; then
|
||||
echo 'Must install `cargo` before proceeding. Please see https://rustup.rs/ for more information.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$(which wasm-bindgen)" ]; then
|
||||
echo "Installing wasm-bindgen-cli"
|
||||
cargo install wasm-bindgen-cli
|
||||
fi
|
||||
|
||||
cargo +nightly build --target=wasm32-unknown-unknown && \
|
||||
wasm-bindgen "$WASM_DIR/debug/$WASM_NAME.wasm" --out-dir "$APP_DIR" --no-typescript && \
|
||||
# Have to use --mode=development so we can patch out the call to instantiateStreaming
|
||||
"$DIR/node_modules/webpack-cli/bin/cli.js" --mode=development "$APP_DIR/app_loader.js" -o "$APP_DIR/bundle.js"
|
||||
# Necessitated by https://github.com/webpack/webpack/issues/7918
|
||||
sed -i '/.*instantiateStreaming.*/d' "$APP_DIR/bundle.js"
|
66
electron_percy_wasm/package.json
Normal file
66
electron_percy_wasm/package.json
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"name": "electron_percy_wasm",
|
||||
"productName": "electron_percy_wasm",
|
||||
"version": "1.0.0",
|
||||
"description": "My Electron application description",
|
||||
"main": "app/index.js",
|
||||
"scripts": {
|
||||
"prestart": "./build_wasm_bundle.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"
|
||||
}
|
||||
}
|
20
electron_percy_wasm/src/lib.rs
Normal file
20
electron_percy_wasm/src/lib.rs
Normal file
@ -0,0 +1,20 @@
|
||||
#[macro_use]
|
||||
extern crate virtual_dom_rs;
|
||||
|
||||
extern crate percy_webapis;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use percy_webapis::log;
|
||||
use percy_webapis::Element;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn main() -> Element {
|
||||
log("Entered Rust code");
|
||||
|
||||
let elem = html! {
|
||||
<span> {"It is alive!"} </span>
|
||||
};
|
||||
|
||||
elem.create_element()
|
||||
}
|
7736
electron_percy_wasm/yarn.lock
Normal file
7736
electron_percy_wasm/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user