From: Dan Cunningham Date: Tue, 21 Dec 2021 22:36:22 +0000 (-0800) Subject: [jsscripting] Update docs and refactor path (#11827) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=ec10dfe897f3db47016e9208917795cf4bf66ce0;p=openhab-addons.git [jsscripting] Update docs and refactor path (#11827) This adds a minor refactoring of loading local resource paths that i didn't have time to get into 3.2 and moves the docs directory to doc. Signed-off-by: Dan Cunningham --- diff --git a/bundles/org.openhab.automation.jsscripting/README.md b/bundles/org.openhab.automation.jsscripting/README.md index 6ce4b4f2f1..7d1b2fcc8d 100644 --- a/bundles/org.openhab.automation.jsscripting/README.md +++ b/bundles/org.openhab.automation.jsscripting/README.md @@ -30,7 +30,7 @@ to common openHAB functionality within rules including items, things, actions, l This add-on includes by default the [openhab-js](https://github.com/openhab/openhab-js/) NPM library and exports it's namespaces onto the global namespace. This allows the use of `items`, `actions`, `cache` and other objects without the need to explicitly import using `require()`. This functionality can be disabled for users who prefer to manage their own imports via the add-on configuration options. -![OpenHAB Rule Configuration](./docs/settings.png) +![openHAB Rule Configuration](./doc/settings.png) ## UI Based Rules @@ -42,17 +42,17 @@ Advanced users, or users migrating scripts from existing systems may want to use Using the openHAB UI, first create a new rule and set a trigger condition -![OpenHAB Rule Configuration](./docs/rule-config.png) +![openHAB Rule Configuration](./doc/rule-config.png) ### Adding Actions Select "Add Action" and then select "ECMAScript 262 Edition 11". Its important this is "Edition 11" or higher, earlier versions will not work. This will bring up a empty script editor where you can enter your javascript. -![OpenHAB Rule Engines](./docs/rule-engines.png) +![openHAB Rule Engines](./doc/rule-engines.png) You can now write rules using standard ES6 Javascript along with the included openHAB [standard library](#standard-library). -![OpenHAB Rule Script](./docs/rule-script.png) +![openHAB Rule Script](./doc/rule-script.png) For example, turning a light on: ```javascript diff --git a/bundles/org.openhab.automation.jsscripting/doc/rule-config.png b/bundles/org.openhab.automation.jsscripting/doc/rule-config.png new file mode 100644 index 0000000000..e26c6a07cd Binary files /dev/null and b/bundles/org.openhab.automation.jsscripting/doc/rule-config.png differ diff --git a/bundles/org.openhab.automation.jsscripting/doc/rule-engines.png b/bundles/org.openhab.automation.jsscripting/doc/rule-engines.png new file mode 100644 index 0000000000..6faa0fb6c1 Binary files /dev/null and b/bundles/org.openhab.automation.jsscripting/doc/rule-engines.png differ diff --git a/bundles/org.openhab.automation.jsscripting/doc/rule-script.png b/bundles/org.openhab.automation.jsscripting/doc/rule-script.png new file mode 100644 index 0000000000..585d16e15e Binary files /dev/null and b/bundles/org.openhab.automation.jsscripting/doc/rule-script.png differ diff --git a/bundles/org.openhab.automation.jsscripting/doc/settings.png b/bundles/org.openhab.automation.jsscripting/doc/settings.png new file mode 100644 index 0000000000..a342844e4e Binary files /dev/null and b/bundles/org.openhab.automation.jsscripting/doc/settings.png differ diff --git a/bundles/org.openhab.automation.jsscripting/docs/rule-config.png b/bundles/org.openhab.automation.jsscripting/docs/rule-config.png deleted file mode 100644 index e26c6a07cd..0000000000 Binary files a/bundles/org.openhab.automation.jsscripting/docs/rule-config.png and /dev/null differ diff --git a/bundles/org.openhab.automation.jsscripting/docs/rule-engines.png b/bundles/org.openhab.automation.jsscripting/docs/rule-engines.png deleted file mode 100644 index 6faa0fb6c1..0000000000 Binary files a/bundles/org.openhab.automation.jsscripting/docs/rule-engines.png and /dev/null differ diff --git a/bundles/org.openhab.automation.jsscripting/docs/rule-script.png b/bundles/org.openhab.automation.jsscripting/docs/rule-script.png deleted file mode 100644 index 585d16e15e..0000000000 Binary files a/bundles/org.openhab.automation.jsscripting/docs/rule-script.png and /dev/null differ diff --git a/bundles/org.openhab.automation.jsscripting/docs/settings.png b/bundles/org.openhab.automation.jsscripting/docs/settings.png deleted file mode 100644 index a342844e4e..0000000000 Binary files a/bundles/org.openhab.automation.jsscripting/docs/settings.png and /dev/null differ diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java index 7f0d4b15a9..93a69ab60d 100644 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java @@ -223,11 +223,12 @@ public class OpenhabGraalJSScriptEngine extends InvocationInterceptingScriptEngi /** * Converts a root node path to a class resource path for loading local modules + * Ex: C:\node_modules\foo.js -> /node_modules/foo.js * * @param path * @return */ private String nodeFileToResource(Path path) { - return "/" + NODE_DIR + "/" + path.getFileName(); + return "/" + path.subpath(0, path.getNameCount()).toString().replace('\\', '/'); } }