Verified Commit 42eacac4 authored by staltz's avatar staltz

dx: setup Desktop build infrastructure with electron and webpack

parent d0b2e6db
......@@ -67,6 +67,8 @@ buck-out/
#
/lib/
/nodejs-assets
/desktop/nodejs-project
/desktop/dist
/android/app/src/main/res/raw/rnnodebundle
*.jsbundle
......
<!DOCTYPE html>
<html>
<head>
<title>Getting Started</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node
<script>
document.write(process.versions.node);</script
>, Chrome
<script>
document.write(process.versions.chrome);</script
>, and Electron
<script>
document.write(process.versions.electron);</script
>.
<script src="./dist/main.js"></script>
</body>
</html>
const path = require('path');
module.exports = {
entry: './index.desktop.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
};
/* Copyright (C) 2018-2019 The Manyverse Authors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function component() {
const element = document.createElement('div');
// Lodash, currently included via a script, is required for this line to work
element.innerHTML = 'Frontend JS activated';
return element;
}
document.body.appendChild(component());
......@@ -5,7 +5,15 @@ const path = require('path');
const blacklistRE = new RegExp(
'(' +
[/nodejs-assets\/.*/, /android\/.*/, /ios\/.*/]
[
/android\/.*/,
/desktop\/.*/,
/e2e\/.*/,
/ios\/.*/,
/nodejs-assets\/.*/,
/patches\/.*/,
/tools\/.*/,
]
.map(escapeRegExp)
.join('|') +
')$',
......
This diff is collapsed.
......@@ -2,6 +2,7 @@
"name": "manyverse",
"version": "0.1908.24-beta",
"private": true,
"main": "desktop/nodejs-project/loader.js",
"scripts": {
"lib": "tsc",
"clean-bundler": "watchman watch-del-all && rm -rf $TMPDIR/react-*",
......@@ -13,6 +14,10 @@
"build-android-assets": "npm run lib && npm run propagate-replacements && npm run build-backend",
"build-android-debug": "npm run build-android-assets && react-native run-android",
"build-android-release": "npm run build-android-assets && cd android && ./gradlew assembleRelease && cd ..",
"build-desktop-backend": "./tools/build-desktop-backend && ./tools/minify-desktop-backend",
"build-desktop-frontend": "webpack --mode production --config desktop/webpack.config.js",
"build-desktop": "npm run build-desktop-backend && npm run build-desktop-frontend",
"desktop": "cd desktop/nodejs-project && npm run electron",
"start": "npm run lib && npm run propagate-replacements && node node_modules/react-native/local-cli/cli.js start",
"psdr": "./tools/print-service-desk-report.js",
"test-e2e-android": "./tools/test-e2e-android",
......@@ -114,6 +119,7 @@
"add-stream": "~1.0.0",
"appium": "1.14.0",
"conventional-changelog": "~2.0.3",
"electron": "^6.0.4",
"into-stream": "~3.1.0",
"jase": "1.2.0",
"left-pad": "1.3.0",
......@@ -127,10 +133,12 @@
"tape": "~4.9.1",
"tslint": "~5.18.0",
"typescript": "3.5.x",
"wd": "1.11.3"
"wd": "1.11.3",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.7"
},
"react-native": {
"os": "react-native-os-staltz",
"rn-viewpager": "@staltz/rn-viewpager"
}
}
\ No newline at end of file
}
......@@ -9,7 +9,6 @@ const path = require('path');
const ssbKeys = require('ssb-keys');
const mkdirp = require('mkdirp');
const DHT = require('multiserver-dht');
const rnBridge = require('rn-bridge');
const rnChannelPlugin = require('multiserver-rn-channel');
const NoauthTransformPlugin = require('multiserver/plugins/noauth');
const WS = require('multiserver/plugins/ws');
......@@ -23,16 +22,18 @@ import votesPlugin = require('./plugins/votes');
import connUtilsPlugin = require('./plugins/connUtils');
import manifest = require('./manifest');
const appDataDir = rnBridge.app.datadir();
const ssbPath = path.resolve(appDataDir, '.ssb');
if (!fs.existsSync(ssbPath)) {
mkdirp.sync(ssbPath);
if (!process.env.APP_DATA_DIR || !process.env.SSB_DIR) {
throw new Error('misconfigured default paths for the backend');
}
const keysPath = path.join(ssbPath, '/secret');
if (!fs.existsSync(process.env.SSB_DIR)) {
mkdirp.sync(process.env.SSB_DIR);
}
const keysPath = path.join(process.env.SSB_DIR, '/secret');
const keys = ssbKeys.loadOrCreateSync(keysPath);
const config = makeConfig('ssb', {
path: ssbPath,
path: process.env.SSB_DIR,
keys,
manifest,
friends: {
......@@ -56,8 +57,8 @@ const config = makeConfig('ssb', {
},
});
function noAuthTransform(_sbot: any, cfg: any) {
_sbot.multiserver.transform({
function noAuthTransform(ssb: any, cfg: any) {
ssb.multiserver.transform({
name: 'noauth',
create: () =>
NoauthTransformPlugin({
......@@ -68,30 +69,34 @@ function noAuthTransform(_sbot: any, cfg: any) {
});
}
function rnChannelTransport(_sbot: any) {
_sbot.multiserver.transport({
name: 'channel',
create: () => rnChannelPlugin(rnBridge.channel),
});
function rnChannelTransport(ssb: any) {
if (process.env.MANYVERSE_PLATFORM !== 'mobile') return;
try {
const rnBridge = require('rn-' + 'bridge'); // bypass noderify
ssb.multiserver.transport({
name: 'channel',
create: () => rnChannelPlugin(rnBridge.channel),
});
} catch (err) {}
}
function wsTransport(_sbot: any) {
_sbot.multiserver.transport({
function wsTransport(ssb: any) {
ssb.multiserver.transport({
name: 'ws',
create: () => WS({}),
});
}
function dhtTransport(_sbot: any) {
_sbot.multiserver.transport({
function dhtTransport(ssb: any) {
ssb.multiserver.transport({
name: 'dht',
create: (dhtConfig: any) =>
DHT({keys: _sbot.dhtInvite.channels(), port: dhtConfig.port}),
DHT({keys: ssb.dhtInvite.channels(), port: dhtConfig.port}),
});
}
const bluetoothManager: any = BluetoothManager({
socketFolderPath: appDataDir,
socketFolderPath: process.env.APP_DATA_DIR,
myIdent: '@' + keys.public,
metadataServiceUUID: 'b4721184-46dc-4314-b031-bf52c2b197f3',
controlSocketFilename: 'manyverse_bt_control.sock',
......
/* Copyright (C) 2018-2019 The Manyverse Authors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import os = require('os');
import path = require('path');
import {BrowserWindow, app} from 'electron';
process.env = process.env || {};
process.env.MANYVERSE_PLATFORM = 'desktop';
// Set default directories
process.env.APP_DATA_DIR = process.cwd();
process.env.SSB_DIR = path.resolve(os.homedir(), '.ssb');
process.env.DEBUG = '*';
// Force libsodium to use a WebAssembly implementation
// process.env.CHLORIDE_JS = 'yes';
let win: BrowserWindow | null;
function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
win.loadFile('../index.html');
win.webContents.openDevTools();
win.on('closed', () => {
win = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform === 'darwin') return;
app.quit();
});
app.on('activate', () => {
if (win === null) {
createWindow();
}
});
require('./index');
......@@ -5,16 +5,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import os = require('os');
const path = require('path');
import path = require('path');
const rnBridge = require('rn-bridge');
// Set default directory
const nodejsProjectDir = path.resolve(rnBridge.app.datadir(), 'nodejs-project');
process.env = process.env || {};
process.env.MANYVERSE_PLATFORM = 'mobile';
// Set default directories
const appDataDir = (process.env.APP_DATA_DIR = rnBridge.app.datadir());
process.env.SSB_DIR = path.resolve(appDataDir, '.ssb');
const nodejsProjectDir = path.resolve(appDataDir, 'nodejs-project');
os.homedir = () => nodejsProjectDir;
process.cwd = () => nodejsProjectDir;
// Force libsodium to use a WebAssembly implementation
process.env = process.env || {};
process.env.CHLORIDE_JS = 'yes';
// Report JS backend crashes to Java, and in turn, to ACRA
......
This diff is collapsed.
......@@ -5,6 +5,10 @@
"engines": {
"node": "10.13.0"
},
"scripts": {
"electron": "electron .",
"debug-electron": "electron --inspect-brk=5858 ."
},
"dependencies": {
"bindings-noderify-nodejs-mobile": "10.3.0",
"bufferutil": "4.0.1",
......@@ -52,6 +56,9 @@
"utf-8-validate": "5.0.2",
"utp-native-no-prebuild": "1.7.3-4"
},
"optionalDependencies": {
"electron": "^6.0.4"
},
"devDependencies": {
"noderify": "4.1.0"
}
......
......@@ -101,9 +101,7 @@ const create = (api: any) => {
const ms = MultiServer([
[
rnChannelPlugin(nodejs.channel),
noAuthPlugin({
keys: toSodiumKeys(keys),
}),
noAuthPlugin({keys: toSodiumKeys(keys)}),
],
]);
......
......@@ -30,8 +30,12 @@ cp -r ./lib/backend ./nodejs-assets;
mv ./nodejs-assets/backend ./nodejs-assets/nodejs-project;
cp ./src/backend/package.json ./nodejs-assets/nodejs-project;
cp ./src/backend/package-lock.json ./nodejs-assets/nodejs-project;
rm ./nodejs-assets/nodejs-project/*.js.map;
rm ./nodejs-assets/nodejs-project/plugins/*.js.map;
cd ./nodejs-assets/nodejs-project;
mv ./loader.mobile.js ./loader.js;
rm ./*.js.map;
rm ./plugins/*.js.map;
rm ./loader.desktop.js;
cd ../..;
echo "Installing dependencies...";
cd ./nodejs-assets/nodejs-project && npm install --no-optional;
......
#!/bin/bash
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
set -eEu -o pipefail
shopt -s extdebug
IFS=$'\n\t'
trap 'onFailure $?' ERR
function onFailure() {
echo "Unhandled script error $1 at ${BASH_SOURCE[0]}:${BASH_LINENO[0]}" >&2
exit 1
}
echo "Compiling TypeScript...";
npm run lib;
echo "Setting up...";
mkdir -p ./desktop;
rm -rf ./desktop/nodejs-project;
cp -r ./lib/backend ./desktop;
mv ./desktop/backend ./desktop/nodejs-project;
cp ./src/backend/package.json ./desktop/nodejs-project;
cp ./src/backend/package-lock.json ./desktop/nodejs-project;
cd ./desktop/nodejs-project;
mv ./loader.desktop.js ./loader.js;
rm ./*.js.map;
rm ./plugins/*.js.map;
rm ./loader.mobile.js;
cd ../..;
echo "Installing dependencies...";
cd ./desktop/nodejs-project && npm install;
# For more details on this, read issue #398:
echo "Removing problematic transitive dependencies...";
cd node_modules && rm -rf chokidar fsevents && cd ../../..;
echo "Updating package-lock.json";
cp ./desktop/nodejs-project/package-lock.json ./src/backend/package-lock.json
echo "Done.";
#!/bin/bash
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
set -eEu -o pipefail
shopt -s extdebug
IFS=$'\n\t'
trap 'onFailure $?' ERR
function onFailure() {
echo "Unhandled script error $1 at ${BASH_SOURCE[0]}:${BASH_LINENO[0]}" >&2
exit 1
}
echo -en "Minifying with noderify...";
cd ./desktop/nodejs-project;
$(npm bin)/noderify \
--replace.node-extend=xtend \
--replace.multiserver/plugins/net=staltz-multiserver/plugins/net \
--replace.non-private-ip=non-private-ip-android \
index.js > _index.js;
rm index.js;
mv _index.js index.js;
cd ../..;
echo -en " done.\n";
......@@ -19,7 +19,8 @@
},
"files": [
"src/backend/index.ts",
"src/backend/loader.ts",
"src/backend/loader.mobile.ts",
"src/backend/loader.desktop.ts",
"src/backend/manifest.ts",
"src/frontend/index.ts",
"src/typings/react-native-bluetooth-status.d.ts",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment