2019-10-27 21:58:54 +00:00
# Electron Node-RED
2020-05-05 18:34:45 +00:00
[![platform ](https://img.shields.io/badge/platform-Node--RED-red )](https://nodered.org)
2019-10-27 21:58:54 +00:00
[![GitHub version ](https://badge.fury.io/gh/dceejay%2Felectron-node-red.svg )](https://badge.fury.io/gh/dceejay%2Felectron-node-red)
2019-11-03 23:34:46 +00:00
[![GitHub license ](https://img.shields.io/github/license/dceejay/electron-node-red.svg )](https://github.com/dceejay/electron-node-red/blob/master/LICENSE)
2016-03-09 21:49:41 +00:00
2019-11-19 15:21:09 +00:00
This is an Electron template to embed [Node-RED ](https://nodered.org ) with an existing Node-RED project to create a native application.
2016-04-20 13:26:46 +00:00
2019-10-23 22:46:16 +00:00
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.
2018-08-25 21:31:44 +00:00
2019-11-15 23:33:40 +00:00
There are several simple switches that can be set in the `NRelectron` section of
the `package.json` file. More significant modifications will require modification
of the `main.js` file. Have fun.
2016-03-09 21:49:41 +00:00
2019-11-19 15:21:09 +00:00
## 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.
2020-04-28 09:48:39 +00:00
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 default name can be changed in the package.json file if required.
2019-11-19 15:21:09 +00:00
2020-04-28 09:48:39 +00:00
**NOTE**: Currently the settings are set around line 110 of the `main.js` file. If you do use any
2019-11-19 15:21:09 +00:00
custom settings then currently you will need to modify this manually.
2019-10-24 13:30:24 +00:00
## Configuring the project for building
2016-03-09 21:49:41 +00:00
2019-10-23 22:46:16 +00:00
This project uses the **electron-builder** project to help build native versions
2019-11-03 22:12:35 +00:00
of Node-RED applications, so please read and become familiar with their
[documentation ](https://www.electron.build/ ) as some basic knowledge is assumed.
2019-10-23 22:46:16 +00:00
2019-11-03 22:12:35 +00:00
As a pre-req, as well as a recent version of node.js, you will need the **yarn** install tool.
2016-03-09 21:49:41 +00:00
```bash
# Clone this repository
2016-10-29 13:43:32 +00:00
git clone https://github.com/dceejay/electron-node-red.git
2016-03-09 21:49:41 +00:00
# Go into the repository
2016-03-09 21:59:34 +00:00
cd electron-node-red
2019-10-23 22:46:16 +00:00
# Install the yarn install tool globally
sudo npm i -g yarn
# Install project dependencies
yarn
2016-03-09 21:49:41 +00:00
```
2019-10-23 22:46:16 +00:00
## Building local runtime
2016-04-20 13:26:46 +00:00
2019-10-23 22:46:16 +00:00
You should then be able to run
2019-11-03 22:12:35 +00:00
```bash
2019-10-23 22:46:16 +00:00
yarn & & yarn dist
2016-04-20 13:26:46 +00:00
```
2019-10-23 22:46:16 +00:00
to create a runtime for your local platform.
2019-11-03 22:12:35 +00:00
However - there may be some errors. If so they are usually fairly self explanatory,
2019-11-19 15:21:09 +00:00
and may just require installation of another **npm** or **brew** or **apt** package,
2019-10-24 08:38:26 +00:00
then retry the command.
2016-05-06 12:18:15 +00:00
2019-10-24 08:38:26 +00:00
Runtimes are created in the `dist` directory under the `electron-node-red` project.
2016-10-29 13:43:32 +00:00
2019-10-23 22:46:16 +00:00
### Building for other platforms
2016-05-06 12:18:15 +00:00
2019-10-23 22:46:16 +00:00
Generally you can just add the required parameter to the command
2019-11-03 22:12:35 +00:00
```bash
2020-04-28 09:48:39 +00:00
yarn & & yarn dist -w // for windows (but use multi-platform builder below for building on Mac Catalina)
2019-10-23 22:46:16 +00:00
yarn & & yarn dist -l // for linux
yarn & & yarn dist -m // for mac
```
2016-05-10 11:39:24 +00:00
2019-11-19 15:21:09 +00:00
These will generally fail the first time through, and you will need to install some extra library in order to make it
2019-10-23 22:46:16 +00:00
complete successfully.
2016-10-30 22:06:48 +00:00
2019-10-26 17:30:16 +00:00
The defaults are to build a `.msi` for Windows, a `.dmg` for Mac, and both a `.deb` and `.rpm` for Linux.
2019-10-23 22:46:16 +00:00
These can be changed by editing the build section of the `package.json` file, see the
2019-11-19 15:21:09 +00:00
[electron-builder config docs ](https://www.electron.build/configuration/configuration ) for more information.
2016-10-30 22:06:48 +00:00
2019-10-24 13:30:24 +00:00
## Building multi platform using Docker
2016-10-31 22:07:52 +00:00
2019-10-24 13:30:24 +00:00
Electron-builder has a pre-configured Docker image that can help you build cross platform
images if you like Docker - again read [their docs ](https://www.electron.build/multi-platform-build#build-electron-app-using-docker-on-a-local-machine ).
2019-11-15 23:33:40 +00:00
This is very useful if you need to build for Windows on a Mac as the electron-builder invokes **wine** which is only 32-bit and so can't be run under Catalina.
2019-10-27 21:58:54 +00:00
2019-10-24 13:30:24 +00:00
## Developing and Testing - Running locally
While developing and testing you can just run your app locally by running
2019-11-03 22:12:35 +00:00
```bash
2019-11-14 21:37:47 +00:00
yarn start
2019-10-23 22:46:16 +00:00
```
2019-11-03 22:12:35 +00:00
2019-10-23 22:46:16 +00:00
from within the project folder.
2016-05-20 10:20:54 +00:00
2019-10-24 08:38:26 +00:00
The initial flow file is named `electronflow.json` along with it's credentials file
`electronflow_cred.json` . Just copy your existing flow in instead.
2019-10-24 13:30:24 +00:00
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
2019-11-19 15:21:09 +00:00
to configure this within the package.json or at the top of main.js.
2019-10-24 08:38:26 +00:00
2019-11-03 22:12:35 +00:00
---