openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

[utils] Add access to library version #244

Closed florian-h05 closed 1 year ago

florian-h05 commented 1 year ago

Fixes #238.

This PR adds a constant to the utils namespace that included the current version string. I had some concerns that this would not work with webpack, but I have tested this and it works as both webpacked version and npm package.

Signed-off-by: Florian Hotze florianh_dev@icloud.com

florian-h05 commented 1 year ago

Please don‘t merge, I missed to update the type defs.

rkoshak commented 1 year ago

Just to show why I asked for this, see https://github.com/rkoshak/openhab-rules-tools/blob/main/helpers.js#L140.

My rewritten rule templates now have at the top

helpers.validateLibraries('4.1.0', '2.0.1');

If either the installed openhab-js or my openhab_rules_tools are too old for the template to run it bails with a meaningful exception. I'm on a big kick to make sure all my rule templates generate meaningful errors and this is a big help. Thanks!