diff --git a/build/build.js b/build/build.js new file mode 100644 index 0000000..f8c8afd --- /dev/null +++ b/build/build.js @@ -0,0 +1,35 @@ +const fs = require("fs") +const Mustache = require('mustache'); + +// Load template +const htmlTemplate = fs.readFileSync("build/template/editor.html.mustache").toString() + +const nodes = fs.readdirSync("src/nodes") + +nodes.forEach((e)=>{ + // Load html parts + const helpHtml = fs.readFileSync(`src/nodes/${e}/ui/editor.html`) + const editorHtml = fs.readFileSync(`src/nodes/${e}/ui/editor.html`) + + // Load complied editor index js/ts + let indexHtml = fs.readFileSync(`dist/nodes/${e}/ui/index.js`).toString() + // Cut first 2 lines because typescript inserts some stuff that the browser does not like + // TODO: is is ugly but it works + const tmp = indexHtml.split("\n") + tmp.splice(0,2) + indexHtml = tmp.join("\n") + + // Prepare view object to be injected into render + const view = { + helpHtml, + editorHtml, + indexHtml, + nodeName: e + } + + const html = Mustache.render(htmlTemplate, view); + + // Write generated html into dist + fs.writeFileSync(`dist/nodes/${e}/${e}.html`,html) +}) + diff --git a/build/template/editor.html.mustache b/build/template/editor.html.mustache new file mode 100644 index 0000000..1fec5b9 --- /dev/null +++ b/build/template/editor.html.mustache @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 5595c10..cc972bd 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "license": "MIT", "scripts": { - "build": "tsc --build && copyfiles -u 2 './src/nodes/**/*.{png,svg,html}' ./dist/nodes/" + "build": "tsc --build && copyfiles -u 2 './src/nodes/**/*.{png,svg}' ./dist/nodes/ && node build/build.js" }, "files": [ "dist/**/*" @@ -24,6 +24,7 @@ "devDependencies": { "@types/node": "^14.14.41", "@types/node-red": "^1.1.1", - "copyfiles": "^2.4.1" + "copyfiles": "^2.4.1", + "mustache": "^4.2.0" } } diff --git a/src/nodes/ts3-config/ts3-config.html b/src/nodes/ts3-config/ts3-config.html deleted file mode 100644 index 4f2c3de..0000000 --- a/src/nodes/ts3-config/ts3-config.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/nodes/ts3-config/types.ts b/src/nodes/ts3-config/types.ts index 37ac0c2..c6ef4a0 100644 --- a/src/nodes/ts3-config/types.ts +++ b/src/nodes/ts3-config/types.ts @@ -1,10 +1,9 @@ -import { NodeDef, Node } from "node-red"; +import { NodeDef, Node, EditorNodeProperties } from "node-red"; import { TeamSpeak } from "ts3-nodejs-library" export interface Ts3ConfigProps{ host: string nickname: string - name: string } export interface Ts3ConfigCreds { @@ -16,7 +15,8 @@ export interface Ts3ConfigData { getConnection(): Promise } - export interface Ts3ConfigConfig extends NodeDef, Ts3ConfigProps, Ts3ConfigCreds { } export interface Ts3ConfigNode extends Node, Ts3ConfigData {} + +export interface Ts3ConfigEditorNodeProperties extends EditorNodeProperties,Ts3ConfigProps {} diff --git a/src/nodes/ts3-config/ui/editor.html b/src/nodes/ts3-config/ui/editor.html new file mode 100644 index 0000000..dd9a012 --- /dev/null +++ b/src/nodes/ts3-config/ui/editor.html @@ -0,0 +1,20 @@ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
\ No newline at end of file diff --git a/src/nodes/ts3-config/ui/help.html b/src/nodes/ts3-config/ui/help.html new file mode 100644 index 0000000..48150d3 --- /dev/null +++ b/src/nodes/ts3-config/ui/help.html @@ -0,0 +1 @@ +

Connection config for a Teamspeak 3 server.

\ No newline at end of file diff --git a/src/nodes/ts3-config/ui/index.ts b/src/nodes/ts3-config/ui/index.ts new file mode 100644 index 0000000..89b7ac0 --- /dev/null +++ b/src/nodes/ts3-config/ui/index.ts @@ -0,0 +1,20 @@ +import { EditorRED } from "node-red"; +import { Ts3ConfigCreds, Ts3ConfigEditorNodeProperties } from "../types"; + +declare const RED: EditorRED; + +RED.nodes.registerType('ts3-config',{ + category: 'config', + color: '#a6bbcf', + defaults: { + host: { value: ""}, + nickname: {value: "ServerQuery"} + }, + credentials: { + username: {type: "text"}, + password: {type: "password"} + }, + label: function() { + return this.name || "Ts3 Config"; + } +}); diff --git a/src/nodes/ts3-get/ts3-get.html b/src/nodes/ts3-get/ts3-get.html deleted file mode 100644 index b23c0e1..0000000 --- a/src/nodes/ts3-get/ts3-get.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/nodes/ts3-get/types.ts b/src/nodes/ts3-get/types.ts index 7fb7961..95f25e8 100644 --- a/src/nodes/ts3-get/types.ts +++ b/src/nodes/ts3-get/types.ts @@ -1,4 +1,4 @@ -import { NodeDef, Node } from "node-red"; +import { NodeDef, Node, EditorNodeProperties } from "node-red"; import { Ts3ConfigNode } from "../ts3-config/types"; export interface Ts3GetProps { @@ -13,6 +13,8 @@ export interface Ts3GetConfig extends NodeDef, Ts3GetProps { } export interface Ts3GetNode extends Node, Ts3GetData {} +export interface Ts3GetEditorNodeProperties extends EditorNodeProperties,Ts3GetProps {} + export enum GetFunctions { CLIENTS_LIST, } diff --git a/src/nodes/ts3-get/ui/editor.html b/src/nodes/ts3-get/ui/editor.html new file mode 100644 index 0000000..67adc5b --- /dev/null +++ b/src/nodes/ts3-get/ui/editor.html @@ -0,0 +1,14 @@ +
+ + +
+
+ + +
+
+ + +
\ No newline at end of file diff --git a/src/nodes/ts3-get/ui/help.html b/src/nodes/ts3-get/ui/help.html new file mode 100644 index 0000000..9ff44a7 --- /dev/null +++ b/src/nodes/ts3-get/ui/help.html @@ -0,0 +1 @@ +

Get information from a Teamspeak 3 server.

\ No newline at end of file diff --git a/src/nodes/ts3-get/ui/index.ts b/src/nodes/ts3-get/ui/index.ts new file mode 100644 index 0000000..7ce9bee --- /dev/null +++ b/src/nodes/ts3-get/ui/index.ts @@ -0,0 +1,18 @@ +import { EditorRED } from "node-red"; +import { Ts3GetEditorNodeProperties } from "../types"; + +declare const RED: EditorRED; + +RED.nodes.registerType('ts3-get',{ + category: 'function', + color: '#a6bbcf', + defaults: { + configid: { type:"ts3-config", value: "" }, + selection: { value:"" } + }, + inputs: 1, + outputs: 1, + label: function() { + return this.name || "Ts3 Get"; + } +}); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 384d9c7..465fa35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -317,6 +317,11 @@ mkdirp@^1.0.4: resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== +mustache@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.2.0.tgz#e5892324d60a12ec9c2a73359edca52972bf6f64" + integrity sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ== + noms@0.0.0: version "0.0.0" resolved "https://registry.npmjs.org/noms/-/noms-0.0.0.tgz"