@bonsae/nrg 0.6.0 → 0.6.2
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 +5 -5
- package/package.json +14 -75
- package/{build/server → server}/index.cjs +1 -1
- package/{src/core/client → shims}/components.d.ts +2 -0
- package/{src/tsconfig → tsconfig}/client.json +3 -3
- package/types/client.d.ts +37 -0
- package/types/index.d.ts +211 -0
- package/types/server.d.ts +2293 -0
- package/types/vite.d.ts +12 -0
- package/{build/vite → vite}/index.js +95 -0
- package/build/vite/utils.js +0 -56
- package/src/core/client/app.vue +0 -185
- package/src/core/client/components/node-red-config-input.vue +0 -79
- package/src/core/client/components/node-red-editor-input.vue +0 -307
- package/src/core/client/components/node-red-input-label.vue +0 -53
- package/src/core/client/components/node-red-input.vue +0 -93
- package/src/core/client/components/node-red-json-schema-form.vue +0 -444
- package/src/core/client/components/node-red-select-input.vue +0 -108
- package/src/core/client/components/node-red-toggle.vue +0 -115
- package/src/core/client/components/node-red-typed-input.vue +0 -158
- package/src/core/client/index.ts +0 -500
- package/src/core/client/tsconfig.json +0 -18
- package/src/core/constants.ts +0 -18
- package/src/core/errors.ts +0 -9
- package/src/core/server/api/index.ts +0 -1
- package/src/core/server/api/serve-nrg-resources.ts +0 -54
- package/src/core/server/index.ts +0 -190
- package/src/core/server/nodes/config-node.ts +0 -67
- package/src/core/server/nodes/factories.ts +0 -133
- package/src/core/server/nodes/index.ts +0 -5
- package/src/core/server/nodes/io-node.ts +0 -179
- package/src/core/server/nodes/node.ts +0 -259
- package/src/core/server/nodes/types/config-node.ts +0 -28
- package/src/core/server/nodes/types/factories.ts +0 -115
- package/src/core/server/nodes/types/index.ts +0 -4
- package/src/core/server/nodes/types/io-node.ts +0 -40
- package/src/core/server/nodes/types/node.ts +0 -41
- package/src/core/server/nodes/utils.ts +0 -106
- package/src/core/server/schemas/base.ts +0 -66
- package/src/core/server/schemas/index.ts +0 -3
- package/src/core/server/schemas/type.ts +0 -95
- package/src/core/server/schemas/types/index.ts +0 -82
- package/src/core/server/tsconfig.json +0 -17
- package/src/core/server/types/index.ts +0 -220
- package/src/core/server/utils.ts +0 -56
- package/src/core/server/validator.ts +0 -36
- package/src/core/validator.ts +0 -222
- package/src/index.ts +0 -2
- package/src/types.ts +0 -189
- package/src/utils.ts +0 -20
- package/src/vite/async-utils.ts +0 -61
- package/src/vite/client/build.ts +0 -227
- package/src/vite/client/index.ts +0 -1
- package/src/vite/client/plugins/html-generator.ts +0 -75
- package/src/vite/client/plugins/index.ts +0 -5
- package/src/vite/client/plugins/locales-generator.ts +0 -126
- package/src/vite/client/plugins/minifier.ts +0 -23
- package/src/vite/client/plugins/node-definitions-inliner.ts +0 -275
- package/src/vite/client/plugins/static-copy.ts +0 -43
- package/src/vite/defaults.ts +0 -77
- package/src/vite/errors.ts +0 -37
- package/src/vite/index.ts +0 -2
- package/src/vite/logger.ts +0 -94
- package/src/vite/node-red-launcher.ts +0 -344
- package/src/vite/plugin.ts +0 -61
- package/src/vite/plugins/build.ts +0 -85
- package/src/vite/plugins/index.ts +0 -2
- package/src/vite/plugins/server.ts +0 -267
- package/src/vite/server/build.ts +0 -124
- package/src/vite/server/index.ts +0 -1
- package/src/vite/server/plugins/index.ts +0 -3
- package/src/vite/server/plugins/output-wrapper.ts +0 -109
- package/src/vite/server/plugins/package-json-generator.ts +0 -203
- package/src/vite/server/plugins/type-generator.ts +0 -285
- package/src/vite/types.ts +0 -174
- package/src/vite/utils.ts +0 -72
- /package/{build/index.js → index.js} +0 -0
- /package/{build/server → server}/resources/nrg-client.js +0 -0
- /package/{build/server → server}/resources/vue.esm-browser.js +0 -0
- /package/{build/server → server}/resources/vue.esm-browser.prod.js +0 -0
- /package/{src/core/client → shims}/globals.d.ts +0 -0
- /package/{src/core/client → shims}/shims-vue.d.ts +0 -0
- /package/{src/tsconfig → tsconfig}/base.json +0 -0
- /package/{src/tsconfig → tsconfig}/server.json +0 -0
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
2
|
-
import { createRequire } from "module";
|
|
3
|
-
import { pathToFileURL } from "url";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import mime from "mime-types";
|
|
7
|
-
|
|
8
|
-
const VIRTUAL_ID = "virtual:nrg/node-definitions";
|
|
9
|
-
const RESOLVED_ID = "\0" + VIRTUAL_ID;
|
|
10
|
-
|
|
11
|
-
const SKIP_DEFAULTS = new Set(["x", "y", "z", "g", "wires", "type", "id"]);
|
|
12
|
-
|
|
13
|
-
function getDefaultsFromSchema(
|
|
14
|
-
schema: any,
|
|
15
|
-
):
|
|
16
|
-
| Record<string, { type?: string; required: boolean; value: any }>
|
|
17
|
-
| undefined {
|
|
18
|
-
if (!schema?.properties) return undefined;
|
|
19
|
-
const result: Record<
|
|
20
|
-
string,
|
|
21
|
-
{ type?: string; required: boolean; value: any }
|
|
22
|
-
> = {};
|
|
23
|
-
for (const [key, prop] of Object.entries(schema.properties) as [
|
|
24
|
-
string,
|
|
25
|
-
any,
|
|
26
|
-
][]) {
|
|
27
|
-
if (SKIP_DEFAULTS.has(key)) continue;
|
|
28
|
-
result[key] = {
|
|
29
|
-
required: false,
|
|
30
|
-
value: prop.default ?? undefined,
|
|
31
|
-
type: prop["x-nrg-node-type"],
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getCredentialsFromSchema(
|
|
38
|
-
schema: any,
|
|
39
|
-
): Record<string, { type: string; required: boolean; value: any }> | undefined {
|
|
40
|
-
if (!schema?.properties) return undefined;
|
|
41
|
-
const result: Record<
|
|
42
|
-
string,
|
|
43
|
-
{ type: string; required: boolean; value: any }
|
|
44
|
-
> = {};
|
|
45
|
-
for (const [key, prop] of Object.entries(schema.properties) as [
|
|
46
|
-
string,
|
|
47
|
-
any,
|
|
48
|
-
][]) {
|
|
49
|
-
result[key] = {
|
|
50
|
-
required: false,
|
|
51
|
-
type: prop.format === "password" ? "password" : "text",
|
|
52
|
-
value: prop.default ?? undefined,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function resolveIcon(iconsDir: string, type: string): string | undefined {
|
|
59
|
-
if (!fs.existsSync(iconsDir)) return undefined;
|
|
60
|
-
return fs.readdirSync(iconsDir).find((f) => {
|
|
61
|
-
if (path.basename(f, path.extname(f)) !== type) return false;
|
|
62
|
-
const mimeType = mime.lookup(f);
|
|
63
|
-
return mimeType !== false && mimeType.startsWith("image/");
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function nodeDefinitionsInliner(
|
|
68
|
-
serverOutDir: string,
|
|
69
|
-
entryPath: string,
|
|
70
|
-
iconsDir?: string,
|
|
71
|
-
componentsDir?: string,
|
|
72
|
-
nodesDir?: string,
|
|
73
|
-
hasUserEntry: boolean = true,
|
|
74
|
-
): Plugin {
|
|
75
|
-
let _nodeTypes: string[] = [];
|
|
76
|
-
let _definitions: Record<string, any> = {};
|
|
77
|
-
// Cache directory for generated files (inside node_modules, gitignored)
|
|
78
|
-
const cacheDir = path.resolve("node_modules", ".nrg", "client");
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
name: "vite-plugin-node-red:client:node-definitions-inliner",
|
|
82
|
-
enforce: "pre",
|
|
83
|
-
|
|
84
|
-
// Load the server bundle in buildStart so _nodeTypes is populated
|
|
85
|
-
// before any load/transform hooks run.
|
|
86
|
-
async buildStart() {
|
|
87
|
-
_nodeTypes = [];
|
|
88
|
-
_definitions = {};
|
|
89
|
-
|
|
90
|
-
const esmEntryPath = path.resolve(serverOutDir, "index.mjs");
|
|
91
|
-
const cjsEntryPath = path.resolve(serverOutDir, "index.js");
|
|
92
|
-
|
|
93
|
-
let packageFn: any;
|
|
94
|
-
if (fs.existsSync(esmEntryPath)) {
|
|
95
|
-
const fileUrl = pathToFileURL(esmEntryPath).href + `?t=${Date.now()}`;
|
|
96
|
-
const mod = await import(fileUrl);
|
|
97
|
-
packageFn = mod?.default ?? mod;
|
|
98
|
-
} else if (fs.existsSync(cjsEntryPath)) {
|
|
99
|
-
const require = createRequire(import.meta.url);
|
|
100
|
-
delete require.cache[cjsEntryPath];
|
|
101
|
-
const rawMod = require(cjsEntryPath);
|
|
102
|
-
packageFn = rawMod?.default ?? rawMod;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const nodeClasses: any[] = packageFn?.nodes ?? [];
|
|
106
|
-
|
|
107
|
-
for (const NodeClass of nodeClasses) {
|
|
108
|
-
const type = NodeClass.type;
|
|
109
|
-
if (!type) continue;
|
|
110
|
-
_nodeTypes.push(type);
|
|
111
|
-
const configSchema = NodeClass.configSchema ?? null;
|
|
112
|
-
const credentialsSchema = NodeClass.credentialsSchema ?? null;
|
|
113
|
-
const inputSchema = NodeClass.inputSchema ?? null;
|
|
114
|
-
const outputsSchema = NodeClass.outputsSchema ?? null;
|
|
115
|
-
|
|
116
|
-
// Pre-compute defaults and credentials at build time
|
|
117
|
-
const defaults = getDefaultsFromSchema(configSchema);
|
|
118
|
-
if (defaults && inputSchema) {
|
|
119
|
-
defaults.validateInput = { required: false, value: false };
|
|
120
|
-
}
|
|
121
|
-
if (defaults && outputsSchema) {
|
|
122
|
-
defaults.validateOutput = { required: false, value: false };
|
|
123
|
-
}
|
|
124
|
-
const credentials = getCredentialsFromSchema(credentialsSchema);
|
|
125
|
-
|
|
126
|
-
_definitions[type] = {
|
|
127
|
-
type,
|
|
128
|
-
category: NodeClass.category,
|
|
129
|
-
configSchema,
|
|
130
|
-
credentialsSchema,
|
|
131
|
-
settingsSchema: NodeClass.settingsSchema ?? null,
|
|
132
|
-
defaults: defaults ?? undefined,
|
|
133
|
-
credentials: credentials ?? undefined,
|
|
134
|
-
align: NodeClass.align,
|
|
135
|
-
color: NodeClass.color,
|
|
136
|
-
icon: iconsDir ? resolveIcon(iconsDir, type) : undefined,
|
|
137
|
-
labelStyle: NodeClass.labelStyle,
|
|
138
|
-
paletteLabel: NodeClass.paletteLabel,
|
|
139
|
-
inputs: NodeClass.inputs,
|
|
140
|
-
outputs: NodeClass.outputs,
|
|
141
|
-
inputLabels: NodeClass.inputLabels,
|
|
142
|
-
outputLabels: NodeClass.outputLabels,
|
|
143
|
-
inputSchema,
|
|
144
|
-
outputsSchema,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// When no user entry, generate node definition files in cache
|
|
149
|
-
// so they appear as separate files in browser devtools.
|
|
150
|
-
if (!hasUserEntry) {
|
|
151
|
-
const nodesCache = path.resolve(cacheDir, "nodes");
|
|
152
|
-
if (fs.existsSync(nodesCache)) {
|
|
153
|
-
fs.rmSync(nodesCache, { recursive: true });
|
|
154
|
-
}
|
|
155
|
-
fs.mkdirSync(nodesCache, { recursive: true });
|
|
156
|
-
|
|
157
|
-
for (const type of _nodeTypes) {
|
|
158
|
-
// Skip if user has a physical node definition file
|
|
159
|
-
const userTsPath = nodesDir
|
|
160
|
-
? path.resolve(nodesDir, `${type}.ts`)
|
|
161
|
-
: null;
|
|
162
|
-
if (userTsPath && fs.existsSync(userTsPath)) continue;
|
|
163
|
-
|
|
164
|
-
const content = [
|
|
165
|
-
`// auto-generated by nrg`,
|
|
166
|
-
`import { defineNode } from "@bonsae/nrg/client";`,
|
|
167
|
-
``,
|
|
168
|
-
`export default defineNode({`,
|
|
169
|
-
` type: ${JSON.stringify(type)},`,
|
|
170
|
-
`});`,
|
|
171
|
-
``,
|
|
172
|
-
].join("\n");
|
|
173
|
-
fs.writeFileSync(path.resolve(nodesCache, `${type}.ts`), content);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Also write the entry file to cache
|
|
177
|
-
const entryContent = generateEntryCode("");
|
|
178
|
-
fs.mkdirSync(path.dirname(path.resolve(cacheDir, "index.ts")), {
|
|
179
|
-
recursive: true,
|
|
180
|
-
});
|
|
181
|
-
fs.writeFileSync(path.resolve(cacheDir, "index.ts"), entryContent);
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
resolveId(id) {
|
|
186
|
-
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
load(id) {
|
|
190
|
-
if (id === RESOLVED_ID)
|
|
191
|
-
return `export default ${JSON.stringify(_definitions)};`;
|
|
192
|
-
|
|
193
|
-
// For auto-generated entries, return the generated code directly
|
|
194
|
-
// so the browser devtools shows the actual source instead of the
|
|
195
|
-
// placeholder comment on disk.
|
|
196
|
-
if (!hasUserEntry && id === entryPath) {
|
|
197
|
-
return generateEntryCode("");
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
transform(code, id) {
|
|
202
|
-
if (id !== entryPath) return;
|
|
203
|
-
// When the user provides their own entry, prepend the generated
|
|
204
|
-
// code to their source. For auto-generated entries, the load hook
|
|
205
|
-
// already returned the full code.
|
|
206
|
-
if (!hasUserEntry) return;
|
|
207
|
-
|
|
208
|
-
return { code: generateEntryCode(code), map: null };
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
function generateEntryCode(userCode: string): string {
|
|
213
|
-
const nrgImports = new Set<string>(["__setSchemas"]);
|
|
214
|
-
const lines = [`import __nrgSchemas from "${VIRTUAL_ID}";`];
|
|
215
|
-
const postLines: string[] = [`__setSchemas(__nrgSchemas);`];
|
|
216
|
-
|
|
217
|
-
// Auto-detect form components by convention: {componentsDir}/{type}.vue
|
|
218
|
-
if (componentsDir && fs.existsSync(componentsDir)) {
|
|
219
|
-
const formImports: string[] = [];
|
|
220
|
-
const formEntries: string[] = [];
|
|
221
|
-
|
|
222
|
-
for (const type of _nodeTypes) {
|
|
223
|
-
const componentPath = path.resolve(componentsDir, `${type}.vue`);
|
|
224
|
-
if (fs.existsSync(componentPath)) {
|
|
225
|
-
const varName = `__nrgForm_${type.replace(/-/g, "_")}`;
|
|
226
|
-
formImports.push(
|
|
227
|
-
`import ${varName} from ${JSON.stringify(componentPath)};`,
|
|
228
|
-
);
|
|
229
|
-
formEntries.push(`${JSON.stringify(type)}: ${varName}`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (formImports.length > 0) {
|
|
234
|
-
lines.push(...formImports);
|
|
235
|
-
nrgImports.add("__setForms");
|
|
236
|
-
postLines.push(`__setForms({ ${formEntries.join(", ")} });`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Auto-register only when no user entry was provided.
|
|
241
|
-
if (!hasUserEntry) {
|
|
242
|
-
const nodesCache = path.resolve(cacheDir, "nodes");
|
|
243
|
-
const defVarNames: string[] = [];
|
|
244
|
-
|
|
245
|
-
for (const type of _nodeTypes) {
|
|
246
|
-
const varName = `__nrgNodeDef_${type.replace(/-/g, "_")}`;
|
|
247
|
-
// Use physical file if user has one, otherwise use cached generated file
|
|
248
|
-
const userTsPath = nodesDir
|
|
249
|
-
? path.resolve(nodesDir, `${type}.ts`)
|
|
250
|
-
: null;
|
|
251
|
-
const tsPath =
|
|
252
|
-
userTsPath && fs.existsSync(userTsPath)
|
|
253
|
-
? userTsPath
|
|
254
|
-
: path.resolve(nodesCache, `${type}.ts`);
|
|
255
|
-
lines.push(`import ${varName} from ${JSON.stringify(tsPath)};`);
|
|
256
|
-
defVarNames.push(varName);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (defVarNames.length > 0) {
|
|
260
|
-
nrgImports.add("registerTypes");
|
|
261
|
-
postLines.push(`registerTypes([${defVarNames.join(", ")}]);`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Build the @bonsae/nrg/client import line
|
|
266
|
-
const importLine = `import { ${[...nrgImports].join(", ")} } from "@bonsae/nrg/client";`;
|
|
267
|
-
lines.splice(1, 0, importLine);
|
|
268
|
-
|
|
269
|
-
lines.push(...postLines);
|
|
270
|
-
lines.push("");
|
|
271
|
-
return lines.join("\n") + userCode;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export { nodeDefinitionsInliner };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
function staticCopy(options: {
|
|
6
|
-
targets: { src: string; dest: string }[];
|
|
7
|
-
}): Plugin {
|
|
8
|
-
const { targets } = options;
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
name: "vite-plugin-node-red:client:static-copy",
|
|
12
|
-
apply: "build",
|
|
13
|
-
enforce: "post",
|
|
14
|
-
|
|
15
|
-
closeBundle() {
|
|
16
|
-
for (const { src, dest } of targets) {
|
|
17
|
-
if (!fs.existsSync(src)) continue;
|
|
18
|
-
|
|
19
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
20
|
-
|
|
21
|
-
const stat = fs.statSync(src);
|
|
22
|
-
if (stat.isDirectory()) {
|
|
23
|
-
const files = fs.readdirSync(src);
|
|
24
|
-
for (const file of files) {
|
|
25
|
-
const srcFile = path.join(src, file);
|
|
26
|
-
const destFile = path.join(dest, file);
|
|
27
|
-
const fileStat = fs.statSync(srcFile);
|
|
28
|
-
|
|
29
|
-
if (fileStat.isDirectory()) {
|
|
30
|
-
fs.cpSync(srcFile, destFile, { recursive: true });
|
|
31
|
-
} else {
|
|
32
|
-
fs.copyFileSync(srcFile, destFile);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
fs.copyFileSync(src, dest);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { staticCopy };
|
package/src/vite/defaults.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CopyTarget,
|
|
3
|
-
ClientBuildOptions,
|
|
4
|
-
NodeRedLauncherOptions,
|
|
5
|
-
ServerBuildOptions,
|
|
6
|
-
} from "./types";
|
|
7
|
-
|
|
8
|
-
const DEFAULT_OUTPUT_DIR = "./dist";
|
|
9
|
-
|
|
10
|
-
const DEFAULT_CLIENT_BUILD_OPTIONS: ClientBuildOptions = {
|
|
11
|
-
srcDir: "./src/client",
|
|
12
|
-
entry: "index.ts",
|
|
13
|
-
nodesSubdir: "nodes",
|
|
14
|
-
name: "NodeRedNodes",
|
|
15
|
-
format: "es",
|
|
16
|
-
licensePath: "./LICENSE",
|
|
17
|
-
external: ["jquery", "node-red", "vue", "@bonsae/nrg/client"],
|
|
18
|
-
globals: {
|
|
19
|
-
jquery: "$",
|
|
20
|
-
"node-red": "RED",
|
|
21
|
-
vue: "Vue",
|
|
22
|
-
},
|
|
23
|
-
locales: {
|
|
24
|
-
docsDir: "./src/locales/docs",
|
|
25
|
-
labelsDir: "./src/locales/labels",
|
|
26
|
-
languages: [
|
|
27
|
-
"en-US",
|
|
28
|
-
"de",
|
|
29
|
-
"es-ES",
|
|
30
|
-
"fr",
|
|
31
|
-
"ko",
|
|
32
|
-
"pt-BR",
|
|
33
|
-
"ru",
|
|
34
|
-
"ja",
|
|
35
|
-
"zh-CN",
|
|
36
|
-
"zh-TW",
|
|
37
|
-
],
|
|
38
|
-
},
|
|
39
|
-
staticDirs: {
|
|
40
|
-
icons: "./src/icons",
|
|
41
|
-
public: "./src/client/public",
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const DEFAULT_SERVER_BUILD_OPTIONS: ServerBuildOptions = {
|
|
46
|
-
srcDir: "./src/server",
|
|
47
|
-
entry: "index.ts",
|
|
48
|
-
format: "esm",
|
|
49
|
-
external: [],
|
|
50
|
-
bundled: [],
|
|
51
|
-
types: true,
|
|
52
|
-
nodeTarget: "node22",
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const DEFAULT_NODE_RED_LAUNCHER_OPTIONS: NodeRedLauncherOptions = {
|
|
56
|
-
runtime: {
|
|
57
|
-
port: 1880,
|
|
58
|
-
settingsFilepath: "./node-red.settings.ts",
|
|
59
|
-
version: "latest",
|
|
60
|
-
},
|
|
61
|
-
restartDelay: 1000,
|
|
62
|
-
args: [],
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const DEFAULT_EXTRA_FILES_COPY_TARGETS: CopyTarget[] = [
|
|
66
|
-
{ src: "./LICENSE", dest: "LICENSE" },
|
|
67
|
-
{ src: "./README.md", dest: "README.md" },
|
|
68
|
-
{ src: "./src/examples", dest: "examples" },
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
export {
|
|
72
|
-
DEFAULT_CLIENT_BUILD_OPTIONS,
|
|
73
|
-
DEFAULT_SERVER_BUILD_OPTIONS,
|
|
74
|
-
DEFAULT_NODE_RED_LAUNCHER_OPTIONS,
|
|
75
|
-
DEFAULT_EXTRA_FILES_COPY_TARGETS,
|
|
76
|
-
DEFAULT_OUTPUT_DIR,
|
|
77
|
-
};
|
package/src/vite/errors.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
class PluginError extends Error {
|
|
2
|
-
constructor(
|
|
3
|
-
message: string,
|
|
4
|
-
public readonly code: string,
|
|
5
|
-
public readonly cause?: Error,
|
|
6
|
-
) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "PluginError";
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class NodeRedStartError extends PluginError {
|
|
13
|
-
constructor(cause?: Error) {
|
|
14
|
-
super("Failed to start Node-RED", "NODE_RED_START_FAILED", cause);
|
|
15
|
-
this.name = "NodeRedStartError";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class BuildError extends PluginError {
|
|
20
|
-
constructor(phase: "server" | "client", cause?: Error) {
|
|
21
|
-
super(
|
|
22
|
-
`Failed to build ${phase}`,
|
|
23
|
-
`BUILD_${phase.toUpperCase()}_FAILED`,
|
|
24
|
-
cause,
|
|
25
|
-
);
|
|
26
|
-
this.name = "BuildError";
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
class ConfigError extends PluginError {
|
|
31
|
-
constructor(message: string) {
|
|
32
|
-
super(message, "CONFIG_INVALID");
|
|
33
|
-
this.name = "ConfigError";
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { PluginError, NodeRedStartError, BuildError, ConfigError };
|
package/src/vite/index.ts
DELETED
package/src/vite/logger.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import * as clackLogger from "@clack/prompts";
|
|
2
|
-
import type { LoggerOptions } from "./types";
|
|
3
|
-
|
|
4
|
-
const color = {
|
|
5
|
-
dim: (s: string) => `\x1b[2m${s}\x1b[0m`,
|
|
6
|
-
cyan: (s: string) => `\x1b[36m${s}\x1b[0m`,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export class Logger {
|
|
10
|
-
private readonly name: string;
|
|
11
|
-
private readonly prefix?: string;
|
|
12
|
-
private readonly spinner = clackLogger.spinner();
|
|
13
|
-
|
|
14
|
-
constructor(options: LoggerOptions) {
|
|
15
|
-
this.name = options.name;
|
|
16
|
-
this.prefix = options.prefix;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private format(message: string): string {
|
|
20
|
-
return this.prefix ? `[${this.prefix}] ${message}` : message;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
intro(message?: string): void {
|
|
24
|
-
clackLogger.intro(message ?? this.name);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
outro(message: string): void {
|
|
28
|
-
clackLogger.outro(this.format(message));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
step(message: string): void {
|
|
32
|
-
clackLogger.log.step(this.format(message));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
success(message: string): void {
|
|
36
|
-
clackLogger.log.success(this.format(message));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
warn(message: string): void {
|
|
40
|
-
clackLogger.log.warn(this.format(message));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
error(message: string, cause?: Error): void {
|
|
44
|
-
clackLogger.log.error(this.format(message));
|
|
45
|
-
if (cause) {
|
|
46
|
-
console.error(cause);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
info(message: string): void {
|
|
51
|
-
clackLogger.log.info(this.format(message));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
message(message: string): void {
|
|
55
|
-
clackLogger.log.message(this.format(message));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
raw(message: string): void {
|
|
59
|
-
const prefix = this.prefix ? color.dim(`[${this.prefix}]`) : "";
|
|
60
|
-
console.log(`│ ${prefix} ${message}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
startGroup(title?: string): void {
|
|
64
|
-
if (title) {
|
|
65
|
-
console.log(`│`);
|
|
66
|
-
console.log(`├─ ${color.cyan(title)}`);
|
|
67
|
-
}
|
|
68
|
-
console.log(`│`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
endGroup(message?: string): void {
|
|
72
|
-
console.log(`│`);
|
|
73
|
-
console.log(`└─ ${message ?? "Done"}`);
|
|
74
|
-
console.log();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
startSpinner(message: string): void {
|
|
78
|
-
this.spinner.start(this.format(message));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
stopSpinner(message: string): void {
|
|
82
|
-
this.spinner.stop(this.format(message));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
child(prefix: string): Logger {
|
|
86
|
-
const newPrefix = this.prefix ? `${this.prefix}:${prefix}` : prefix;
|
|
87
|
-
return new Logger({ name: this.name, prefix: newPrefix });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// NOTE: global logger is still used by other vite messages
|
|
92
|
-
const logger = new Logger({ name: "vite-plugin-node-red" });
|
|
93
|
-
|
|
94
|
-
export { createLogger, logger };
|