Skip to content

Commit

Permalink
Nodered node (#24)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lobis authored Jul 4, 2023
1 parent 7352ce3 commit 68628ff
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 16 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
45 changes: 38 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions bindings/nodejs/nodered/hvps-nodered.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script type="text/javascript">
RED.nodes.registerType('hvps', {
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value: ""}
},
inputs: 1,
outputs: 1,
icon: "file.png",
label: function () {
return this.name || "hvps";
}
});
</script>

<script type="text/html" data-template-name="lower-case">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>

<script type="text/html" data-help-name="lower-case">
<p>TODO</p>
</script>
14 changes: 14 additions & 0 deletions bindings/nodejs/nodered/hvps-nodered.js
Original file line number Diff line number Diff line change
@@ -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);
}
191 changes: 191 additions & 0 deletions bindings/nodejs/nodered/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 68628ff

Please sign in to comment.