Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add design note for converting SUBFLOW to NPM #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ with enough detail to review the intent and direction of the feature.
- [Dynamic MQTT Node](designs/dynamic-mqtt-node.md)
- [Exportable Subflow](designs/exportable-subflow/README.md)
- [Node Timeout API](designs/timeout-api.md)
- [Converting Subflow to NPM](designs/subflow-to-npm/README.md)

#### In-progress

Expand Down
84 changes: 84 additions & 0 deletions designs/subflow-to-npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
state: draft
---

# Converting Exportable SUBFLOW to NPM

This proposal covers how a Exportable SUBFLOW can be converted to NPM module.

Currently Node-RED nodes are distributed as NPM module. There is a design proposal that enable a SUBFLOW to be exported as a node in JSON format (https://github.com/node-red-hitachi/designs/blob/subflow-encryption/designs/exportable-subflow/README.md).

Even if redistributing SUBFLOW in JSON format is possible, it is useful to convert it to NPM format for the following reasons:

- automatic detection of node update,
- embedding example flows,
- listing in flow library by crawling npm repository,
- ...

Therefore, this design note proposes a method of converting JSON-formatted SUBFLOW nodes into NPM modules.

![subflow-to-npm](subflow-to-npm.png)

### Authors

- @HiroyasuNishiyama

### Details

#### Node API for installing SUBFLOW node

Current Node-RED API for installing nodes only accepts JavaScript/HTML description of nodes. To cope with this, we introduce a new API that accepts and installs JSON format SUBFLOW representation.

- `RED.nodes.registerSubflow(`*\<SUBFLOW definition\>*`)`

This API is called from the JavaScript file that correspond to installed node.

#### SUBFLOW NPM Module

Command-line tool or editor support is provided that converts SUBFLOW JSON representation to SUBFLOW NPM module. Converted SUBFLOW NPM module contains following contents:

- *\<SUBFLOW\>*`.json`

Exported SUBFLOW JSON definition

- *\<SUBFLOW\>*`.js`

Template code that loads `SUBFLOW.json` and call `registerSubflow` API.

- README.md

Generated from SUBFLOW matadata (description property)

- package.json

Generated from SUBFLOW metadata.

**Example**

```
{
"name": <exportName>,
"version": <version>,
"description": <description>,
"dependencies": [list of depending modules],
"keywrods": <keywords>,
"node-red": {
"subflows": {
<name>: <SUBFLOW>.js
    }
}
}
```

JavaScript module is listed in `node-red.subflows` property. This distingishes normal node module and SUBFLOW node module.

The `dependencies` property points to array of depending modules. This information is extracted from imported module list of function nodes. This is covered by separate design note on extension of function node (https://github.com/node-red/designs/pull/22).

HTML file is not required by SUBFLOW node module because editor-side UI information is contained in JSON representation.

![subflow-to-npm-process](subflow-to-npm-process.png)


## History

- 2020-02-23 - initial design note
Binary file added designs/subflow-to-npm/subflow-to-npm-process.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added designs/subflow-to-npm/subflow-to-npm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.