Skip to content

Commit

Permalink
Much cleaner builds all round
Browse files Browse the repository at this point in the history
Add Node-RED menu inside app
move built files to parallel directory
  • Loading branch information
Dave Conway-Jones committed Oct 31, 2016
1 parent 25624c8 commit 2df6a50
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 49 deletions.
19 changes: 12 additions & 7 deletions README.md
Expand Up @@ -17,13 +17,13 @@ cd electron-node-red
npm install && npm run clean && npm start
```

## TL:DR
## TL:DR - building runtimes

Run `npm run pack` to create packages for all platforms
or `npm run build` to build a .dmg file for OSX, and deb files for linux (32 and 64bit).
or `npm run build:osx` to just build for OSX.
On OSX you can run `./buildall` to build binaries of "everything"... maybe...

Builds are created in the `build` directory. Runtimes are created in the `dist` directory.
Run `npm run pack` to create packages for all platforms - these are the files required to run, they are not binary installers.

Builds are created in the `build` directory. Runtimes are created in the `../electron-bin` directory.

## Packaging your application

Expand Down Expand Up @@ -58,13 +58,17 @@ look at `https://github.com/LinusU/node-appdmg`

### To package as a deb

`npm run build:linux` or `npm run build:linux32` - for Intel Linux
`npm run build:linux64` or `npm run build:linux32` - for Intel Linux

look at `https://github.com/jordansissel/fpm`
Look at `https://github.com/jordansissel/fpm`

fpm -s dir -t deb -f -n node-red-electron -v 0.15.2 -m your-email@example.com -a i386 Node-RED-linux-ia32/
fpm -s dir -t deb -f -n node-red-electron -v 0.15.2 -m your-email@example.com -a x86_64 Node-RED-linux-x64/

Use **sudo dpkg -i ...*** to install the correct deb for your architecture.

Use `Node-RED` command to run. Flows are stored in `~/.node-red`.


### To package as an exe

Expand All @@ -74,6 +78,7 @@ look at `https://github.com/jordansissel/fpm`

**Note**: This project was built to run on Mac OSX - To build for windows on other platforms you may need to use other tools.


## License [CC0 (Public Domain)](LICENSE.md)

