@theotherwillembotha/node-red-plugincore 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +616 -220
- package/build/GenerateNodes.js +9 -33
- package/build/Nodes.html +2 -1505
- package/build/Nodes.js +5 -19
- package/build/Plugins.html +11 -0
- package/build/Plugins.js +17 -12
- package/build/core/NodeConstructor.d.ts +12 -16
- package/build/core/NodeConstructor.d.ts.map +1 -1
- package/build/core/NodeConstructor.js +125 -185
- package/build/core/NodeGenerator.d.ts +3 -1
- package/build/core/NodeGenerator.d.ts.map +1 -1
- package/build/core/NodeGenerator.js +139 -43
- package/build/core/NodeManagerRuntime.d.ts +44 -0
- package/build/core/NodeManagerRuntime.d.ts.map +1 -0
- package/build/core/NodeManagerRuntime.js +140 -0
- package/build/core/Utils.d.ts.map +1 -1
- package/build/core/logger/service/LoggerService.d.ts +8 -6
- package/build/core/logger/service/LoggerService.d.ts.map +1 -1
- package/build/core/logger/service/LoggerService.js +101 -23
- package/build/core/logger/template/LoggerTemplate.d.ts +1 -2
- package/build/core/logger/template/LoggerTemplate.d.ts.map +1 -1
- package/build/core/logger/template/LoggerTemplate.js +18 -5
- package/build/core/metrics/MetricsDecorator.d.ts +1 -2
- package/build/core/metrics/MetricsDecorator.d.ts.map +1 -1
- package/build/core/metrics/MetricsDecorator.js +89 -116
- package/build/core/metrics/node/CounterMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/CounterMetricConfigNode.js +4 -5
- package/build/core/metrics/node/GaugeMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/GaugeMetricConfigNode.js +5 -6
- package/build/core/metrics/node/MetricsConfigNode.d.ts +19 -9
- package/build/core/metrics/node/MetricsConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/MetricsConfigNode.js +14 -45
- package/build/core/metrics/node/TimerMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/TimerMetricConfigNode.js +11 -17
- package/build/core/metrics/service/MetricsService.d.ts +110 -114
- package/build/core/metrics/service/MetricsService.d.ts.map +1 -1
- package/build/core/metrics/service/MetricsService.js +122 -339
- package/build/core/metrics/template/CounterMetricTemplate.d.ts +1 -2
- package/build/core/metrics/template/CounterMetricTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/CounterMetricTemplate.js +16 -5
- package/build/core/metrics/template/GaugeMetricTemplate.d.ts +1 -2
- package/build/core/metrics/template/GaugeMetricTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/GaugeMetricTemplate.js +16 -5
- package/build/core/metrics/template/MetricsTemplate.d.ts +1 -2
- package/build/core/metrics/template/MetricsTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/MetricsTemplate.js +18 -6
- package/build/core/metrics/template/TimerMetricTemplate.d.ts +1 -2
- package/build/core/metrics/template/TimerMetricTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/TimerMetricTemplate.js +16 -5
- package/build/core/other/node/DelegatedConfigReferenceNode.d.ts +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.d.ts.map +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.js +1 -1
- package/build/core/other/service/InputService.d.ts.map +1 -1
- package/build/core/other/service/SettingsService.d.ts +1 -2
- package/build/core/other/service/SettingsService.d.ts.map +1 -1
- package/build/core/other/service/SettingsService.js +19 -5
- package/build/core/other/template/BasicTemplate.d.ts +1 -2
- package/build/core/other/template/BasicTemplate.d.ts.map +1 -1
- package/build/core/other/template/BasicTemplate.js +15 -5
- package/build/core/other/template/SettingsTemplate.d.ts +1 -2
- package/build/core/other/template/SettingsTemplate.d.ts.map +1 -1
- package/build/core/other/template/SettingsTemplate.js +17 -5
- package/build/core/state/node/InternalStateConfigNode.d.ts +16 -0
- package/build/core/state/node/InternalStateConfigNode.d.ts.map +1 -0
- package/build/core/state/node/InternalStateConfigNode.js +89 -0
- package/build/core/state/node/StateConfigNode.d.ts +24 -0
- package/build/core/state/node/StateConfigNode.d.ts.map +1 -0
- package/build/core/state/node/StateConfigNode.js +22 -0
- package/build/core/state/service/StateService.d.ts +34 -0
- package/build/core/state/service/StateService.d.ts.map +1 -0
- package/build/core/state/service/StateService.js +201 -0
- package/build/core/state/template/StateTemplate.d.ts +7 -0
- package/build/core/state/template/StateTemplate.d.ts.map +1 -0
- package/build/core/state/template/StateTemplate.js +25 -0
- package/build/core/tagging/ServiceDescriptionDecorator.d.ts +10 -0
- package/build/core/tagging/ServiceDescriptionDecorator.d.ts.map +1 -0
- package/build/core/tagging/ServiceDescriptionDecorator.js +10 -0
- package/build/core/tagging/TemplateDescriptionDecorator.d.ts +8 -0
- package/build/core/tagging/TemplateDescriptionDecorator.d.ts.map +1 -0
- package/build/core/tagging/TemplateDescriptionDecorator.js +10 -0
- package/build/core/tagging/service/NodeTypeService.d.ts +1 -2
- package/build/core/tagging/service/NodeTypeService.d.ts.map +1 -1
- package/build/core/tagging/service/NodeTypeService.js +19 -5
- package/build/core/ui/template/ScriptEditorTemplate.d.ts +1 -2
- package/build/core/ui/template/ScriptEditorTemplate.d.ts.map +1 -1
- package/build/core/ui/template/ScriptEditorTemplate.js +15 -5
- package/build/core/ui/template/UIHelperTemplate.d.ts +1 -2
- package/build/core/ui/template/UIHelperTemplate.d.ts.map +1 -1
- package/build/core/ui/template/UIHelperTemplate.js +15 -5
- package/build/core/webhook/node/WebhookServerConfigNode.d.ts.map +1 -1
- package/build/core/webhook/service/ReverseProxyTypeService.d.ts.map +1 -1
- package/build/core/webhook/service/WebhookServerService.d.ts +3 -4
- package/build/core/webhook/service/WebhookServerService.d.ts.map +1 -1
- package/build/core/webhook/service/WebhookServerService.js +48 -18
- package/build/core/webhook/template/WebhookTemplate.d.ts +1 -2
- package/build/core/webhook/template/WebhookTemplate.d.ts.map +1 -1
- package/build/core/webhook/template/WebhookTemplate.js +19 -6
- package/build/index.d.ts +6 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -2
- package/build/runtime/NodeManagerRuntime.js +140 -0
- package/documentation/CounterMetricConfigNode.png +0 -0
- package/documentation/GaugeMetricConfigNode.png +0 -0
- package/documentation/LoggerTemplate.png +0 -0
- package/documentation/MetricsTemplate.png +0 -0
- package/documentation/StateTemplate.png +0 -0
- package/documentation/TimerMetricConfigNode_histogram.png +0 -0
- package/documentation/TimerMetricConfigNode_summary.png +0 -0
- package/documentation/WebhookServerConfigNode.png +0 -0
- package/documentation/WebhookTemplate.png +0 -0
- package/package.json +4 -11
- package/src/GenerateNodes.ts +10 -40
- package/src/core/NodeConstructor.ts +150 -228
- package/src/core/NodeGenerator.ts +156 -47
- package/src/core/NodeManagerRuntime.ts +179 -0
- package/src/core/logger/service/LoggerService.ts +60 -32
- package/src/core/logger/template/LoggerTemplate.html +11 -6
- package/src/core/logger/template/LoggerTemplate.ts +9 -11
- package/src/core/metrics/MetricsDecorator.ts +140 -168
- package/src/core/metrics/node/CounterMetricConfigNode.ts +20 -20
- package/src/core/metrics/node/GaugeMetricConfigNode.ts +24 -25
- package/src/core/metrics/node/MetricsConfigNode.ts +29 -48
- package/src/core/metrics/node/TimerMetricConfigNode.ts +50 -59
- package/src/core/metrics/service/MetricsService.ts +214 -489
- package/src/core/metrics/template/CounterMetricTemplate.html +0 -1
- package/src/core/metrics/template/CounterMetricTemplate.ts +8 -11
- package/src/core/metrics/template/GaugeMetricTemplate.html +1 -1
- package/src/core/metrics/template/GaugeMetricTemplate.ts +8 -11
- package/src/core/metrics/template/MetricsTemplate.html +132 -13
- package/src/core/metrics/template/MetricsTemplate.ts +9 -10
- package/src/core/metrics/template/TimerMetricTemplate.ts +8 -10
- package/src/core/other/node/DelegatedConfigReferenceNode.ts +1 -1
- package/src/core/other/service/SettingsService.ts +6 -10
- package/src/core/other/template/BasicTemplate.html +1 -1
- package/src/core/other/template/BasicTemplate.ts +6 -11
- package/src/core/other/template/SettingsTemplate.ts +8 -13
- package/src/core/state/node/InternalStateConfigNode.html +77 -0
- package/src/core/state/node/InternalStateConfigNode.ts +102 -0
- package/src/core/state/node/StateConfigNode.ts +29 -0
- package/src/core/state/service/StateService.ts +180 -0
- package/src/core/state/template/StateTemplate.html +244 -0
- package/src/core/state/template/StateTemplate.ts +18 -0
- package/src/core/tagging/ServiceDescriptionDecorator.ts +23 -0
- package/src/core/tagging/TemplateDescriptionDecorator.ts +19 -0
- package/src/core/tagging/service/NodeTypeService.ts +6 -11
- package/src/core/ui/template/ScriptEditorTemplate.ts +6 -10
- package/src/core/ui/template/UIHelperTemplate.html +41 -26
- package/src/core/ui/template/UIHelperTemplate.ts +6 -10
- package/src/core/webhook/service/WebhookServerService.ts +39 -23
- package/src/core/webhook/template/WebhookTemplate.html +28 -35
- package/src/core/webhook/template/WebhookTemplate.ts +10 -12
- package/src/index.ts +8 -2
- package/build/core/logger/node/ConsoleLoggerConfigNode.d.ts +0 -20
- package/build/core/logger/node/ConsoleLoggerConfigNode.d.ts.map +0 -1
- package/build/core/logger/node/ConsoleLoggerConfigNode.js +0 -62
- package/build/core/logger/node/RestLoggerConfigNode.d.ts +0 -40
- package/build/core/logger/node/RestLoggerConfigNode.d.ts.map +0 -1
- package/build/core/logger/node/RestLoggerConfigNode.js +0 -128
- package/documentation/ConsoleLoggerConfigNode.png +0 -0
- package/documentation/MetricsConfigNode.png +0 -0
- package/documentation/RestLoggerConfigNode.png +0 -0
- package/documentation/TimerMetricConfigNode.png +0 -0
- package/documentation/WebhookNode.png +0 -0
- package/src/core/logger/node/ConsoleLoggerConfigNode.html +0 -90
- package/src/core/logger/node/ConsoleLoggerConfigNode.ts +0 -71
- package/src/core/logger/node/RestLoggerConfigNode.html +0 -183
- package/src/core/logger/node/RestLoggerConfigNode.ts +0 -170
package/build/Nodes.js
CHANGED
|
@@ -8,25 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
|
-
const NodeManager = require("
|
|
12
|
-
|
|
13
|
-
const ConsoleLoggerConfigNode = require("@theotherwillembotha/node-red-plugincore").ConsoleLoggerConfigNode;
|
|
14
|
-
const RestLoggerConfigNode = require("@theotherwillembotha/node-red-plugincore").RestLoggerConfigNode;
|
|
15
|
-
const MetricsConfigNode = require("@theotherwillembotha/node-red-plugincore").MetricsConfigNode;
|
|
16
|
-
const CounterMetricConfigNode = require("@theotherwillembotha/node-red-plugincore").CounterMetricConfigNode;
|
|
17
|
-
const GaugeMetricConfigNode = require("@theotherwillembotha/node-red-plugincore").GaugeMetricConfigNode;
|
|
18
|
-
const TimerMetricConfigNode = require("@theotherwillembotha/node-red-plugincore").TimerMetricConfigNode;
|
|
19
|
-
const WebhookServerConfigNode = require("@theotherwillembotha/node-red-plugincore").WebhookServerConfigNode;
|
|
11
|
+
const { NodeManager } = require("./runtime/NodeManagerRuntime");
|
|
12
|
+
|
|
20
13
|
module.exports = (RED) => {
|
|
21
14
|
let manager = new NodeManager(RED);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
manager.registerNodeType("MetricsConfigNode", MetricsConfigNode);
|
|
26
|
-
manager.registerNodeType("CounterMetricConfigNode", CounterMetricConfigNode);
|
|
27
|
-
manager.registerNodeType("GaugeMetricConfigNode", GaugeMetricConfigNode);
|
|
28
|
-
manager.registerNodeType("TimerMetricConfigNode", TimerMetricConfigNode);
|
|
29
|
-
manager.registerNodeType("WebhookServerConfigNode", WebhookServerConfigNode);
|
|
30
|
-
}
|
|
31
|
-
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
32
18
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
<!--
|
|
3
|
+
|
|
4
|
+
This file was automatically generated using the NODERED Core utility.
|
|
5
|
+
Any modifications to his file will be overwritten the next time the code is regenerated.
|
|
6
|
+
|
|
7
|
+
You have been warned.
|
|
8
|
+
|
|
9
|
+
No shared nodes in this package. All nodes are registered via Nodes.html.
|
|
10
|
+
-->
|
|
11
|
+
|
package/build/Plugins.js
CHANGED
|
@@ -9,16 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
11
|
const runtime = require("node-red").runtime;
|
|
12
|
-
const LoggerService = require("@theotherwillembotha/node-red-plugincore").LoggerService;
|
|
13
|
-
const MetricsService = require("@theotherwillembotha/node-red-plugincore").MetricsService;
|
|
14
|
-
const SettingsService = require("@theotherwillembotha/node-red-plugincore").SettingsService;
|
|
15
|
-
const WebhookServerService = require("@theotherwillembotha/node-red-plugincore").WebhookServerService;
|
|
16
12
|
const NodeTypeService = require("@theotherwillembotha/node-red-plugincore").NodeTypeService;
|
|
17
13
|
|
|
18
14
|
module.exports = function (RED) {
|
|
19
15
|
|
|
20
16
|
// 1. make a list of all the plugins that need to be installed.
|
|
21
|
-
let pluginList = [
|
|
17
|
+
let pluginList = [NodeTypeService]
|
|
22
18
|
.map(service => service.getServiceDescriptor())
|
|
23
19
|
.filter(plugin => !RED.plugins.get(plugin.id()));
|
|
24
20
|
|
|
@@ -31,29 +27,38 @@ module.exports = function (RED) {
|
|
|
31
27
|
|
|
32
28
|
if(addedPlugin && plugin.instantiate && !plugin.instance){
|
|
33
29
|
plugin.instance = new plugin.class();
|
|
34
|
-
|
|
30
|
+
|
|
35
31
|
// instantiate the plugin.
|
|
36
32
|
await plugin.instance.init(RED);
|
|
37
33
|
|
|
34
|
+
// Eagerly call onDeploy with any pre-existing saved flows so that
|
|
35
|
+
// service registries (MetricsService, WebhookServerService, etc.) are
|
|
36
|
+
// populated before config nodes are constructed during flow startup.
|
|
37
|
+
// Without this, MetricsConfigNode._metrics is undefined on first boot.
|
|
38
|
+
const existingFlows = await runtime.flows.getFlows({});
|
|
39
|
+
const hasExistingFlows = existingFlows && existingFlows.flows && existingFlows.flows.length > 0;
|
|
40
|
+
if (hasExistingFlows) {
|
|
41
|
+
await plugin.instance.onDeploy(existingFlows);
|
|
42
|
+
}
|
|
43
|
+
|
|
38
44
|
// publish an event that it has ben deployed.
|
|
39
45
|
RED.events.emit("plugin.instantiated", pluginID);
|
|
40
|
-
|
|
46
|
+
|
|
41
47
|
pluginList.splice(pluginList.findIndex(current => current.id() === addedPlugin.id()), 1);
|
|
42
48
|
|
|
43
49
|
// register a flow deployment listener.
|
|
44
|
-
|
|
50
|
+
// startupDeployment is only needed for a truly fresh Node-RED with no saved flows.
|
|
51
|
+
let startupDeployment = !hasExistingFlows;
|
|
45
52
|
RED.events.on('runtime-event', async (event) => {
|
|
46
|
-
// startup deployment.
|
|
53
|
+
// startup deployment (fresh Node-RED with no pre-existing flows).
|
|
47
54
|
if ("runtime-deploy" === event?.id && startupDeployment) {
|
|
48
|
-
//console.log("STARTUP DEPLOYMENT");
|
|
49
55
|
startupDeployment = false;
|
|
50
56
|
const flows = await runtime.flows.getFlows({});
|
|
51
57
|
await plugin.instance.onDeploy(flows);
|
|
52
58
|
}
|
|
53
|
-
|
|
59
|
+
|
|
54
60
|
// stopping flows on redeployment.
|
|
55
61
|
if ("runtime-state" === event?.id && event?.payload?.state === "stop" && event?.payload?.deploy) {
|
|
56
|
-
//console.log("REDEPLOY!");
|
|
57
62
|
const flows = await runtime.flows.getFlows({});
|
|
58
63
|
await plugin.instance.onDeploy(flows);
|
|
59
64
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Node, NodeAPI, NodeAPISettingsWithData } from "node-red";
|
|
2
2
|
import { INamedType, INodeClass, ITemplateClass } from "./NodeGenerator";
|
|
3
3
|
import "reflect-metadata";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
name: string;
|
|
7
|
-
type: string;
|
|
8
|
-
}
|
|
4
|
+
import { NODEMANAGER_API_VERSION, POST_CONSTRUCT_KEY, BaseNodeConfig, runPostConstructInitializers, NodeManager } from "./NodeManagerRuntime";
|
|
5
|
+
export { NODEMANAGER_API_VERSION, POST_CONSTRUCT_KEY, BaseNodeConfig, runPostConstructInitializers, NodeManager };
|
|
9
6
|
export declare abstract class BaseNode<Config extends BaseNodeConfig> {
|
|
10
7
|
private _node;
|
|
11
8
|
node(): Node<{}>;
|
|
@@ -102,16 +99,6 @@ declare class PostConstructDecoratorBuilder<TMetadata = any> {
|
|
|
102
99
|
build(): any;
|
|
103
100
|
}
|
|
104
101
|
export declare function createPostConstructDecorator<TMetadata = any>(decoratorName: string): PostConstructDecoratorBuilder<TMetadata>;
|
|
105
|
-
export declare class NodeManager {
|
|
106
|
-
private static PLUGINID;
|
|
107
|
-
private static _RED;
|
|
108
|
-
private nodeTypeService;
|
|
109
|
-
private typeBacklog;
|
|
110
|
-
constructor(RED: NodeAPI<NodeAPISettingsWithData>);
|
|
111
|
-
static get RED(): NodeAPI<NodeAPISettingsWithData>;
|
|
112
|
-
registerService(type: IServiceClass): NodeManager;
|
|
113
|
-
registerNodeType(typeName: string, type: INodeClass): NodeManager;
|
|
114
|
-
}
|
|
115
102
|
export type FlowDeployment = {
|
|
116
103
|
rev: string;
|
|
117
104
|
flows: [FlowElement];
|
|
@@ -177,6 +164,14 @@ export declare class NodeBuilder {
|
|
|
177
164
|
addIncludeEditDelete(source: string, script: string): NodeBuilder;
|
|
178
165
|
addIncludeEditForm(source: string, script: string): NodeBuilder;
|
|
179
166
|
addIncludeDocumentation(source: string, script: string): NodeBuilder;
|
|
167
|
+
buildOnceHtml(): {
|
|
168
|
+
source: string;
|
|
169
|
+
html: string;
|
|
170
|
+
}[];
|
|
171
|
+
private applyShaddowDefaults;
|
|
172
|
+
private buildRegisterTypeBody;
|
|
173
|
+
buildDeferredType(): string;
|
|
174
|
+
buildStandardType(): string;
|
|
180
175
|
private serializeProperty;
|
|
181
176
|
private serializeHTML;
|
|
182
177
|
private serializeJavaScript;
|
|
@@ -187,6 +182,7 @@ export declare class NodeBuilder {
|
|
|
187
182
|
buildHtml(): string;
|
|
188
183
|
buildDocumentation(): string;
|
|
189
184
|
}
|
|
185
|
+
declare let buildNodeBuilder: (node: INodeClass) => NodeBuilder;
|
|
190
186
|
declare let buildNode: (node: INodeClass) => string;
|
|
191
|
-
export { buildNode };
|
|
187
|
+
export { buildNode, buildNodeBuilder };
|
|
192
188
|
//# sourceMappingURL=NodeConstructor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeConstructor.d.ts","sourceRoot":"","sources":["../../src/core/NodeConstructor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NodeConstructor.d.ts","sourceRoot":"","sources":["../../src/core/NodeConstructor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,uBAAuB,EAAC,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,kBAAkB,CAAC;AAG1B,OAAO,EACH,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,4BAA4B,EAC5B,WAAW,EACd,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACH,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,4BAA4B,EAC5B,WAAW,EACd,CAAC;AAEF,8BAAsB,QAAQ,CAAC,MAAM,SAAS,cAAc;IAExD,OAAO,CAAC,KAAK,CAAM;IACZ,IAAI,aAAyB;IAEpC,OAAO,CAAC,OAAO,CAAQ;IAChB,MAAM,WAA2B;IAExC,OAAO,CAAC,KAAK,CAAO;IACb,IAAI,WAAyB;IAG7B,EAAE,WAA8B;IAChC,IAAI,WAAgC;IACpC,IAAI,WAAgC;IAE3C,SAAS,aAAa,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAO/C;IAID,SAAS,CAAC,MAAM,SAAI;IAGpB,OAAc,iBAAiB,IAAG,cAAc,CAE/C;CACJ;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CACvD;AAED,8BAAsB,UAAU,CAAC,MAAM,SAAS,gBAAgB,CAAE,SAAQ,QAAQ,CAAC,MAAM,CAAC;IAEtF,SAAS,aAAa,IAAI,EAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAE9C;IAED,OAAc,iBAAiB,IAAG,cAA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AG,MAAM,CAMxB;IAEM,kBAAkB,IAAG,MAAM,CAMjC;CAGJ;AAiBD,QAAA,IAAI,gBAAgB,SAAkB,UAAU,KAAG,WA2BlD,CAAA;AAED,QAAA,IAAI,SAAS,SAAiB,UAAU,WAGvC,CAAA;AAED,OAAO,EACH,SAAS,EACT,gBAAgB,EACnB,CAAA"}
|
|
@@ -3,14 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.buildNodeBuilder = exports.buildNode = exports.NodeBuilder = exports.BaseService = exports.Template = exports.ServiceDescriptor = exports.TemplateDescriptor = exports.NodeDescriptor = exports.ConfigNode = exports.BaseNode = exports.NodeManager = exports.runPostConstructInitializers = exports.POST_CONSTRUCT_KEY = exports.NODEMANAGER_API_VERSION = void 0;
|
|
7
7
|
exports.createPostConstructDecorator = createPostConstructDecorator;
|
|
8
8
|
require("reflect-metadata");
|
|
9
|
-
const jsdom_1 = __importDefault(require("jsdom"));
|
|
10
9
|
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const NodeManagerRuntime_1 = require("./NodeManagerRuntime");
|
|
11
|
+
Object.defineProperty(exports, "NODEMANAGER_API_VERSION", { enumerable: true, get: function () { return NodeManagerRuntime_1.NODEMANAGER_API_VERSION; } });
|
|
12
|
+
Object.defineProperty(exports, "POST_CONSTRUCT_KEY", { enumerable: true, get: function () { return NodeManagerRuntime_1.POST_CONSTRUCT_KEY; } });
|
|
13
|
+
Object.defineProperty(exports, "runPostConstructInitializers", { enumerable: true, get: function () { return NodeManagerRuntime_1.runPostConstructInitializers; } });
|
|
14
|
+
Object.defineProperty(exports, "NodeManager", { enumerable: true, get: function () { return NodeManagerRuntime_1.NodeManager; } });
|
|
14
15
|
class BaseNode {
|
|
15
16
|
node() { return this._node; }
|
|
16
17
|
config() { return this._config; }
|
|
@@ -135,7 +136,6 @@ class Template {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
exports.Template = Template;
|
|
138
|
-
const POST_CONSTRUCT_KEY = Symbol('postConstructInitializers');
|
|
139
139
|
// Builder class for post-construct decorators
|
|
140
140
|
class PostConstructDecoratorBuilder {
|
|
141
141
|
constructor(decoratorName) {
|
|
@@ -201,10 +201,10 @@ class PostConstructDecoratorBuilder {
|
|
|
201
201
|
` Issue: Method returned a value (${typeof result}) but should return void or Promise<void>.`);
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
|
-
if (!target[POST_CONSTRUCT_KEY]) {
|
|
205
|
-
target[POST_CONSTRUCT_KEY] = [];
|
|
204
|
+
if (!target[NodeManagerRuntime_1.POST_CONSTRUCT_KEY]) {
|
|
205
|
+
target[NodeManagerRuntime_1.POST_CONSTRUCT_KEY] = [];
|
|
206
206
|
}
|
|
207
|
-
target[POST_CONSTRUCT_KEY].push((instance) => {
|
|
207
|
+
target[NodeManagerRuntime_1.POST_CONSTRUCT_KEY].push((instance) => {
|
|
208
208
|
if (initLogic) {
|
|
209
209
|
try {
|
|
210
210
|
initLogic(instance, propertyKey, config);
|
|
@@ -245,117 +245,6 @@ class PostConstructDecoratorBuilder {
|
|
|
245
245
|
function createPostConstructDecorator(decoratorName) {
|
|
246
246
|
return new PostConstructDecoratorBuilder(decoratorName);
|
|
247
247
|
}
|
|
248
|
-
// Single function to run all post-construct initializers
|
|
249
|
-
let runPostConstructInitializers = function (instance) {
|
|
250
|
-
const initializers = instance[POST_CONSTRUCT_KEY];
|
|
251
|
-
if (initializers && initializers.length > 0) {
|
|
252
|
-
const className = instance.constructor.name;
|
|
253
|
-
//console.log(`Running ${initializers.length} post-construct initializers for ${className}`);
|
|
254
|
-
initializers.forEach((init, index) => {
|
|
255
|
-
try {
|
|
256
|
-
init(instance);
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
console.error(`Post-construct initialization failed:\n` +
|
|
260
|
-
` Class: ${className}\n` +
|
|
261
|
-
` Initializer: ${index + 1}/${initializers.length}\n` +
|
|
262
|
-
` Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
263
|
-
throw error;
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
// Clear the initializers after running
|
|
267
|
-
delete instance[POST_CONSTRUCT_KEY];
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
// ************************************************
|
|
271
|
-
class NodeManager {
|
|
272
|
-
static { this.PLUGINID = "node-red-contrib-theotherwillembotha/services-plugin"; }
|
|
273
|
-
constructor(RED) {
|
|
274
|
-
this.typeBacklog = [];
|
|
275
|
-
NodeManager._RED = RED;
|
|
276
|
-
let nodeTypeServiceListener = async (pluginID) => {
|
|
277
|
-
if (pluginID === "@theotherwillembotha/nodetypeservice") {
|
|
278
|
-
// disable the listener- the plugin has been installed.
|
|
279
|
-
RED.events.off('plugin.instantiated', nodeTypeServiceListener);
|
|
280
|
-
// get a handle on the NodeTypeService
|
|
281
|
-
let plugin = RED.plugins.get("@theotherwillembotha/nodetypeservice");
|
|
282
|
-
this.nodeTypeService = RED.plugins.get("@theotherwillembotha/nodetypeservice").instance;
|
|
283
|
-
// process the backlog.
|
|
284
|
-
for (let nodeType of this.typeBacklog) {
|
|
285
|
-
for (let tag of nodeType.getNodeDescriptor().tags()) {
|
|
286
|
-
this.nodeTypeService.registerNodeType(tag, nodeType);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
// check if the reverserproxyttypesewrvice is installed yet.
|
|
292
|
-
this.nodeTypeService = RED.plugins.get("@theotherwillembotha/nodetypeservice").instance;
|
|
293
|
-
if (!this.nodeTypeService) {
|
|
294
|
-
RED.events.on('plugin.instantiated', nodeTypeServiceListener);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
static get RED() {
|
|
298
|
-
return NodeManager._RED;
|
|
299
|
-
}
|
|
300
|
-
registerService(type) {
|
|
301
|
-
let servicePlugin = NodeManager.RED.plugins.get(NodeManager.PLUGINID);
|
|
302
|
-
if (servicePlugin) {
|
|
303
|
-
servicePlugin.instance.install(NodeManager.RED, type);
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
let serviceName = `${type.getServiceDescriptor().sourceFile()}.${type.getServiceDescriptor().name()}`;
|
|
307
|
-
console.log(`ERROR: plugin ${NodeManager.PLUGINID} does not seem to be loaded. Cannot start service: ${serviceName}`);
|
|
308
|
-
}
|
|
309
|
-
return this;
|
|
310
|
-
}
|
|
311
|
-
registerNodeType(typeName, type) {
|
|
312
|
-
if (!type) {
|
|
313
|
-
console.error(`Type "${typeName}" has no associated type. Make sure that it was exported and included in the index.js file!`);
|
|
314
|
-
}
|
|
315
|
-
let nodeConstructor = function (config) {
|
|
316
|
-
//console.log("constructing node", typeName);
|
|
317
|
-
try {
|
|
318
|
-
// instantiate the node.
|
|
319
|
-
NodeManager.RED.nodes.createNode(this, config);
|
|
320
|
-
// assign an instance of it to the config.
|
|
321
|
-
//(config as any).__node = this;
|
|
322
|
-
// instatiate the actual node.
|
|
323
|
-
let node = new type(this, config);
|
|
324
|
-
//this.__node = node;
|
|
325
|
-
// run the constructor initializers.
|
|
326
|
-
runPostConstructInitializers(node);
|
|
327
|
-
// after the node has been instantiated, attempt to invole the onInit method.
|
|
328
|
-
if (node.onInit) {
|
|
329
|
-
node.onInit();
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
catch (error) {
|
|
333
|
-
console.log(error);
|
|
334
|
-
console.log("typeName:", typeName);
|
|
335
|
-
console.log("type:", type);
|
|
336
|
-
console.log("config:", config);
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
try {
|
|
340
|
-
NodeManager.RED.nodes.registerType(typeName, nodeConstructor, { settings: {} });
|
|
341
|
-
let nodeDescription = type.getNodeDescriptor();
|
|
342
|
-
// registger the node tags.
|
|
343
|
-
if (this.nodeTypeService) {
|
|
344
|
-
for (let tag of nodeDescription.tags()) {
|
|
345
|
-
this.nodeTypeService.registerNodeType(tag, type);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
this.typeBacklog.push(type);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
catch (error) {
|
|
353
|
-
console.error("registering node: " + typeName + " failed", error);
|
|
354
|
-
}
|
|
355
|
-
return this;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
exports.NodeManager = NodeManager;
|
|
359
248
|
class BaseService {
|
|
360
249
|
constructor(name) {
|
|
361
250
|
this._name = name;
|
|
@@ -371,23 +260,26 @@ class BaseService {
|
|
|
371
260
|
}
|
|
372
261
|
}
|
|
373
262
|
exports.BaseService = BaseService;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
};
|
|
263
|
+
// Build-time deps - lazy loaded so they are never required at runtime in production bundles.
|
|
264
|
+
// These are only invoked during `npm run build` (GenerateNodes), never in the deployed container.
|
|
265
|
+
function getJSDOM() { return require('jsdom').JSDOM; }
|
|
266
|
+
function getBeautify() { return require('js-beautify'); }
|
|
267
|
+
function getHandlebars() { return require('handlebars'); }
|
|
268
|
+
let _md = null;
|
|
269
|
+
function getMd() {
|
|
270
|
+
if (!_md) {
|
|
271
|
+
_md = require('markdown-it')({ html: true, linkify: true, typographer: true });
|
|
272
|
+
_md.renderer.rules.heading_open = (tokens, idx) => {
|
|
273
|
+
const level = tokens[idx].tag.substring(1);
|
|
274
|
+
return `<h${level} class="custom-heading">`;
|
|
275
|
+
};
|
|
276
|
+
_md.renderer.rules.heading_close = (tokens, idx) => {
|
|
277
|
+
const level = tokens[idx].tag.substring(1);
|
|
278
|
+
return `</h${level}>`;
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return _md;
|
|
282
|
+
}
|
|
391
283
|
let beautifyOptions = {
|
|
392
284
|
"indent_size": 4,
|
|
393
285
|
"preserve-newlines": false,
|
|
@@ -423,7 +315,7 @@ class NodeBuilder {
|
|
|
423
315
|
this._category = category;
|
|
424
316
|
}
|
|
425
317
|
addDefault(name, template) {
|
|
426
|
-
// if list:true, this is an array of config references
|
|
318
|
+
// if list:true, this is an array of config references - generate shadow defaults for each slot.
|
|
427
319
|
if (template.list === true) {
|
|
428
320
|
template.maxInstances = template.maxInstances ? template.maxInstances : 10;
|
|
429
321
|
this._defaults[name] = { value: "", required: (template.required) ? template.required : false, maxInstances: template.maxInstances };
|
|
@@ -466,8 +358,9 @@ class NodeBuilder {
|
|
|
466
358
|
}
|
|
467
359
|
addTemplate(template) {
|
|
468
360
|
let templateDescriptor = template.template.getTemplateDescriptor();
|
|
361
|
+
let templateConfig = template.config;
|
|
469
362
|
// load the html source file
|
|
470
|
-
let uiDom = new
|
|
363
|
+
let uiDom = new (getJSDOM())(fs_1.default.readFileSync(templateDescriptor.templateFile()));
|
|
471
364
|
// apply the onCompose section if available.
|
|
472
365
|
let onCompose = uiDom.window.document.querySelector("script[template-section='onCompose']")?.innerHTML;
|
|
473
366
|
if (onCompose) {
|
|
@@ -478,6 +371,14 @@ class NodeBuilder {
|
|
|
478
371
|
Object.values(sections).forEach(section => {
|
|
479
372
|
let sectionData = uiDom.window.document.querySelector(`[template-section='on${section}']`)?.innerHTML;
|
|
480
373
|
if (sectionData) {
|
|
374
|
+
if (section !== "IncludeOnce" && section !== "IncludeEditForm" && section !== "IncludeDocumentation") {
|
|
375
|
+
// add the packageing around the sectionData
|
|
376
|
+
sectionData = `{
|
|
377
|
+
let node = this;
|
|
378
|
+
let templateConfig = ${JSON.stringify(templateConfig)};
|
|
379
|
+
${sectionData}
|
|
380
|
+
}`;
|
|
381
|
+
}
|
|
481
382
|
this[`add${section}`](templateDescriptor.name(), sectionData);
|
|
482
383
|
}
|
|
483
384
|
});
|
|
@@ -511,6 +412,76 @@ class NodeBuilder {
|
|
|
511
412
|
this._onIncludeDocumentation.push({ source: source, script: script });
|
|
512
413
|
return this;
|
|
513
414
|
}
|
|
415
|
+
buildOnceHtml() {
|
|
416
|
+
return this._onIncludeOnce.map(entry => ({
|
|
417
|
+
source: entry.source,
|
|
418
|
+
html: this.serializeHTML(entry.source, entry.script)
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
421
|
+
applyShaddowDefaults() {
|
|
422
|
+
let shaddowDefaults = Object.entries(this._defaults).filter(([name, template]) => template.type && template.type.endsWith("[]"));
|
|
423
|
+
if (shaddowDefaults.length > 0) {
|
|
424
|
+
this.addIncludeEditSave(this._name + "_shaddowDefaults", `{ let node = this; ` +
|
|
425
|
+
shaddowDefaults
|
|
426
|
+
.map(([name, template]) => `
|
|
427
|
+
for(let i = 0; i < ${template.maxInstances}; i++){
|
|
428
|
+
node["_${name}_" + i] = (node.${name}[i] || {}).proxy || "";
|
|
429
|
+
}`)
|
|
430
|
+
.join("\n\n") +
|
|
431
|
+
`}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
buildRegisterTypeBody() {
|
|
435
|
+
return `{
|
|
436
|
+
category: '${this._category}',
|
|
437
|
+
${(this._category !== "config" && this._icon) ? `icon: '${this._icon}',` : ""}
|
|
438
|
+
${(this._category !== "config" && this._color) ? `color: '${this._color}',` : ""}
|
|
439
|
+
${(this._category !== "config" && this._labelStyle) ? `labelStyle: '${this._labelStyle}',` : ""}
|
|
440
|
+
${(this._label) ? `label: ${this._label},` : ""}
|
|
441
|
+
${this._paletteLabel ? `paletteLabel: '${this._paletteLabel}',` : ""}
|
|
442
|
+
${(this._category !== "config") ? `inputs:${this._inputs ? "1" : "0"},` : ""}
|
|
443
|
+
${(this._category !== "config") ? `inputLabels:(i) => '${this._inputs}',` : ""}
|
|
444
|
+
${(this._category !== "config") ? `outputs:${this._outputs.length},` : ""}
|
|
445
|
+
${(this._category !== "config") ? `outputLabels:(i) => ${this.serializeProperty(this._outputs)}[i],` : ""}
|
|
446
|
+
defaults: {
|
|
447
|
+
${Object.entries(this._defaults).map(([key, value]) => this.serializeDefault(key, value)).join("\n")}
|
|
448
|
+
},
|
|
449
|
+
oneditprepare: function() {
|
|
450
|
+
${this._onIncludeEditPrepare.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
451
|
+
},
|
|
452
|
+
oneditsave: function() {
|
|
453
|
+
${this._onIncludeEditSave.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
454
|
+
},
|
|
455
|
+
oneditcancel: function() {
|
|
456
|
+
${this._onIncludeEditCancel.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
457
|
+
},
|
|
458
|
+
oneditdelete: function() {
|
|
459
|
+
${this._onIncludeEditDelete.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
460
|
+
},
|
|
461
|
+
}`;
|
|
462
|
+
}
|
|
463
|
+
buildDeferredType() {
|
|
464
|
+
this.applyShaddowDefaults();
|
|
465
|
+
const registerTypeBody = this.buildRegisterTypeBody();
|
|
466
|
+
return getBeautify().html_beautify(`
|
|
467
|
+
<script type="text/javascript">
|
|
468
|
+
(function () {
|
|
469
|
+
RED.events.on('registry:node-set-added', function (ns) {
|
|
470
|
+
if (ns.types && ns.types.indexOf('${this._name}') !== -1) {
|
|
471
|
+
RED.nodes.registerType('${this._name}', ${registerTypeBody});
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}());
|
|
475
|
+
</script>`, beautifyOptions);
|
|
476
|
+
}
|
|
477
|
+
buildStandardType() {
|
|
478
|
+
this.applyShaddowDefaults();
|
|
479
|
+
const registerTypeBody = this.buildRegisterTypeBody();
|
|
480
|
+
return getBeautify().html_beautify(`
|
|
481
|
+
<script type="text/javascript">
|
|
482
|
+
RED.nodes.registerType('${this._name}', ${registerTypeBody});
|
|
483
|
+
</script>`, beautifyOptions);
|
|
484
|
+
}
|
|
514
485
|
serializeProperty(value) {
|
|
515
486
|
switch (typeof value) {
|
|
516
487
|
case "boolean": {
|
|
@@ -540,7 +511,7 @@ class NodeBuilder {
|
|
|
540
511
|
: Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-input-${k}`]))
|
|
541
512
|
};
|
|
542
513
|
return `<!-- ${source} -->
|
|
543
|
-
${
|
|
514
|
+
${getHandlebars().compile(script)(context)}
|
|
544
515
|
`;
|
|
545
516
|
}
|
|
546
517
|
serializeJavaScript(source, script) {
|
|
@@ -549,7 +520,7 @@ class NodeBuilder {
|
|
|
549
520
|
? Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-config-input-${k}`]))
|
|
550
521
|
: Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-input-${k}`]))
|
|
551
522
|
};
|
|
552
|
-
let serialized =
|
|
523
|
+
let serialized = getHandlebars().compile(script)(context).trim();
|
|
553
524
|
if (!serialized.startsWith("{") && !serialized.endsWith("}")) {
|
|
554
525
|
serialized = "{\n" + serialized + "\n}";
|
|
555
526
|
}
|
|
@@ -564,7 +535,7 @@ class NodeBuilder {
|
|
|
564
535
|
: Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-input-${k}`]))
|
|
565
536
|
};
|
|
566
537
|
return `
|
|
567
|
-
<div id='section_${source}'>${
|
|
538
|
+
<div id='section_${source}'>${getHandlebars().compile(script)(context)}
|
|
568
539
|
</div>
|
|
569
540
|
`;
|
|
570
541
|
}
|
|
@@ -575,53 +546,17 @@ class NodeBuilder {
|
|
|
575
546
|
return script;
|
|
576
547
|
}
|
|
577
548
|
buildType() {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
this.addIncludeEditSave(this._name + "_shaddowDefaults", `{ let node = this; ` +
|
|
582
|
-
shaddowDefaults
|
|
583
|
-
.map(([name, template]) => `
|
|
584
|
-
for(let i = 0; i < ${template.maxInstances}; i++){
|
|
585
|
-
node["_${name}_" + i] = (node.${name}[i] || {}).proxy || "";
|
|
586
|
-
}`)
|
|
587
|
-
.join("\n\n") +
|
|
588
|
-
`}`);
|
|
589
|
-
}
|
|
590
|
-
return js_beautify_1.default.html_beautify(`
|
|
549
|
+
this.applyShaddowDefaults();
|
|
550
|
+
const registerTypeBody = this.buildRegisterTypeBody();
|
|
551
|
+
return getBeautify().html_beautify(`
|
|
591
552
|
${this._onIncludeOnce.map(entry => this.serializeHTML(entry.source, entry.script)).join("")}
|
|
592
553
|
<script type="text/javascript">
|
|
593
|
-
RED.nodes.registerType('${this._name}',{
|
|
594
|
-
category: '${this._category}',
|
|
595
|
-
${(this._category !== "config" && this._icon) ? `icon: '${this._icon}',` : ""}
|
|
596
|
-
${(this._category !== "config" && this._color) ? `color: '${this._color}',` : ""}
|
|
597
|
-
${(this._category !== "config" && this._labelStyle) ? `labelStyle: '${this._labelStyle}',` : ""}
|
|
598
|
-
${(this._label) ? `label: ${this._label},` : ""}
|
|
599
|
-
${this._paletteLabel ? `paletteLabel: '${this._paletteLabel}',` : ""}
|
|
600
|
-
${(this._category !== "config") ? `inputs:${this._inputs ? "1" : "0"},` : ""}
|
|
601
|
-
${(this._category !== "config") ? `inputLabels:(i) => '${this._inputs}',` : ""}
|
|
602
|
-
${(this._category !== "config") ? `outputs:${this._outputs.length},` : ""}
|
|
603
|
-
${(this._category !== "config") ? `outputLabels:(i) => ${this.serializeProperty(this._outputs)}[i],` : ""}
|
|
604
|
-
defaults: {
|
|
605
|
-
${Object.entries(this._defaults).map(([key, value]) => this.serializeDefault(key, value)).join("\n")}
|
|
606
|
-
},
|
|
607
|
-
oneditprepare: function() {
|
|
608
|
-
${this._onIncludeEditPrepare.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
609
|
-
},
|
|
610
|
-
oneditsave: function() {
|
|
611
|
-
${this._onIncludeEditSave.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
612
|
-
},
|
|
613
|
-
oneditcancel: function() {
|
|
614
|
-
${this._onIncludeEditCancel.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
615
|
-
},
|
|
616
|
-
oneditdelete: function() {
|
|
617
|
-
${this._onIncludeEditDelete.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
618
|
-
},
|
|
619
|
-
});
|
|
554
|
+
RED.nodes.registerType('${this._name}', ${registerTypeBody});
|
|
620
555
|
</script>`, beautifyOptions);
|
|
621
556
|
}
|
|
622
557
|
;
|
|
623
558
|
buildHtml() {
|
|
624
|
-
return
|
|
559
|
+
return getBeautify().html_beautify(`
|
|
625
560
|
<script type="text/html" data-template-name='${this._name}'>
|
|
626
561
|
${this._onIncludeEditForm.map(entry => this.serializeFormEntry(entry.source, entry.script)).join("")}
|
|
627
562
|
</script>
|
|
@@ -651,12 +586,12 @@ let evalInContext = (context, js) => {
|
|
|
651
586
|
throw error;
|
|
652
587
|
}
|
|
653
588
|
};
|
|
654
|
-
let
|
|
589
|
+
let buildNodeBuilder = function (node) {
|
|
655
590
|
// get the node descriptor and create the builder.
|
|
656
591
|
let nodeDescriptor = node.getNodeDescriptor();
|
|
657
592
|
let nodeBuilder = new NodeBuilder(nodeDescriptor.id(), nodeDescriptor.group());
|
|
658
593
|
// load the html source file
|
|
659
|
-
let uiDom = new
|
|
594
|
+
let uiDom = new (getJSDOM())(fs_1.default.readFileSync(nodeDescriptor.sourceFile()));
|
|
660
595
|
// apply the onCompose section if available.
|
|
661
596
|
let onCompose = uiDom.window.document.querySelector("script[template-section='onCompose']")?.innerHTML;
|
|
662
597
|
if (onCompose) {
|
|
@@ -672,6 +607,11 @@ let buildNode = function (node) {
|
|
|
672
607
|
});
|
|
673
608
|
// add some of the dependencies here.
|
|
674
609
|
nodeDescriptor.templates().forEach(template => nodeBuilder.addTemplate(template));
|
|
610
|
+
return nodeBuilder;
|
|
611
|
+
};
|
|
612
|
+
exports.buildNodeBuilder = buildNodeBuilder;
|
|
613
|
+
let buildNode = function (node) {
|
|
614
|
+
let nodeBuilder = buildNodeBuilder(node);
|
|
675
615
|
return [nodeBuilder.buildType(), nodeBuilder.buildHtml(), nodeBuilder.buildDocumentation()].join("\n\n");
|
|
676
616
|
};
|
|
677
617
|
exports.buildNode = buildNode;
|
|
@@ -21,7 +21,9 @@ declare class NodeGenerator {
|
|
|
21
21
|
registerTemplate(template: ITemplateClass): NodeGenerator;
|
|
22
22
|
registerNode(node: INodeClass): NodeGenerator;
|
|
23
23
|
registerService(service: IServiceClass): NodeGenerator;
|
|
24
|
-
generate(nodesOutputFile: string, pluginsOutputFile: string): void;
|
|
24
|
+
generate(nodesOutputFile: string, pluginsOutputFile: string, packageName: string): void;
|
|
25
|
+
private generateNodesHtml;
|
|
26
|
+
private generatePluginsHtml;
|
|
25
27
|
private static generateHeader;
|
|
26
28
|
}
|
|
27
29
|
export { NodeGenerator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeGenerator.d.ts","sourceRoot":"","sources":["../../src/core/NodeGenerator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NodeGenerator.d.ts","sourceRoot":"","sources":["../../src/core/NodeGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+B,QAAQ,EAAE,cAAc,EAAe,iBAAiB,EAA4B,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAIvK,MAAM,WAAW,cAAc;IAC3B,QAAQ,QAAQ,CAAC;IACjB,qBAAqB,IAAI,kBAAkB,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IACvB,iBAAiB,IAAG,cAAc,CAAC;CACtC;AAED,MAAM,WAAW,aAAa;IAC1B,oBAAoB,IAAG,iBAAiB,CAAC;CAC5C;AAED,cAAM,aAAa;IAEf,OAAO,CAAC,MAAM,CAAC,WAAW,CAAM;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAKpB;IAEF,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,MAAM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