From 68628ff00ffe6a532f023ea5fd04f28fa9d016c0 Mon Sep 17 00:00:00 2001
From: Luis Antonio Obis Aparicio <35803280+lobis@users.noreply.github.com>
Date: Tue, 4 Jul 2023 12:04:00 +0200
Subject: [PATCH] Nodered node (#24)
* working on nodered node
* working on nodered node
* automatically sync version between python and js
* add ruff cache to .gitignore
* add check for nodejs and python version sync
* add additional check for version matching
* refactor bindings into two projects: js bindings and nodered module
* refactor bindings into two projects: js bindings and nodered module
* working on nodered node
* automatically sync version between python and js
* add ruff cache to .gitignore
* add check for nodejs and python version sync
* add additional check for version matching
* fix bad path
* publish node-red package to npm
---
.github/workflows/build-test.yml | 19 +-
.github/workflows/publish.yml | 45 ++++-
bindings/nodejs/{ => hvps}/cli.js | 0
bindings/nodejs/{ => hvps}/index.js | 0
bindings/nodejs/{ => hvps}/package-lock.json | 4 +-
bindings/nodejs/{ => hvps}/package.json | 5 +
bindings/nodejs/{ => nodered}/README.md | 0
bindings/nodejs/nodered/hvps-nodered.html | 26 +++
bindings/nodejs/nodered/hvps-nodered.js | 14 ++
bindings/nodejs/nodered/package-lock.json | 191 +++++++++++++++++++
bindings/nodejs/nodered/package.json | 27 +++
11 files changed, 315 insertions(+), 16 deletions(-)
rename bindings/nodejs/{ => hvps}/cli.js (100%)
rename bindings/nodejs/{ => hvps}/index.js (100%)
rename bindings/nodejs/{ => hvps}/package-lock.json (99%)
rename bindings/nodejs/{ => hvps}/package.json (88%)
rename bindings/nodejs/{ => nodered}/README.md (100%)
create mode 100644 bindings/nodejs/nodered/hvps-nodered.html
create mode 100644 bindings/nodejs/nodered/hvps-nodered.js
create mode 100644 bindings/nodejs/nodered/package-lock.json
create mode 100644 bindings/nodejs/nodered/package.json
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
index 7e347bf..82ce599 100644
--- a/.github/workflows/build-test.yml
+++ b/.github/workflows/build-test.yml
@@ -29,25 +29,30 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- - name: "Install the package with pip"
+ - name: Install the package with pip
run: python -m pip install .[test]
- - name: "Run pytest"
+ - name: Run pytest
run: python -m pytest
- - name: "Run from cli"
+ - name: Run from cli
run: python -m hvps --version
- uses: actions/setup-node@v3
with:
node-version: 18
- cache: 'npm'
- cache-dependency-path: bindings/nodejs/package-lock.json
+ cache: "npm"
+ cache-dependency-path: bindings/nodejs/hvps/package-lock.json
- - name: "Install nodejs bindings"
+ - name: Install nodejs bindings
run: |
- cd bindings/nodejs
+ cd bindings/nodejs/hvps
npm --version
node --version
npm install
node cli.js --version
+
+ - name: Check nodejs package version is in sync with python
+ run: |
+ cd bindings/nodejs/hvps/
+ node cli.js --version | grep $(python -m hvps --version)
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 93f324e..968b39c 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -22,13 +22,17 @@ jobs:
# Update the version file (version.py)
sed -i "s/__version__ = \".*\"/__version__ = \"$TAG\"/" src/hvps/version.py
- # Update the package.json file
- sed -i "s/\"version\": \".*\",/\"version\": \"$TAG\",/" bindings/nodejs/package.json
+ # Update the package.json file for bindings
+ sed -i "s/\"version\": \".*\",/\"version\": \"$TAG\",/" bindings/nodejs/hvps/package.json
+
+ # Update the package.json file for nodered
+ sed -i "s/\"version\": \".*\",/\"version\": \"$TAG\",/" bindings/nodejs/nodered/package.json
+ sed -i "s/\"hvps\": \".*\",/\"version\": \"$TAG\",/" bindings/nodejs/nodered/package.json
# Commit and push changes
git config --local user.name "Luis Antonio Obis Aparicio"
git config --local user.email "luis.antonio.obis@gmail.com"
- git add src/hvps/version.py bindings/nodejs/package.json
+ git add src/hvps/version.py bindings/nodejs/hvps/package.json bindings/nodejs/nodered/package.json
git commit -m "Update version to $TAG"
git push origin HEAD:main
@@ -74,7 +78,7 @@ jobs:
- name: Verify npm package version matches tag
run: |
- python -c "import os,json;version=json.load(open('bindings/nodejs/package.json'))['version'];assert '${{ github.event.release.tag_name }}' == 'v' + version"
+ python -c "import os,json;version=json.load(open('bindings/nodejs/hvps/package.json'))['version'];assert '${{ github.event.release.tag_name }}' == 'v' + version"
- name: Cache dist directory
uses: actions/cache@v3
@@ -98,12 +102,40 @@ jobs:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- publish-to-npm:
+ publish-bindings-to-npm:
+ needs: [ publish-to-pypi ]
+ runs-on: ubuntu-latest
+ defaults:
+ run:
+ working-directory: bindings/nodejs/hvps
+
+ steps:
+ - name: restore source code from cache (contains update to version)
+ uses: actions/cache@v3
+ with:
+ path: ${{ github.workspace }}
+ key: ${{ runner.os }}-src-${{ github.sha }}-${{ github.run_id}}-${{ github.run_number }}
+
+ - uses: actions/setup-node@v3
+ with:
+ node-version: 18
+ cache: 'npm'
+ registry-url: 'https://registry.npmjs.org'
+
+ - name: Install dependencies
+ run: npm ci
+
+ - name: Publish to npm
+ run: npm publish
+ env:
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+
+ publish-node-to-npm:
needs: [ publish-to-pypi ]
runs-on: ubuntu-latest
defaults:
run:
- working-directory: bindings/nodejs
+ working-directory: bindings/nodejs/nodered
steps:
- name: restore source code from cache (contains update to version)
@@ -116,7 +148,6 @@ jobs:
with:
node-version: 18
cache: 'npm'
- cache-dependency-path: bindings/nodejs/package-lock.json
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
diff --git a/bindings/nodejs/cli.js b/bindings/nodejs/hvps/cli.js
similarity index 100%
rename from bindings/nodejs/cli.js
rename to bindings/nodejs/hvps/cli.js
diff --git a/bindings/nodejs/index.js b/bindings/nodejs/hvps/index.js
similarity index 100%
rename from bindings/nodejs/index.js
rename to bindings/nodejs/hvps/index.js
diff --git a/bindings/nodejs/package-lock.json b/bindings/nodejs/hvps/package-lock.json
similarity index 99%
rename from bindings/nodejs/package-lock.json
rename to bindings/nodejs/hvps/package-lock.json
index 8925db1..9f0cf58 100644
--- a/bindings/nodejs/package-lock.json
+++ b/bindings/nodejs/hvps/package-lock.json
@@ -11,7 +11,7 @@
},
"license": "BSD-3-Clause",
"name": "hvps",
- "version": "0.0.1"
+ "version": "0.0.21"
},
"node_modules/ansi-regex": {
"engines": {
@@ -176,5 +176,5 @@
}
},
"requires": true,
- "version": "0.0.1"
+ "version": "0.0.21"
}
diff --git a/bindings/nodejs/package.json b/bindings/nodejs/hvps/package.json
similarity index 88%
rename from bindings/nodejs/package.json
rename to bindings/nodejs/hvps/package.json
index 44b606e..3aa2821 100644
--- a/bindings/nodejs/package.json
+++ b/bindings/nodejs/hvps/package.json
@@ -14,6 +14,11 @@
"license": "BSD-3-Clause",
"main": "index.js",
"name": "hvps",
+ "node-red": {
+ "nodes": {
+ "hvps": "hvps-nodered.js"
+ }
+ },
"repository": {
"type": "git",
"url": "git+https://github.com/lobis/hvps.git"
diff --git a/bindings/nodejs/README.md b/bindings/nodejs/nodered/README.md
similarity index 100%
rename from bindings/nodejs/README.md
rename to bindings/nodejs/nodered/README.md
diff --git a/bindings/nodejs/nodered/hvps-nodered.html b/bindings/nodejs/nodered/hvps-nodered.html
new file mode 100644
index 0000000..2be0a73
--- /dev/null
+++ b/bindings/nodejs/nodered/hvps-nodered.html
@@ -0,0 +1,26 @@
+
+
+
+
+
diff --git a/bindings/nodejs/nodered/hvps-nodered.js b/bindings/nodejs/nodered/hvps-nodered.js
new file mode 100644
index 0000000..03fc3cb
--- /dev/null
+++ b/bindings/nodejs/nodered/hvps-nodered.js
@@ -0,0 +1,14 @@
+import { ExecutionContext } from "hvps";
+
+module.exports = function (RED) {
+ function HVPS(config) {
+ RED.nodes.createNode(this, config);
+ const node = this;
+ node.on('input', function (msg) {
+ msg.payload = msg.payload.toLowerCase();
+ node.send(msg);
+ });
+ }
+
+ RED.nodes.registerType("hvps", HVPS);
+}
diff --git a/bindings/nodejs/nodered/package-lock.json b/bindings/nodejs/nodered/package-lock.json
new file mode 100644
index 0000000..3704d39
--- /dev/null
+++ b/bindings/nodejs/nodered/package-lock.json
@@ -0,0 +1,191 @@
+{
+ "lockfileVersion": 3,
+ "name": "hvps",
+ "packages": {
+ "": {
+ "bin": {
+ "hvps": "cli.js"
+ },
+ "dependencies": {
+ "hvps": "0.0.21"
+ },
+ "license": "BSD-3-Clause",
+ "name": "hvps",
+ "version": "0.0.21"
+ },
+ "node_modules/ansi-regex": {
+ "engines": {
+ "node": ">=8"
+ },
+ "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
+ "version": "5.0.1"
+ },
+ "node_modules/ansi-styles": {
+ "dependencies": {
+ "color-convert": "^2.0.1"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "funding": {
+ "url": "https://github.com/chalk/ansi-styles?sponsor=1"
+ },
+ "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
+ "version": "4.3.0"
+ },
+ "node_modules/cliui": {
+ "dependencies": {
+ "string-width": "^4.2.0",
+ "strip-ansi": "^6.0.1",
+ "wrap-ansi": "^7.0.0"
+ },
+ "engines": {
+ "node": ">=12"
+ },
+ "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
+ "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
+ "version": "8.0.1"
+ },
+ "node_modules/color-convert": {
+ "dependencies": {
+ "color-name": "~1.1.4"
+ },
+ "engines": {
+ "node": ">=7.0.0"
+ },
+ "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
+ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
+ "version": "2.0.1"
+ },
+ "node_modules/color-name": {
+ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
+ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
+ "version": "1.1.4"
+ },
+ "node_modules/emoji-regex": {
+ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
+ "version": "8.0.0"
+ },
+ "node_modules/escalade": {
+ "engines": {
+ "node": ">=6"
+ },
+ "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
+ "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
+ "version": "3.1.1"
+ },
+ "node_modules/get-caller-file": {
+ "engines": {
+ "node": "6.* || 8.* || >= 10.*"
+ },
+ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
+ "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
+ "version": "2.0.5"
+ },
+ "node_modules/hvps": {
+ "bin": {
+ "hvps": "cli.js"
+ },
+ "dependencies": {
+ "yargs": "^17.7.2"
+ },
+ "integrity": "sha512-zrPr+ZX4tGW5GRnQRUPME4DKVrID1ETaTxV4wnEtehAQWa7DMry/5TTJDw3A2y00HkEmD/NuHu8QfQ3ix/m6Ow==",
+ "resolved": "https://registry.npmjs.org/hvps/-/hvps-0.0.21.tgz",
+ "version": "0.0.21"
+ },
+ "node_modules/is-fullwidth-code-point": {
+ "engines": {
+ "node": ">=8"
+ },
+ "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
+ "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
+ "version": "3.0.0"
+ },
+ "node_modules/require-directory": {
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
+ "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
+ "version": "2.1.1"
+ },
+ "node_modules/string-width": {
+ "dependencies": {
+ "emoji-regex": "^8.0.0",
+ "is-fullwidth-code-point": "^3.0.0",
+ "strip-ansi": "^6.0.1"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
+ "version": "4.2.3"
+ },
+ "node_modules/strip-ansi": {
+ "dependencies": {
+ "ansi-regex": "^5.0.1"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
+ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
+ "version": "6.0.1"
+ },
+ "node_modules/wrap-ansi": {
+ "dependencies": {
+ "ansi-styles": "^4.0.0",
+ "string-width": "^4.1.0",
+ "strip-ansi": "^6.0.0"
+ },
+ "engines": {
+ "node": ">=10"
+ },
+ "funding": {
+ "url": "https://github.com/chalk/wrap-ansi?sponsor=1"
+ },
+ "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
+ "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
+ "version": "7.0.0"
+ },
+ "node_modules/y18n": {
+ "engines": {
+ "node": ">=10"
+ },
+ "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
+ "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
+ "version": "5.0.8"
+ },
+ "node_modules/yargs": {
+ "dependencies": {
+ "cliui": "^8.0.1",
+ "escalade": "^3.1.1",
+ "get-caller-file": "^2.0.5",
+ "require-directory": "^2.1.1",
+ "string-width": "^4.2.3",
+ "y18n": "^5.0.5",
+ "yargs-parser": "^21.1.1"
+ },
+ "engines": {
+ "node": ">=12"
+ },
+ "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
+ "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
+ "version": "17.7.2"
+ },
+ "node_modules/yargs-parser": {
+ "engines": {
+ "node": ">=12"
+ },
+ "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
+ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
+ "version": "21.1.1"
+ }
+ },
+ "requires": true,
+ "version": "0.0.21"
+}
diff --git a/bindings/nodejs/nodered/package.json b/bindings/nodejs/nodered/package.json
new file mode 100644
index 0000000..8d23767
--- /dev/null
+++ b/bindings/nodejs/nodered/package.json
@@ -0,0 +1,27 @@
+{
+ "author": "Luis Antonio Obis Aparicio (@lobis)",
+ "bugs": {
+ "url": "https://github.com/lobis/hvps/issues"
+ },
+ "dependencies": {
+ "hvps": "0.0.21"
+ },
+ "description": "node-red node for the HVPS python package",
+ "homepage": "https://github.com/lobis/hvps#readme",
+ "license": "BSD-3-Clause",
+ "main": "index.js",
+ "name": "hvps-node-red",
+ "node-red": {
+ "nodes": {
+ "hvps": "hvps-nodered.js"
+ }
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/lobis/hvps.git"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "version": "0.0.21"
+}