diff --git a/README.md b/README.md index 5de9ba1..d10ef2e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/designs/subflow-to-npm/README.md b/designs/subflow-to-npm/README.md new file mode 100644 index 0000000..8209b1c --- /dev/null +++ b/designs/subflow-to-npm/README.md @@ -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(`*\*`)` + + 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: + +- *\*`.json` + + Exported SUBFLOW JSON definition + +- *\*`.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": , + "version": , + "description": , + "dependencies": [list of depending modules], + "keywrods": , + "node-red": { + "subflows": { + : .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 diff --git a/designs/subflow-to-npm/subflow-to-npm-process.png b/designs/subflow-to-npm/subflow-to-npm-process.png new file mode 100644 index 0000000..d4141eb Binary files /dev/null and b/designs/subflow-to-npm/subflow-to-npm-process.png differ diff --git a/designs/subflow-to-npm/subflow-to-npm.png b/designs/subflow-to-npm/subflow-to-npm.png new file mode 100644 index 0000000..7127f4f Binary files /dev/null and b/designs/subflow-to-npm/subflow-to-npm.png differ