@keload/node-red-dxp 1.5.0 → 1.7.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.
@@ -0,0 +1,705 @@
1
+ import fs, { readFileSync } from 'node:fs';
2
+ import path2, { sep } from 'node:path';
3
+ import { cosmiconfigSync } from 'cosmiconfig';
4
+ import { globSync } from 'fast-glob';
5
+ import { dash, pascal } from 'radash';
6
+ import fsPromise from 'node:fs/promises';
7
+ import esbuild from 'esbuild';
8
+ import { minify } from 'html-minifier-terser';
9
+ import purgeCss from '@fullhuman/postcss-purgecss';
10
+ import autoprefixer from 'autoprefixer';
11
+ import cssnano from 'cssnano';
12
+ import postcss from 'postcss';
13
+ import * as sass from 'sass';
14
+ import tailwindcss from 'tailwindcss';
15
+
16
+ var __defProp = Object.defineProperty;
17
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
18
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
19
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
20
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
21
+ var __spreadValues = (a, b) => {
22
+ for (var prop in b || (b = {}))
23
+ if (__hasOwnProp.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ if (__getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(b)) {
27
+ if (__propIsEnum.call(b, prop))
28
+ __defNormalProp(a, prop, b[prop]);
29
+ }
30
+ return a;
31
+ };
32
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
33
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
34
+ }) : x)(function(x) {
35
+ if (typeof require !== "undefined") return require.apply(this, arguments);
36
+ throw Error('Dynamic require of "' + x + '" is not supported');
37
+ });
38
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
39
+ var __async = (__this, __arguments, generator) => {
40
+ return new Promise((resolve, reject) => {
41
+ var fulfilled = (value) => {
42
+ try {
43
+ step(generator.next(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var rejected = (value) => {
49
+ try {
50
+ step(generator.throw(value));
51
+ } catch (e) {
52
+ reject(e);
53
+ }
54
+ };
55
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
56
+ step((generator = generator.apply(__this, __arguments)).next());
57
+ });
58
+ };
59
+
60
+ // node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/getType.js
61
+ function getType(payload) {
62
+ return Object.prototype.toString.call(payload).slice(8, -1);
63
+ }
64
+
65
+ // node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/isPlainObject.js
66
+ function isPlainObject(payload) {
67
+ if (getType(payload) !== "Object")
68
+ return false;
69
+ const prototype = Object.getPrototypeOf(payload);
70
+ return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
71
+ }
72
+
73
+ // node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/isSymbol.js
74
+ function isSymbol(payload) {
75
+ return getType(payload) === "Symbol";
76
+ }
77
+
78
+ // node_modules/.pnpm/merge-anything@6.0.2/node_modules/merge-anything/dist/merge.js
79
+ function assignProp(carry, key, newVal, originalObject) {
80
+ const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
81
+ if (propType === "enumerable")
82
+ carry[key] = newVal;
83
+ if (propType === "nonenumerable") {
84
+ Object.defineProperty(carry, key, {
85
+ value: newVal,
86
+ enumerable: false,
87
+ writable: true,
88
+ configurable: true
89
+ });
90
+ }
91
+ }
92
+ function mergeRecursively(origin, newComer, compareFn) {
93
+ if (!isPlainObject(newComer))
94
+ return newComer;
95
+ let newObject = {};
96
+ if (isPlainObject(origin)) {
97
+ const props2 = Object.getOwnPropertyNames(origin);
98
+ const symbols2 = Object.getOwnPropertySymbols(origin);
99
+ newObject = [...props2, ...symbols2].reduce((carry, key) => {
100
+ const targetVal = origin[key];
101
+ if (!isSymbol(key) && !Object.getOwnPropertyNames(newComer).includes(key) || isSymbol(key) && !Object.getOwnPropertySymbols(newComer).includes(key)) {
102
+ assignProp(carry, key, targetVal, origin);
103
+ }
104
+ return carry;
105
+ }, {});
106
+ }
107
+ const props = Object.getOwnPropertyNames(newComer);
108
+ const symbols = Object.getOwnPropertySymbols(newComer);
109
+ const result = [...props, ...symbols].reduce((carry, key) => {
110
+ let newVal = newComer[key];
111
+ const targetVal = isPlainObject(origin) ? origin[key] : void 0;
112
+ if (targetVal !== void 0 && isPlainObject(newVal)) {
113
+ newVal = mergeRecursively(targetVal, newVal);
114
+ }
115
+ const propToAssign = newVal;
116
+ assignProp(carry, key, propToAssign, newComer);
117
+ return carry;
118
+ }, newObject);
119
+ return result;
120
+ }
121
+ function merge(object, ...otherObjects) {
122
+ return otherObjects.reduce((result, newComer) => {
123
+ return mergeRecursively(result, newComer);
124
+ }, object);
125
+ }
126
+
127
+ // src/default-config.ts
128
+ var defaultConfig = {
129
+ libCacheDir: ".node-red-dx",
130
+ srcDir: "src",
131
+ nodesDirName: "nodes",
132
+ nodes: {
133
+ controllerName: "controller",
134
+ localesDirName: "locales",
135
+ editor: {
136
+ dirName: "editor",
137
+ htmlName: "index",
138
+ tsName: "index"
139
+ }
140
+ },
141
+ builder: {
142
+ outputDir: "dist"
143
+ },
144
+ watcher: {
145
+ nodeRed: {
146
+ enabled: true,
147
+ path: "~/.node-red",
148
+ url: "http://localhost:1880"
149
+ }
150
+ }
151
+ };
152
+
153
+ // src/current-context.ts
154
+ var CONFIG_FILE_NAME = "node-red-dx";
155
+ var cleanPkgName = (pkgName) => pkgName.replace("@", "").replace("/", "-");
156
+ function getConfig() {
157
+ const explorerSync = cosmiconfigSync(CONFIG_FILE_NAME);
158
+ try {
159
+ const result = explorerSync.search();
160
+ return merge(defaultConfig, result ? result.config : {});
161
+ } catch (error) {
162
+ console.error("Error while loading configuration", error);
163
+ throw error;
164
+ }
165
+ }
166
+ var currentConfig = getConfig();
167
+ var currentDir = process.cwd();
168
+ var jsonPackage = JSON.parse(readFileSync(`${currentDir}/package.json`, "utf-8"));
169
+ var pathSrcDir = `${currentDir}/${currentConfig.srcDir}`;
170
+ var additionalResourcesDir = `${currentDir}/resources`;
171
+ var pathSrcNodesDir = `${pathSrcDir}/${currentConfig.nodesDirName}`;
172
+ var pathLibCacheDir = `${currentDir}/${currentConfig.libCacheDir}`;
173
+ var currentPackagedDistPath = `${path2.resolve(__dirname, "..")}`;
174
+ var packageNameSlug = cleanPkgName(jsonPackage.name);
175
+ function listNodeFolders(rawNodes = []) {
176
+ return rawNodes.map((entry) => {
177
+ const fullPath = entry.path;
178
+ const fullEditorPath = `${fullPath}/${currentConfig.nodes.editor.dirName}`;
179
+ const relativePath = fullPath.replace(currentDir, "").slice(1);
180
+ const relativeEditorPath = `${relativePath}/${currentConfig.nodes.editor.dirName}`;
181
+ const scssFiles = globSync(`${fullEditorPath}/**/*.scss`);
182
+ const mdxFiles = globSync(`${fullPath}/doc.mdx`);
183
+ const mdFiles = globSync(`${fullPath}/doc.md`);
184
+ const dashName = dash(entry.name);
185
+ return {
186
+ fullEditorPath,
187
+ fullPath,
188
+ name: entry.name,
189
+ pascalName: pascal(entry.name),
190
+ dashName,
191
+ relativeEditorPath,
192
+ relativePath,
193
+ resolvedLocalesPaths: globSync(`${fullPath}/${currentConfig.nodes.localesDirName}/*.json`),
194
+ nodeIdentifier: `${packageNameSlug}-${dashName}`,
195
+ fullControllerPath: `${fullPath}/controller.ts`,
196
+ editor: {
197
+ tsPath: `${fullEditorPath}/${currentConfig.nodes.editor.tsName}.ts`,
198
+ htmlPath: `${fullEditorPath}/${currentConfig.nodes.editor.htmlName}.html`,
199
+ scssFiles
200
+ },
201
+ doc: {
202
+ mdxFiles,
203
+ mdFiles
204
+ }
205
+ };
206
+ });
207
+ }
208
+ function getCurrentContext() {
209
+ const resolvedNodesPaths = globSync(`${pathSrcNodesDir}/**/*`, { onlyDirectories: true, deep: 1, objectMode: true });
210
+ const listNodesFull = listNodeFolders(resolvedNodesPaths);
211
+ const listNodesFullNames = listNodesFull.map((node) => node.name);
212
+ return {
213
+ currentDir,
214
+ pathSrcDir,
215
+ pathSrcNodesDir,
216
+ additionalResourcesDir,
217
+ pathDist: `${currentDir}/${currentConfig.builder.outputDir}`,
218
+ currentPackagedDistPath,
219
+ cacheDirFiles: {
220
+ controllerIndex: `${pathLibCacheDir}/controller-index.ts`,
221
+ editorIndex: `${pathLibCacheDir}/editor-index.ts`
222
+ },
223
+ pathLibCacheDir,
224
+ packageName: jsonPackage.name,
225
+ packageNameSlug,
226
+ config: currentConfig,
227
+ resolvedSrcPathsScss: globSync(`${pathSrcDir}/**/*.scss`, { ignore: [`${pathSrcNodesDir}/**/*.scss`] }),
228
+ resolvedNodesPaths: resolvedNodesPaths.map((entry) => entry.path),
229
+ resolvedSrcLocalesPaths: globSync(`${pathSrcDir}/locales/*.json`),
230
+ listNodesFull,
231
+ listNodesFullNames
232
+ };
233
+ }
234
+ var currentContext = getCurrentContext();
235
+ var distributionPackagePath = `${path2.resolve(__dirname, "..")}`;
236
+ function createFolderIfNotExists(folderPath) {
237
+ if (!fs.existsSync(folderPath)) {
238
+ fs.mkdirSync(folderPath, { recursive: true });
239
+ }
240
+ }
241
+ function writeFile(path3, content) {
242
+ return __async(this, null, function* () {
243
+ try {
244
+ yield fsPromise.writeFile(path3, content);
245
+ } catch (error) {
246
+ console.error("Error writing controller index:", error);
247
+ }
248
+ });
249
+ }
250
+ function cleanPaths(paths) {
251
+ return __async(this, null, function* () {
252
+ for (const dirPath of paths) {
253
+ try {
254
+ const resolvedPath = path2.resolve(dirPath);
255
+ const stats = yield fsPromise.stat(resolvedPath).catch(() => null);
256
+ if (stats == null ? void 0 : stats.isDirectory()) {
257
+ yield fsPromise.rm(resolvedPath, { recursive: true, force: true });
258
+ }
259
+ } catch (error) {
260
+ console.error(`Error cleaning path (${dirPath}): ${error}`);
261
+ }
262
+ }
263
+ });
264
+ }
265
+ var addCredentialsExportPlugin = {
266
+ name: "add-credentials-export",
267
+ setup(build) {
268
+ build.onLoad({ filter: /controller\.ts$/ }, (args) => __async(this, null, function* () {
269
+ const source = yield fsPromise.readFile(args.path, "utf8");
270
+ const hasCredentialsExport = /export\s+const\s+credentials\s*=/.test(source);
271
+ if (!hasCredentialsExport) {
272
+ return {
273
+ contents: `${source}
274
+ export const credentials = {};`,
275
+ loader: "ts"
276
+ };
277
+ }
278
+ return { contents: source, loader: "ts" };
279
+ }));
280
+ }
281
+ };
282
+
283
+ // src/builder/controller/BuilderController.class.ts
284
+ var BuilderController = class {
285
+ constructor(params) {
286
+ __publicField(this, "params");
287
+ this.params = __spreadValues({ minify: false }, params);
288
+ }
289
+ getControllerIndexContent() {
290
+ return __async(this, null, function* () {
291
+ return `
292
+ import type { NodeAPI } from 'node-red';
293
+ ${currentContext.listNodesFull.map((node) => `import ${node.pascalName}, {credentials as cred${node.pascalName}} from '${node.fullControllerPath}';`).join("\n")}
294
+
295
+
296
+ export default async (RED: NodeAPI): Promise<void> => {
297
+ global.RED = RED;
298
+
299
+ ${currentContext.listNodesFull.map(
300
+ (node) => `// @ts-ignore
301
+ global.RED.nodes.registerType('${node.name}', ${node.pascalName}, {
302
+ credentials: cred${node.pascalName}
303
+ });`
304
+ ).join("\n")}
305
+ };
306
+ `.trim();
307
+ });
308
+ }
309
+ buildScript() {
310
+ return esbuild.build({
311
+ entryPoints: [currentContext.cacheDirFiles.controllerIndex],
312
+ outfile: `${currentContext.pathDist}/index.js`,
313
+ bundle: true,
314
+ minify: this.params.minify,
315
+ minifyWhitespace: this.params.minify,
316
+ minifyIdentifiers: this.params.minify,
317
+ minifySyntax: this.params.minify,
318
+ platform: "node",
319
+ format: "cjs",
320
+ target: "es2018",
321
+ loader: { ".ts": "ts" },
322
+ packages: "external",
323
+ plugins: [addCredentialsExportPlugin]
324
+ });
325
+ }
326
+ getControllerTask() {
327
+ return __async(this, null, function* () {
328
+ return this.getControllerIndexContent().then((content) => {
329
+ writeFile(`${currentContext.cacheDirFiles.controllerIndex}`, content).then(() => {
330
+ this.buildScript();
331
+ });
332
+ });
333
+ });
334
+ }
335
+ };
336
+ var BuildDoc = class {
337
+ // TODO need to refactor
338
+ getAllDocContent() {
339
+ const result = [];
340
+ for (const node of currentContext.listNodesFull) {
341
+ const fileMd = node.doc.mdFiles[0];
342
+ if (fileMd) {
343
+ const htmlMd = fs.readFileSync(node.doc.mdFiles[0], "utf-8");
344
+ const inner = `
345
+ <script type="text/markdown" data-help-name="${node.name}">
346
+ ${htmlMd}
347
+ </script>
348
+ `;
349
+ result.push(inner);
350
+ }
351
+ }
352
+ return result.length ? result.join("\n") : "";
353
+ }
354
+ };
355
+ function cleanSpaces(str) {
356
+ return str.trim().replace(/\n\s+/g, "");
357
+ }
358
+
359
+ // src/builder/editor/i18n.ts
360
+ function updateI18nAttributes(nodeName = "", htmlContent = "") {
361
+ if (!nodeName || !htmlContent) {
362
+ return htmlContent;
363
+ }
364
+ return htmlContent.replace(/data-i18n="([^"]+)"/g, (match, i18nValue) => {
365
+ const updatedValue = i18nValue.replace(/(\[.*?\])?(node-red:[^;]+|[^;]+)/g, (_, prefix, key) => {
366
+ let res = key;
367
+ if (!key.startsWith("node-red:")) {
368
+ res = `${nodeName}.${key}`;
369
+ }
370
+ return (prefix || "") + res;
371
+ });
372
+ return `data-i18n="${updatedValue}"`;
373
+ });
374
+ }
375
+
376
+ // src/builder/editor/html.ts
377
+ function minifyHtml(content) {
378
+ return __async(this, null, function* () {
379
+ return minify(content, {
380
+ collapseWhitespace: true,
381
+ removeComments: true,
382
+ removeRedundantAttributes: false,
383
+ useShortDoctype: true,
384
+ removeEmptyAttributes: false,
385
+ minifyCSS: false,
386
+ minifyJS: false
387
+ });
388
+ });
389
+ }
390
+ function wrapHtml(nodeName, html) {
391
+ return `
392
+ <script type="text/html" data-template-name="${nodeName}">
393
+ ${html}
394
+ </script>
395
+ `;
396
+ }
397
+ function processNodeHtml(node, packageNameSlug2, minify2 = false) {
398
+ return __async(this, null, function* () {
399
+ const htmlContent = readFileSync(node.editor.htmlPath, "utf8");
400
+ const htmlContentWithAdditionalDiv = `
401
+ <div class="${packageNameSlug2}">
402
+ <div class="${node.nodeIdentifier}">${htmlContent}</div>
403
+ </div>
404
+ `;
405
+ let html = minify2 ? yield minifyHtml(htmlContentWithAdditionalDiv) : htmlContentWithAdditionalDiv;
406
+ html = updateI18nAttributes(node.name, html);
407
+ const wrappedHtml = wrapHtml(node.name, html);
408
+ return {
409
+ nodeName: node.name,
410
+ nodeIdentifier: node.nodeIdentifier,
411
+ html,
412
+ wrappedHtml
413
+ };
414
+ });
415
+ }
416
+ function getNodesHtml(params) {
417
+ return __async(this, null, function* () {
418
+ const { nodes, minify: minify2 = false } = params;
419
+ const res = yield Promise.all(nodes.map((node) => processNodeHtml(node, params.packageNameSlug, minify2)));
420
+ const allHtml = res.map((node) => node.html).join("").trim();
421
+ return {
422
+ html: allHtml,
423
+ allWrappedHtml: res.map((node) => minify2 ? cleanSpaces(node.wrappedHtml) : node.wrappedHtml).join("").trim()
424
+ };
425
+ });
426
+ }
427
+ function processCSS(cssString, htmlString) {
428
+ return __async(this, null, function* () {
429
+ const result = yield postcss([
430
+ purgeCss({
431
+ content: [{ raw: htmlString, extension: "html" }]
432
+ // Analyse directe du HTML
433
+ }),
434
+ autoprefixer,
435
+ cssnano({ preset: "default" })
436
+ ]).process(cssString, { from: void 0 });
437
+ return result.css;
438
+ });
439
+ }
440
+ function compileScss(filePath) {
441
+ const result = sass.compile(filePath, { style: "expanded" });
442
+ return result.css;
443
+ }
444
+ function buildStyles(files) {
445
+ const styles = {};
446
+ for (let i = 0; i < files.length; i++) {
447
+ const filePath = files[i];
448
+ styles[filePath] = compileScss(filePath);
449
+ }
450
+ return styles;
451
+ }
452
+ function getNodesStyles(nodes) {
453
+ const hasStyles = nodes.some((node) => node.editor.scssFiles.length);
454
+ if (!hasStyles) {
455
+ return [];
456
+ }
457
+ return nodes.filter((node) => node.editor.scssFiles.length).map((node) => {
458
+ const nodeStyles = buildStyles(node.editor.scssFiles);
459
+ const mergedCompiledStyles = Object.values(nodeStyles).join("");
460
+ return {
461
+ name: node.name,
462
+ mergedCompiledStyles,
463
+ scssFinal: `
464
+ #${node.nodeIdentifier}{
465
+ ${mergedCompiledStyles}
466
+ }`
467
+ };
468
+ });
469
+ }
470
+ function generateCSSFromHTMLWithTailwind(_0) {
471
+ return __async(this, arguments, function* (htmlString, tailwindConfig = {}) {
472
+ const defaultConfig2 = {
473
+ content: [{ raw: htmlString }],
474
+ theme: {}
475
+ };
476
+ const finalConfig = __spreadValues(__spreadValues({}, defaultConfig2), tailwindConfig);
477
+ const tailwindScssFilePath = globSync(
478
+ `${distributionPackagePath}/${currentContext.config.nodes.editor.dirName}/assets/tailwind.scss`
479
+ )[0];
480
+ const scssString = tailwindScssFilePath.length ? fs.readFileSync(tailwindScssFilePath, "utf8") : "";
481
+ const result = yield postcss([tailwindcss(finalConfig), __require("autoprefixer")]).process(scssString, {
482
+ from: void 0
483
+ });
484
+ return result.css;
485
+ });
486
+ }
487
+ function getSrcStyles() {
488
+ const srcStyles = currentContext.resolvedSrcPathsScss;
489
+ const srcStylesCompiled = buildStyles([...srcStyles]);
490
+ return Object.values(srcStylesCompiled).join("");
491
+ }
492
+ function getAllCompiledStyles(params) {
493
+ return __async(this, null, function* () {
494
+ const { rawHtml, minify: minify2 = false, nodes } = params || {};
495
+ const srcStyles = getSrcStyles();
496
+ const nodesStyles = getNodesStyles(nodes);
497
+ const twCss = yield generateCSSFromHTMLWithTailwind(rawHtml);
498
+ const getSrcWrapper = (content) => `.${currentContext.packageNameSlug}{${content}}`;
499
+ const allNodesStyles = nodesStyles.map((node) => node.scssFinal).join("\n");
500
+ const result = getSrcWrapper(`${twCss}${srcStyles}${allNodesStyles}`);
501
+ return minify2 ? processCSS(result, rawHtml) : result;
502
+ });
503
+ }
504
+
505
+ // src/builder/editor/BuilderEditor.class.ts
506
+ var BuilderEditor = class {
507
+ constructor(params) {
508
+ __publicField(this, "params");
509
+ this.params = __spreadValues({ minify: false }, params);
510
+ }
511
+ getEditorIndexContent() {
512
+ return __async(this, null, function* () {
513
+ return `
514
+ import type { NodeAPI } from 'node-red';
515
+ ${currentContext.listNodesFull.map((node) => `import ${node.pascalName} from '${node.editor.tsPath}';`).join("\n")}
516
+
517
+ declare const RED: NodeAPI;
518
+
519
+ ${currentContext.listNodesFull.map((node) => `// @ts-ignore
520
+ window.RED.nodes.registerType('${node.name}', ${node.pascalName});`).join("\n")}
521
+ `.trim();
522
+ });
523
+ }
524
+ getBuiltScript() {
525
+ return __async(this, null, function* () {
526
+ const result = yield esbuild.build({
527
+ entryPoints: [currentContext.cacheDirFiles.editorIndex],
528
+ bundle: true,
529
+ platform: "browser",
530
+ format: "iife",
531
+ target: "es6",
532
+ sourcemap: false,
533
+ minify: this.params.minify,
534
+ minifyWhitespace: this.params.minify,
535
+ minifySyntax: this.params.minify,
536
+ minifyIdentifiers: this.params.minify,
537
+ legalComments: "none",
538
+ inject: [`${currentContext.currentPackagedDistPath}/editor/global-solid.ts`],
539
+ write: false,
540
+ loader: { ".ts": "ts" }
541
+ });
542
+ if (result.outputFiles && result.outputFiles.length > 0) {
543
+ return result.outputFiles[0].text;
544
+ }
545
+ return "";
546
+ });
547
+ }
548
+ prepareEditorIndex() {
549
+ return __async(this, null, function* () {
550
+ const js = yield this.getBuiltScript();
551
+ const html = yield getNodesHtml({
552
+ minify: this.params.minify,
553
+ nodes: currentContext.listNodesFull,
554
+ packageNameSlug: currentContext.packageNameSlug
555
+ });
556
+ const css = yield getAllCompiledStyles({
557
+ rawHtml: html.html,
558
+ minify: this.params.minify,
559
+ nodes: currentContext.listNodesFull
560
+ });
561
+ const builderDoc = new BuildDoc();
562
+ const docs = builderDoc.getAllDocContent();
563
+ const wrappedJs = `<script type="application/javascript">${js.trim()}</script>`;
564
+ const wrappedCss = `<style>${css}</style>`;
565
+ return `
566
+ ${html.allWrappedHtml}
567
+ ${wrappedCss}
568
+ ${wrappedJs}
569
+ ${docs}`.trim();
570
+ });
571
+ }
572
+ getEditorTask() {
573
+ return __async(this, null, function* () {
574
+ return this.getEditorIndexContent().then((content) => {
575
+ writeFile(`${currentContext.cacheDirFiles.editorIndex}`, content).then(() => {
576
+ this.prepareEditorIndex().then((contentFinalIndexHtml) => __async(this, null, function* () {
577
+ yield writeFile(
578
+ `${currentContext.pathDist}/${currentContext.config.nodes.editor.htmlName}.html`,
579
+ contentFinalIndexHtml
580
+ );
581
+ }));
582
+ });
583
+ });
584
+ });
585
+ }
586
+ };
587
+ function getWithContent(path3) {
588
+ return __async(this, null, function* () {
589
+ const codeLang = path3.split("/").pop().split(".").shift();
590
+ const content = yield fsPromise.readFile(path3, "utf-8");
591
+ return {
592
+ codeLang,
593
+ content
594
+ };
595
+ });
596
+ }
597
+ function getGlobalLocales() {
598
+ return __async(this, null, function* () {
599
+ const nodesList = currentContext.listNodesFullNames;
600
+ const srcLocales = currentContext.resolvedSrcLocalesPaths;
601
+ const srcLocalesWithContent = yield Promise.all(srcLocales.map(getWithContent));
602
+ const grouped = {};
603
+ nodesList.forEach((nodeName) => {
604
+ for (const { codeLang, content } of srcLocalesWithContent) {
605
+ if (!grouped[codeLang]) {
606
+ grouped[codeLang] = [];
607
+ }
608
+ grouped[codeLang].push(`"${nodeName}":${content}`);
609
+ }
610
+ });
611
+ let allContent = "";
612
+ for (const [lang, locales] of Object.entries(grouped)) {
613
+ const content = locales.map((innerContent) => innerContent).join(",").slice(0, -1);
614
+ allContent += `"${lang}":{${content}},`;
615
+ }
616
+ return `{${allContent.slice(0, -1)}}`;
617
+ });
618
+ }
619
+ function processNode(path3) {
620
+ return __async(this, null, function* () {
621
+ const cleanPath = path3.replace(`${currentContext.pathSrcNodesDir}${sep}`, "");
622
+ const [nodeName, , fileName] = cleanPath.split(sep);
623
+ const [codeLang] = fileName.split(".");
624
+ const content = yield fsPromise.readFile(path3, "utf-8");
625
+ return {
626
+ nodeName,
627
+ codeLang,
628
+ path: path3,
629
+ content
630
+ };
631
+ });
632
+ }
633
+ function getScopedNodesLocales() {
634
+ return __async(this, null, function* () {
635
+ const toto = globSync(`${currentContext.pathSrcNodesDir}/**/locales/*.json`);
636
+ const res = yield Promise.all(toto.map(processNode));
637
+ const grouped = {};
638
+ res.forEach(({ nodeName, codeLang, content }) => {
639
+ if (!grouped[codeLang]) {
640
+ grouped[codeLang] = [];
641
+ }
642
+ grouped[codeLang].push(`"${nodeName}":${content}`);
643
+ });
644
+ let allContent = "";
645
+ for (const [lang, locales] of Object.entries(grouped)) {
646
+ const content = locales.map((innerContent) => innerContent).join(",").slice(0, -1);
647
+ allContent += `"${lang}":{${content}},`;
648
+ }
649
+ return `{${allContent.slice(0, -1)}}`;
650
+ });
651
+ }
652
+
653
+ // src/builder/locales/getLocales.ts
654
+ function writeAllLocales() {
655
+ return __async(this, null, function* () {
656
+ const [globalLocales, scopedLocales] = yield Promise.all([getGlobalLocales(), getScopedNodesLocales()]);
657
+ const res = merge(JSON.parse(globalLocales), JSON.parse(scopedLocales));
658
+ const toResolveCreateDirs = [];
659
+ const toResolve = [];
660
+ for (const [folderName, locales] of Object.entries(res)) {
661
+ toResolveCreateDirs.push(createFolderIfNotExists(`${currentContext.pathDist}/locales/${folderName}`));
662
+ toResolve.push(writeFile(`${currentContext.pathDist}/locales/${folderName}/index.json`, JSON.stringify(locales)));
663
+ }
664
+ yield Promise.all(toResolveCreateDirs);
665
+ yield Promise.all(toResolve);
666
+ });
667
+ }
668
+
669
+ // src/builder/Builder.class.ts
670
+ var Builder = class {
671
+ constructor(params) {
672
+ __publicField(this, "params");
673
+ __publicField(this, "builderController");
674
+ __publicField(this, "builderEditor");
675
+ this.params = __spreadValues({ minify: false }, params);
676
+ this.builderController = new BuilderController({
677
+ minify: this.params.minify
678
+ });
679
+ this.builderEditor = new BuilderEditor({
680
+ minify: this.params.minify
681
+ });
682
+ }
683
+ prepare() {
684
+ createFolderIfNotExists(currentContext.pathLibCacheDir);
685
+ const runs = [
686
+ cleanPaths([currentContext.pathDist]),
687
+ writeFile(`${currentContext.pathLibCacheDir}/config.json`, JSON.stringify(currentContext.config, null, 2))
688
+ ];
689
+ return Promise.all(runs);
690
+ }
691
+ buildAll() {
692
+ return __async(this, null, function* () {
693
+ yield this.prepare();
694
+ return Promise.all([
695
+ this.builderController.getControllerTask(),
696
+ this.builderEditor.getEditorTask(),
697
+ writeAllLocales()
698
+ ]);
699
+ });
700
+ }
701
+ };
702
+
703
+ export { Builder };
704
+ //# sourceMappingURL=index.js.map
705
+ //# sourceMappingURL=index.js.map