kopia lustrzana https://github.com/dceejay/electron-node-red
tidy docs
rodzic
38eaac77e6
commit
4bb41d2e6c
38
README.md
38
README.md
|
@ -3,7 +3,7 @@
|
||||||
[](https://badge.fury.io/gh/dceejay%2Felectron-node-red)
|
[](https://badge.fury.io/gh/dceejay%2Felectron-node-red)
|
||||||
[](https://github.com/dceejay/electron-node-red/blob/master/LICENSE)
|
[](https://github.com/dceejay/electron-node-red/blob/master/LICENSE)
|
||||||
|
|
||||||
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.
|
This is an Electron template to embed [Node-RED](https://nodered.org) with an existing Node-RED project to create a native application.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
@ -11,6 +11,28 @@ There are several simple switches that can be set in the `NRelectron` section of
|
||||||
the `package.json` file. More significant modifications will require modification
|
the `package.json` file. More significant modifications will require modification
|
||||||
of the `main.js` file. Have fun.
|
of the `main.js` file. Have fun.
|
||||||
|
|
||||||
|
## Wrapping an existing Node-RED project
|
||||||
|
|
||||||
|
The `merger.js` utility should be run from within this projects directory and can be pointed at
|
||||||
|
an existing Node-RED project directory. 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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./merger.js {path to my Node-RED project directory}
|
||||||
|
yarn
|
||||||
|
yarn start
|
||||||
|
```
|
||||||
|
|
||||||
|
This uses the `package-template.json` file as the main electron setup - so you should edit any
|
||||||
|
build parameters, product name, whether you want the app version to be editable, run in kiosk mode, etc in the `NRelectron` section before running.
|
||||||
|
|
||||||
|
The app name, version and description are picked up from the package.json file of the original project.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
**NOTE**: Currently the settings are set around line 109 of the `main.js` file. If you do use any
|
||||||
|
custom settings then currently you will need to modify this manually.
|
||||||
|
|
||||||
## Configuring the project for building
|
## Configuring the project for building
|
||||||
|
|
||||||
This project uses the **electron-builder** project to help build native versions
|
This project uses the **electron-builder** project to help build native versions
|
||||||
|
@ -40,17 +62,11 @@ yarn && yarn dist
|
||||||
|
|
||||||
to create a runtime for your local platform.
|
to create a runtime for your local platform.
|
||||||
However - there may be some errors. If so they are usually fairly self explanatory,
|
However - there may be some errors. If so they are usually fairly self explanatory,
|
||||||
and may just require installation of another npm or brew or apt package,
|
and may just require installation of another **npm** or **brew** or **apt** package,
|
||||||
then retry the command.
|
then retry the command.
|
||||||
|
|
||||||
Runtimes are created in the `dist` directory under the `electron-node-red` project.
|
Runtimes are created in the `dist` directory under the `electron-node-red` project.
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
```
|
|
||||||
./merger.js {path to my Node-RED project directory} && yarn && yarn start
|
|
||||||
```
|
|
||||||
|
|
||||||
### Building for other platforms
|
### Building for other platforms
|
||||||
|
|
||||||
Generally you can just add the required parameter to the command
|
Generally you can just add the required parameter to the command
|
||||||
|
@ -61,12 +77,12 @@ yarn && yarn dist -l // for linux
|
||||||
yarn && yarn dist -m // for mac
|
yarn && yarn dist -m // for mac
|
||||||
```
|
```
|
||||||
|
|
||||||
These will generally fail the first time through and you will need to install some extra library in order to make it
|
These will generally fail the first time through, and you will need to install some extra library in order to make it
|
||||||
complete successfully.
|
complete successfully.
|
||||||
|
|
||||||
The defaults are to build a `.msi` for Windows, a `.dmg` for Mac, and both a `.deb` and `.rpm` for Linux.
|
The defaults are to build a `.msi` for Windows, a `.dmg` for Mac, and both a `.deb` and `.rpm` for Linux.
|
||||||
These can be changed by editing the build section of the `package.json` file, see the
|
These can be changed by editing the build section of the `package.json` file, see the
|
||||||
[electron-builder config docs](https://www.electron.build/configuration/configuration) for more info.
|
[electron-builder config docs](https://www.electron.build/configuration/configuration) for more information.
|
||||||
|
|
||||||
## Building multi platform using Docker
|
## Building multi platform using Docker
|
||||||
|
|
||||||
|
@ -89,6 +105,6 @@ The initial flow file is named `electronflow.json` along with it's credentials f
|
||||||
`electronflow_cred.json`. Just copy your existing flow in instead.
|
`electronflow_cred.json`. Just copy your existing flow in instead.
|
||||||
|
|
||||||
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
|
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
|
||||||
to configure this at the top of `main.js`.
|
to configure this within the package.json or at the top of main.js.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
22
merger.js
22
merger.js
|
@ -8,6 +8,7 @@ let arg = "./example";
|
||||||
let flowfile = null;
|
let flowfile = null;
|
||||||
let dn = arg;
|
let dn = arg;
|
||||||
let app;
|
let app;
|
||||||
|
// If extra param specified then is it a directory or a package or flow file ?
|
||||||
if (process.argv.length === 3 ) {
|
if (process.argv.length === 3 ) {
|
||||||
arg = process.argv[2];
|
arg = process.argv[2];
|
||||||
|
|
||||||
|
@ -30,31 +31,38 @@ else {
|
||||||
app = require(arg+"/package.json");
|
app = require(arg+"/package.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge electron settings over project settings (project has priority)
|
||||||
const merge = {
|
const merge = {
|
||||||
...app.dependencies,
|
...app.dependencies,
|
||||||
...pkg.dependencies
|
...pkg.dependencies
|
||||||
};
|
};
|
||||||
|
|
||||||
pkg.dependencies = merge;
|
pkg.dependencies = merge;
|
||||||
// Try to get flow file name
|
// Try to get flow file name from package.json setiings
|
||||||
if (app.hasOwnProperty("node-red") && app["node-red"].hasOwnProperty("settings") && app["node-red"].settings.hasOwnProperty("flowFile") ) {
|
if (app.hasOwnProperty("node-red") && app["node-red"].hasOwnProperty("settings") && app["node-red"].settings.hasOwnProperty("flowFile") ) {
|
||||||
pkg.NRelectron.flowFile = app["node-red"].settings.flowFile;
|
pkg.NRelectron.flowFile = app["node-red"].settings.flowFile;
|
||||||
}
|
} // or the npm scripts if there is a run command
|
||||||
else if (app.hasOwnProperty("scripts") && app.scripts.hasOwnProperty("start")) {
|
else if (app.hasOwnProperty("scripts") && app.scripts.hasOwnProperty("start")) {
|
||||||
pkg.NRelectron.flowFile = app.scripts.start.split(' ').pop();
|
pkg.NRelectron.flowFile = app.scripts.start.split(' ').pop();
|
||||||
}
|
} // or the command line if the user gave us a name - or just guess flow.json.
|
||||||
else {
|
else {
|
||||||
pkg.NRelectron.flowFile = flowfile || "flow.json";
|
pkg.NRelectron.flowFile = flowfile || "flow.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If dashboard is in package.json assume start with dashboard.
|
||||||
if (merge.hasOwnProperty("node-red-dashboard")) {
|
if (merge.hasOwnProperty("node-red-dashboard")) {
|
||||||
pkg.NRelectron.start = "dashboard";
|
pkg.NRelectron.start = "dashboard";
|
||||||
}
|
}
|
||||||
|
// If map is not in package.json then force it to be hidden
|
||||||
|
if (!merge.hasOwnProperty("node-red-contrib-web-worldmap")) {
|
||||||
|
pkg.NRelectron.showmap = false;
|
||||||
|
}
|
||||||
pkg.name = app.name;
|
pkg.name = app.name;
|
||||||
pkg.version = app.version;
|
pkg.version = app.version;
|
||||||
pkg.description = app.description;
|
pkg.description = app.description;
|
||||||
// console.log(pkg);
|
// console.log(pkg);
|
||||||
|
|
||||||
|
// Copy over existing flow file and creds file
|
||||||
fs.copyFile(path.join(arg, pkg.NRelectron.flowFile), path.join("./", pkg.NRelectron.flowFile), (err) => {
|
fs.copyFile(path.join(arg, pkg.NRelectron.flowFile), path.join("./", pkg.NRelectron.flowFile), (err) => {
|
||||||
if (err) { console.log("Failed to copy flows file - "+path.join(arg, pkg.NRelectron.flowFile)); }
|
if (err) { console.log("Failed to copy flows file - "+path.join(arg, pkg.NRelectron.flowFile)); }
|
||||||
else { console.log('Copied flows file - '+pkg.NRelectron.flowFile); }
|
else { console.log('Copied flows file - '+pkg.NRelectron.flowFile); }
|
||||||
|
@ -65,9 +73,13 @@ fs.copyFile(path.join(arg, creds), path.join("./", creds), (err) => {
|
||||||
else { console.log('Copied creds file - '+creds); }
|
else { console.log('Copied creds file - '+creds); }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Finally re-write th new package.json
|
||||||
fs.writeFile("./package.json", JSON.stringify(pkg, null, 4), 'utf8', function (err) {
|
fs.writeFile("./package.json", JSON.stringify(pkg, null, 4), 'utf8', function (err) {
|
||||||
if (err) { console.log("Failed to re-write package.json file."); }
|
if (err) { console.log("Failed to re-write package.json file."); }
|
||||||
else {
|
else {
|
||||||
console.log("Merged package.json.");
|
console.log("Merged package.json");
|
||||||
|
console.log("OK - you can now run yarn");
|
||||||
|
console.log("and then yarn start to run");
|
||||||
|
console.log(" or yarn dist to build");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,15 @@
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"description": "Electron Node-RED application starter kit for development",
|
"description": "Electron Node-RED application starter kit for development",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
|
"NRelectron": {
|
||||||
|
"productName": "Node-RED Electron",
|
||||||
|
"editable": true,
|
||||||
|
"allowLoadSave": false,
|
||||||
|
"showMap": false,
|
||||||
|
"kioskMode": false,
|
||||||
|
"flowFile": "electronflow.json",
|
||||||
|
"start": "editor"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pack": "electron-builder --dir",
|
"pack": "electron-builder --dir",
|
||||||
"dist": "electron-builder",
|
"dist": "electron-builder",
|
||||||
|
@ -38,15 +47,6 @@
|
||||||
"electron": "^7.1.1",
|
"electron": "^7.1.1",
|
||||||
"electron-builder": "^22.1.0"
|
"electron-builder": "^22.1.0"
|
||||||
},
|
},
|
||||||
"NRelectron": {
|
|
||||||
"productName": "Node-RED Electron",
|
|
||||||
"editable": true,
|
|
||||||
"allowLoadSave": false,
|
|
||||||
"showMap": false,
|
|
||||||
"kioskMode": false,
|
|
||||||
"flowFile": "electronflow.json",
|
|
||||||
"start": "editor"
|
|
||||||
},
|
|
||||||
"build": {
|
"build": {
|
||||||
"appId": "com.electron.node-red",
|
"appId": "com.electron.node-red",
|
||||||
"productName": "Node-RED Electron",
|
"productName": "Node-RED Electron",
|
||||||
|
|
18
package.json
18
package.json
|
@ -3,6 +3,15 @@
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"description": "Electron Node-RED application starter kit for development",
|
"description": "Electron Node-RED application starter kit for development",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
|
"NRelectron": {
|
||||||
|
"productName": "Node-RED Electron",
|
||||||
|
"editable": true,
|
||||||
|
"allowLoadSave": false,
|
||||||
|
"showMap": false,
|
||||||
|
"kioskMode": false,
|
||||||
|
"flowFile": "electronflow.json",
|
||||||
|
"start": "dashboard"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pack": "electron-builder --dir",
|
"pack": "electron-builder --dir",
|
||||||
"dist": "electron-builder",
|
"dist": "electron-builder",
|
||||||
|
@ -45,15 +54,6 @@
|
||||||
"electron": "^7.1.1",
|
"electron": "^7.1.1",
|
||||||
"electron-builder": "^22.1.0"
|
"electron-builder": "^22.1.0"
|
||||||
},
|
},
|
||||||
"NRelectron": {
|
|
||||||
"productName": "Node-RED Electron",
|
|
||||||
"editable": true,
|
|
||||||
"allowLoadSave": false,
|
|
||||||
"showMap": false,
|
|
||||||
"kioskMode": false,
|
|
||||||
"flowFile": "electronflow.json",
|
|
||||||
"start": "dashboard"
|
|
||||||
},
|
|
||||||
"build": {
|
"build": {
|
||||||
"appId": "com.electron.node-red",
|
"appId": "com.electron.node-red",
|
||||||
"productName": "Node-RED Electron",
|
"productName": "Node-RED Electron",
|
||||||
|
|
Ładowanie…
Reference in New Issue