## See also
Expand Down
1 change: 1 addition & 0 deletions afterinst.sh
@@ -0,0 +1 @@
ln -s /opt/node-red/Node-RED /usr/bin/Node-RED
2 changes: 1 addition & 1 deletion appdmg.json
@@ -1,5 +1,5 @@
{
"title": "Node-RED installer",
"title": "Node-RED Electron installer",
"icon": "nodered.icns",
"background": "appbkg.png",
"icon-size": 80,
Expand Down
14 changes: 14 additions & 0 deletions buildall
@@ -0,0 +1,14 @@
npm i
rm -rf node_modules/node-red/node_modules/node-red-node-serialport node_modules/node-red/node_modules/node-red-node-feedparser node_modules/node-red/node_modules/node-red-node-email
./node_modules/.bin/electron-rebuild
npm run clean
npm run build:osx
rm -rf build/
npm run build:linux32
rm -rf build/
npm run build:linux64
rm -rf build/
npm run build:win32
rm -rf build/ ../electron-bin/*.nupkg ../electron-bin/RELEASES
npm run build:win64
rm -rf build/ ../electron-bin/*.nu* ../electron-bin/RELEASES
88 changes: 66 additions & 22 deletions main.js
@@ -1,22 +1,23 @@

'use strict';

// Some settings you can edit easily
// Start on the dashboard page
const url = "/ui";
// url for the editor page
const urledit = "/admin";
// tcp port to use
//const listenPort = "18880"; // fix it just because
const listenPort = parseInt(Math.random()*16383+49152) // or random ephemeral port

const os = require('os');
const electron = require('electron');
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
// Start directly on the ui page
const url = "http://localhost:8000/ui";

const {Menu, MenuItem} = electron;

// this should be placed at top of main.js to handle setup events quickly
if (handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}
// this should be placed at top of main.js to handle squirrel setup events quickly
if (handleSquirrelEvent()) { return; }

var http = require('http');
var express = require("express");
Expand All @@ -31,18 +32,21 @@ var red_app = express();
// Create a server
var server = http.createServer(red_app);

// If on Windows move the userdir away from the asar bundle.
var userdir = __dirname;
if (os.platform() === "win32") {
var userdir;
if (process.argv[1] && (process.argv[1] === "main.js")) {
userdir = __dirname;
}
else { // We set the user directory to be in the users home directory...
const fs = require('fs');
userdir = os.homedir() + '\\.node-red';
userdir = os.homedir() + '/.node-red';
if (!fs.existsSync(userdir)) {
fs.mkdirSync(userdir);
}
if (!fs.existsSync(userdir+"\\flows.json")) {
fs.writeFileSync(userdir+"\\flows.json", fs.readFileSync(__dirname+"\\flows.json"));
if (!fs.existsSync(userdir+"/flows.json")) {
fs.writeFileSync(userdir+"/flows.json", fs.readFileSync(__dirname+"/flows.json"));
}
}
console.log("Setting UserDir to ",userdir);

// Create the settings object - see default settings.js file for other options
var settings = {
Expand All @@ -67,9 +71,9 @@ red_app.use(settings.httpNodeRoot,RED.httpNode);
var template = [{
label: "Application",
submenu: [
{ label: "About Application", selector: "orderFrontStandardAboutPanel:" },
{ role: 'about' },
{ type: "separator" },
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }}
{ role: 'quit' }
]}, {
label: "Edit",
submenu: [
Expand All @@ -80,7 +84,45 @@ var template = [{
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
]}
]}, {
label: 'View',
submenu: [
{ label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click (item, focusedWindow) { if (focusedWindow) focusedWindow.reload() }
},
{ label: 'Toggle Developer Tools',
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click (item, focusedWindow) { if (focusedWindow) focusedWindow.webContents.toggleDevTools() }
},
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },
{ type: 'separator' },
{ role: 'togglefullscreen' },
{ role: 'minimize' }
]
}, {
label: 'Node-RED',
submenu: [
{ label: 'Editor',
accelerator: "Shift+CmdOrCtrl+E",
click () { mainWindow.loadURL("http://localhost:"+listenPort+urledit); }
},
{ label: 'Dashboard',
accelerator: "Shift+CmdOrCtrl+D",
click () { mainWindow.loadURL("http://localhost:"+listenPort+url); }
},
{ type: 'separator' },
{ label: 'Documentation',
click () { require('electron').shell.openExternal('http://nodered.org/docs') }
},
{ label: 'Google group',
click () { require('electron').shell.openExternal('https://groups.google.com/forum/#!forum/node-red') }
}
]
}
];

// Keep a global reference of the window object, if you don't, the window will
Expand All @@ -104,7 +146,7 @@ function createWindow () {

var webContents = mainWindow.webContents;
webContents.on('did-get-response-details', function(event, status, newURL, originalURL, httpResponseCode) {
if ((httpResponseCode == 404) && (newURL == url)) {
if ((httpResponseCode == 404) && (newURL == ("http://localhost:"+listenPort+url))) {
setTimeout(webContents.reload, 200);
}
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
Expand Down Expand Up @@ -151,16 +193,18 @@ app.on('activate', function () {
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
mainWindow.loadURL("http://127.0.0.1:"+listenPort+url);
}
});

// Start the Node-RED runtime, then load the inital page
RED.start().then(function() {
server.listen(8000,function() {
mainWindow.loadURL(url);
server.listen(listenPort,"127.0.0.1",function() {
mainWindow.loadURL("http://127.0.0.1:"+listenPort+url);
});
});

///////////////////////////////////////////////////////
// All this Squirrel stuff is for the Windows installer
function handleSquirrelEvent() {
if (process.argv.length === 1) {
Expand Down
4 changes: 2 additions & 2 deletions makewin32.js
Expand Up @@ -6,10 +6,10 @@ if (fs.existsSync('build/Node-RED-win32-ia32')) {
console.log("Building setup app for Windows 32bit");
resultPromise = electronInstaller.createWindowsInstaller({
appDirectory: 'build/Node-RED-win32-ia32',
outputDirectory: 'dist',
outputDirectory: '../electron-bin/',
authors: 'IBM Corp.',
exe: 'Node-RED.exe',
setupExe: 'Node-RED-ia32-setup.exe',
setupExe: 'Node-RED-Electron-ia32.exe',
setupIcon: 'nodered.ico',
loadingGif: 'loading.gif',
skipUpdateIcon: true
Expand Down
4 changes: 2 additions & 2 deletions makewin64.js
Expand Up @@ -6,10 +6,10 @@ if (fs.existsSync('build/Node-RED-win32-x64')) {
console.log("Building setup app for Windows 64bit");
resultPromise = electronInstaller.createWindowsInstaller({
appDirectory: 'build/Node-RED-win32-x64',
outputDirectory: 'dist',
outputDirectory: '../electron-bin/',
authors: 'IBM Corp.',
exe: 'Node-RED.exe',
setupExe: 'Node-RED-x64-setup.exe',
setupExe: 'Node-RED-Electron-x64.exe',
setupIcon: 'nodered.ico',
loadingGif: 'loading.gif',
skipUpdateIcon: true
Expand Down
29 changes: 14 additions & 15 deletions package.json
@@ -1,29 +1,29 @@
{
"name": "electron-node-red",
"version": "1.0.8",
"version": "0.15.2",
"description": "Electron Node-RED application starter",
"main": "main.js",
"scripts": {
"start": "electron main.js",
"test": "echo \" Warning: no test specified \"",

"clean": "rm -rf ./build ./dist && mkdir -p ./dist && ./node_modules/.bin/electron-rebuild",
"clean": "rm -rf ./build ../electron-bin && mkdir -p ./build ../electron-bin",

"pack": "npm run clean && electron-packager . Node-RED --icon=nodered.icns --all --out=build --overwrite",
"pack:osx": "electron-packager . Node-RED --icon=nodered.icns --platform=darwin --arch=x64 --out=build --overwrite",
"pack:win64": "electron-packager . Node-RED --icon=nodered.icns --platform=win32 --arch=x64 --out=build --asar=true --overwrite --win32metadata.CompanyName='IBM Corp.' --win32metadata.ProductName='Node-RED Electron'",
"pack:linux32": "electron-packager . Node-RED --icon=nodered.icns --platform=linux --arch=ia32 --out=build --overwrite && cp afterinst.sh build/Node-RED-linux-ia32/",
"pack:linux64": "electron-packager . Node-RED --icon=nodered.icns --platform=linux --arch=x64 --out=build --overwrite && cp afterinst.sh build/Node-RED-linux-x64",
"pack:win32": "electron-packager . Node-RED --icon=nodered.icns --platform=win32 --arch=ia32 --out=build --asar=true --overwrite --win32metadata.CompanyName='IBM Corp.' --win32metadata.ProductName='Node-RED Electron'",
"pack:linux": "electron-packager . Node-RED --icon=nodered.icns --platform=linux --arch=x64 --out=build --overwrite",
"pack:linux32": "electron-packager . Node-RED --icon=nodered.icns --platform=linux --arch=ia32 --out=build --overwrite",
"pack:armv7l": "electron-packager . Node-RED --icon=nodered.icns --platform=linux --arch=armv7l --out=build --overwrite",
"pack:win64": "electron-packager . Node-RED --icon=nodered.icns --platform=win32 --arch=x64 --out=build --asar=true --overwrite --win32metadata.CompanyName='IBM Corp.' --win32metadata.ProductName='Node-RED Electron'",
"pack:armv7l": "electron-packager . Node-RED --icon=nodered.icns --platform=linux --arch=armv7l --out=build --overwrite && cp afterinst.sh build/Node-RED-linux-armv7l",

"build": "npm run build:osx && npm run build:linux && npm run build:linux32",
"build:osx": "npm run pack && appdmg appdmg.json dist/Node-RED.dmg",
"build:win64": "npm run pack:win64 && ./makewin64.js && rm -f dist/RELEASES dist/*nupkg ",
"build:win32": "npm run pack:win32 && ./makewin32.js && rm -f dist/RELEASES dist/*nupkg",
"build:linux32": "npm run pack:linux32 && fpm -s dir -t deb -f -n node-red-electron -v 0.15.2 -m conway@uk.ibm.com -a i386 -p dist build/Node-RED-linux-ia32/",
"build:linux": "npm run pack:linux && fpm -s dir -t deb -f -n node-red-electron -v 0.15.2 -m conway@uk.ibm.com -a x86_64 -p dist build/Node-RED-linux-x64/",
"build:armv7l": "npm run pack:armv7l && fpm -s dir -t deb -f -n node-red-electron -v 0.15.2 -m conway@uk.ibm.com -a armv7l -p dist build/Node-RED-linux-armv7l/"
"build": "npm run clean && npm run build:osx && npm run build:linux64 && npm run build:linux32",
"build:osx": "npm run pack:osx && appdmg appdmg.json ../electron-bin/Node-RED-Electron_$npm_package_version.dmg",
"build:linux32": "npm run pack:linux32 && fpm -s dir -t deb -f -n node-red-electron -v $npm_package_version -m conway@uk.ibm.com -a i386 -p ../electron-bin -C build/Node-RED-linux-ia32 --prefix=/opt/node-red --after-install=afterinst.sh ./",
"build:linux64": "npm run pack:linux64 && fpm -s dir -t deb -f -n node-red-electron -v $npm_package_version -m conway@uk.ibm.com -a x86_64 -p ../electron-bin -C build/Node-RED-linux-x64 --prefix=/opt/node-red --after-install=afterinst.sh ./",
"build:win32": "npm run pack:win32 && ./makewin32.js",
"build:win64": "npm run pack:win64 && ./makewin64.js",
"build:armv7l": "npm run pack:armv7l && fpm -s dir -t deb -f -n node-red-electron -v $npm_package_version -m conway@uk.ibm.com -a armv7l -p ../electron-bin -C build/Node-RED-linux-armv7l --prefix=/opt/node-red --after-install=afterinst.sh ./"
},
"repository": {
"type": "git",
Expand All @@ -41,8 +41,7 @@
},
"keywords": [
"electron",
"quick",
"start",
"quick start",
"node-red"
],
"contributors": [
Expand Down

0 comments on commit 2df6a50

Please sign in to comment.