Skip to content

Commit 4bb41d2

Browse files
author
Dave Conway-Jones
committed
tidy docs
1 parent 38eaac7 commit 4bb41d2

File tree

4 files changed

+62
-34
lines changed

4 files changed

+62
-34
lines changed

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,36 @@
33
[![GitHub version](https://badge.fury.io/gh/dceejay%2Felectron-node-red.svg)](https://badge.fury.io/gh/dceejay%2Felectron-node-red)
44
[![GitHub license](https://img.shields.io/github/license/dceejay/electron-node-red.svg)](https://github.com/dceejay/electron-node-red/blob/master/LICENSE)
55

6-
This is an Electron template to embed [Node-RED](https://nodered.org) with a Dashboard generated by node-red-dashboard to create a native application.
6+
This is an Electron template to embed [Node-RED](https://nodered.org) with an existing Node-RED project to create a native application.
77

88
This is not intended to be a useful tool as-is, but as a base for you to create your own versions. You will need to edit the `main.js` to suit your application and update the `package.json` file to include your own required nodes and dependencies.
99

1010
There are several simple switches that can be set in the `NRelectron` section of
1111
the `package.json` file. More significant modifications will require modification
1212
of the `main.js` file. Have fun.
1313

14+
## Wrapping an existing Node-RED project
15+
16+
The `merger.js` utility should be run from within this projects directory and can be pointed at
17+
an existing Node-RED project directory. It will try to copy over and package up the
18+
relevant files into this project ready to install and build - so the simple flow would be
19+
20+
```bash
21+
./merger.js {path to my Node-RED project directory}
22+
yarn
23+
yarn start
24+
```
25+
26+
This uses the `package-template.json` file as the main electron setup - so you should edit any
27+
build parameters, product name, whether you want the app version to be editable, run in kiosk mode, etc in the `NRelectron` section before running.
28+
29+
The app name, version and description are picked up from the package.json file of the original project.
30+
31+
When running using yarn start - the flow file is picked from the current directory. When running as an app (but only if editable), then the flow file is copied into the users `.node-red` directory and is read and written from there. The deafult name can be changed in the package.json file if required.
32+
33+
**NOTE**: Currently the settings are set around line 109 of the `main.js` file. If you do use any
34+
custom settings then currently you will need to modify this manually.
35+
1436
## Configuring the project for building
1537

1638
This project uses the **electron-builder** project to help build native versions
@@ -40,17 +62,11 @@ yarn && yarn dist
4062

4163
to create a runtime for your local platform.
4264
However - there may be some errors. If so they are usually fairly self explanatory,
43-
and may just require installation of another npm or brew or apt package,
65+
and may just require installation of another **npm** or **brew** or **apt** package,
4466
then retry the command.
4567

4668
Runtimes are created in the `dist` directory under the `electron-node-red` project.
4769

48-
The `merger.js` utility can be pointed at an existing Node-RED projects directory and it will try to copy over and package up the relevant files into this project ready to install and build - so the simple flow would be
49-
50-
```
51-
./merger.js {path to my Node-RED project directory} && yarn && yarn start
52-
```
53-
5470
### Building for other platforms
5571

5672
Generally you can just add the required parameter to the command
@@ -61,12 +77,12 @@ yarn && yarn dist -l // for linux
6177
yarn && yarn dist -m // for mac
6278
```
6379

64-
These will generally fail the first time through and you will need to install some extra library in order to make it
80+
These will generally fail the first time through, and you will need to install some extra library in order to make it
6581
complete successfully.
6682

6783
The defaults are to build a `.msi` for Windows, a `.dmg` for Mac, and both a `.deb` and `.rpm` for Linux.
6884
These can be changed by editing the build section of the `package.json` file, see the
69-
[electron-builder config docs](https://www.electron.build/configuration/configuration) for more info.
85+
[electron-builder config docs](https://www.electron.build/configuration/configuration) for more information.
7086

7187
## Building multi platform using Docker
7288

@@ -89,6 +105,6 @@ The initial flow file is named `electronflow.json` along with it's credentials f
89105
`electronflow_cred.json`. Just copy your existing flow in instead.
90106

91107
The default is to start on the dashboard page - as this is intended to be just an application - without the Node-RED editor exposed to the end user, but there are some simple flags to
92-
to configure this at the top of `main.js`.
108+
to configure this within the package.json or at the top of main.js.
93109

94110
---

merger.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let arg = "./example";
88
let flowfile = null;
99
let dn = arg;
1010
let app;
11+
// If extra param specified then is it a directory or a package or flow file ?
1112
if (process.argv.length === 3 ) {
1213
arg = process.argv[2];
1314

@@ -30,31 +31,38 @@ else {
3031
app = require(arg+"/package.json");
3132
}
3233

34+
// Merge electron settings over project settings (project has priority)
3335
const merge = {
3436
...app.dependencies,
3537
...pkg.dependencies
3638
};
3739

3840
pkg.dependencies = merge;
39-
// Try to get flow file name
41+
// Try to get flow file name from package.json setiings
4042
if (app.hasOwnProperty("node-red") && app["node-red"].hasOwnProperty("settings") && app["node-red"].settings.hasOwnProperty("flowFile") ) {
4143
pkg.NRelectron.flowFile = app["node-red"].settings.flowFile;
42-
}
44+
} // or the npm scripts if there is a run command
4345
else if (app.hasOwnProperty("scripts") && app.scripts.hasOwnProperty("start")) {
4446
pkg.NRelectron.flowFile = app.scripts.start.split(' ').pop();
45-
}
46-
else {
47+
} // or the command line if the user gave us a name - or just guess flow.json.
48+
else {
4749
pkg.NRelectron.flowFile = flowfile || "flow.json";
4850
}
4951

52+
// If dashboard is in package.json assume start with dashboard.
5053
if (merge.hasOwnProperty("node-red-dashboard")) {
5154
pkg.NRelectron.start = "dashboard";
5255
}
56+
// If map is not in package.json then force it to be hidden
57+
if (!merge.hasOwnProperty("node-red-contrib-web-worldmap")) {
58+
pkg.NRelectron.showmap = false;
59+
}
5360
pkg.name = app.name;
5461
pkg.version = app.version;
5562
pkg.description = app.description;
5663
// console.log(pkg);
5764

65+
// Copy over existing flow file and creds file
5866
fs.copyFile(path.join(arg, pkg.NRelectron.flowFile), path.join("./", pkg.NRelectron.flowFile), (err) => {
5967
if (err) { console.log("Failed to copy flows file - "+path.join(arg, pkg.NRelectron.flowFile)); }
6068
else { console.log('Copied flows file - '+pkg.NRelectron.flowFile); }
@@ -65,9 +73,13 @@ fs.copyFile(path.join(arg, creds), path.join("./", creds), (err) => {
6573
else { console.log('Copied creds file - '+creds); }
6674
});
6775

76+
// Finally re-write th new package.json
6877
fs.writeFile("./package.json", JSON.stringify(pkg, null, 4), 'utf8', function (err) {
6978
if (err) { console.log("Failed to re-write package.json file."); }
7079
else {
71-
console.log("Merged package.json.");
80+
console.log("Merged package.json");
81+
console.log("OK - you can now run yarn");
82+
console.log("and then yarn start to run");
83+
console.log(" or yarn dist to build");
7284
}
7385
});

package-template.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
"version": "1.0.2",
44
"description": "Electron Node-RED application starter kit for development",
55
"main": "main.js",
6+
"NRelectron": {
7+
"productName": "Node-RED Electron",
8+
"editable": true,
9+
"allowLoadSave": false,
10+
"showMap": false,
11+
"kioskMode": false,
12+
"flowFile": "electronflow.json",
13+
"start": "editor"
14+
},
615
"scripts": {
716
"pack": "electron-builder --dir",
817
"dist": "electron-builder",
@@ -38,15 +47,6 @@
3847
"electron": "^7.1.1",
3948
"electron-builder": "^22.1.0"
4049
},
41-
"NRelectron": {
42-
"productName": "Node-RED Electron",
43-
"editable": true,
44-
"allowLoadSave": false,
45-
"showMap": false,
46-
"kioskMode": false,
47-
"flowFile": "electronflow.json",
48-
"start": "editor"
49-
},
5050
"build": {
5151
"appId": "com.electron.node-red",
5252
"productName": "Node-RED Electron",

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
"version": "1.0.2",
44
"description": "Electron Node-RED application starter kit for development",
55
"main": "main.js",
6+
"NRelectron": {
7+
"productName": "Node-RED Electron",
8+
"editable": true,
9+
"allowLoadSave": false,
10+
"showMap": false,
11+
"kioskMode": false,
12+
"flowFile": "electronflow.json",
13+
"start": "dashboard"
14+
},
615
"scripts": {
716
"pack": "electron-builder --dir",
817
"dist": "electron-builder",
@@ -45,15 +54,6 @@
4554
"electron": "^7.1.1",
4655
"electron-builder": "^22.1.0"
4756
},
48-
"NRelectron": {
49-
"productName": "Node-RED Electron",
50-
"editable": true,
51-
"allowLoadSave": false,
52-
"showMap": false,
53-
"kioskMode": false,
54-
"flowFile": "electronflow.json",
55-
"start": "dashboard"
56-
},
5757
"build": {
5858
"appId": "com.electron.node-red",
5959
"productName": "Node-RED Electron",

0 commit comments

Comments
 (0)