@bonsae/nrg 0.26.3 → 0.28.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/vite/index.js CHANGED
@@ -3,6 +3,7 @@ import path15 from "path";
3
3
 
4
4
  // src/vite/defaults.ts
5
5
  var DEFAULT_OUTPUT_DIR = "./dist";
6
+ var DEFAULT_RESOURCES_DIR = "./src/resources";
6
7
  var DEFAULT_CLIENT_BUILD_OPTIONS = {
7
8
  srcDir: "./src/client",
8
9
  entry: "index.ts",
@@ -16,14 +17,7 @@ var DEFAULT_CLIENT_BUILD_OPTIONS = {
16
17
  "node-red": "RED",
17
18
  vue: "Vue"
18
19
  },
19
- locales: {
20
- docsDir: "./src/locales/docs",
21
- labelsDir: "./src/locales/labels"
22
- },
23
- staticDirs: {
24
- icons: "./src/icons",
25
- public: "./src/client/public"
26
- }
20
+ publicDir: "./src/client/public"
27
21
  };
28
22
  var DEFAULT_SERVER_BUILD_OPTIONS = {
29
23
  srcDir: "./src/server",
@@ -45,8 +39,7 @@ var DEFAULT_NODE_RED_LAUNCHER_OPTIONS = {
45
39
  };
46
40
  var DEFAULT_EXTRA_FILES_COPY_TARGETS = [
47
41
  { src: "./LICENSE", dest: "LICENSE" },
48
- { src: "./README.md", dest: "README.md" },
49
- { src: "./src/examples", dest: "examples" }
42
+ { src: "./README.md", dest: "README.md" }
50
43
  ];
51
44
 
52
45
  // src/vite/utils.ts
@@ -74,6 +67,16 @@ function copyFiles(targets, outDir) {
74
67
  }
75
68
  }
76
69
  }
70
+ var RESOURCE_PIPELINE_FOLDERS = /* @__PURE__ */ new Set(["icons", "locales"]);
71
+ function discoverResourceCopyTargets(resourcesDir) {
72
+ if (!fs.existsSync(resourcesDir)) return [];
73
+ return fs.readdirSync(resourcesDir, { withFileTypes: true }).filter(
74
+ (entry) => entry.isDirectory() && !RESOURCE_PIPELINE_FOLDERS.has(entry.name)
75
+ ).map((entry) => ({
76
+ src: path.join(resourcesDir, entry.name),
77
+ dest: entry.name
78
+ }));
79
+ }
77
80
  function getPackageName() {
78
81
  const pkgPath = path.resolve("./package.json");
79
82
  if (fs.existsSync(pkgPath)) {
@@ -110,13 +113,6 @@ function mergeOptions(defaults, overrides) {
110
113
  import fs4 from "fs";
111
114
 
112
115
  // src/vite/async-utils.ts
113
- function debounce(fn, delay) {
114
- let timeout = null;
115
- return (...args) => {
116
- if (timeout) clearTimeout(timeout);
117
- timeout = setTimeout(() => fn(...args), delay);
118
- };
119
- }
120
116
  function withTimeout(promise, ms, fallback) {
121
117
  return new Promise((resolve, reject) => {
122
118
  const timeout = setTimeout(() => {
@@ -767,6 +763,7 @@ var NodeRedLauncher = class {
767
763
  import chokidar from "chokidar";
768
764
  import treeKill2 from "tree-kill";
769
765
  import path14 from "path";
766
+ import { debounce } from "es-toolkit";
770
767
 
771
768
  // src/vite/server/build.ts
772
769
  import { build as viteBuild } from "vite";
@@ -1366,11 +1363,17 @@ function packageJsonGenerator(options) {
1366
1363
  distDependencies = void 0;
1367
1364
  }
1368
1365
  const distPackageJson = {
1369
- ...rootPackageJson,
1366
+ name: rootPackageJson.name,
1367
+ version: rootPackageJson.version,
1368
+ description: rootPackageJson.description,
1369
+ author: rootPackageJson.author,
1370
+ license: rootPackageJson.license,
1371
+ homepage: rootPackageJson.homepage,
1372
+ repository: rootPackageJson.repository,
1373
+ bugs: rootPackageJson.bugs,
1374
+ engines: rootPackageJson.engines,
1370
1375
  main: "index.js",
1371
1376
  type: "commonjs",
1372
- devDependencies: void 0,
1373
- scripts: void 0,
1374
1377
  dependencies: distDependencies,
1375
1378
  keywords: [
1376
1379
  .../* @__PURE__ */ new Set([...rootPackageJson.keywords ?? [], "node-red"])
@@ -2519,8 +2522,8 @@ function localesGenerator(options) {
2519
2522
  }
2520
2523
  },
2521
2524
  help: {
2522
- validateInput: "\u5728 input() \u8FD0\u884C\u524D\uFF0C\u6839\u636E\u8F93\u5165\u6A21\u5F0F\u6821\u9A8C\u4F20\u5165\u6D88\u606F\u3002",
2523
- outputs: "\u6309\u7AEF\u53E3\u7684\u8F93\u51FA\u8BBE\u7F6E\u3002\u9A8C\u8BC1\u6570\u636E\u6839\u636E\u7AEF\u53E3\u6A21\u5F0F\u6821\u9A8C\u53D1\u9001\u7684\u503C\uFF1B\u4E0A\u4E0B\u6587\u6A21\u5F0F\u63A7\u5236\u5982\u4F55\u643A\u5E26\u4F20\u5165\u6D88\u606F\u3002",
2525
+ validateInput: "\u5728 input() \u8FD0\u884C\u524D\uFF0C\u6839\u636E\u8F93\u5165\u7ED3\u6784\u63CF\u8FF0\u6821\u9A8C\u4F20\u5165\u6D88\u606F\u3002",
2526
+ outputs: "\u6309\u7AEF\u53E3\u7684\u8F93\u51FA\u8BBE\u7F6E\u3002\u9A8C\u8BC1\u6570\u636E\u6839\u636E\u7AEF\u53E3\u7ED3\u6784\u63CF\u8FF0\u6821\u9A8C\u53D1\u9001\u7684\u503C\uFF1B\u4E0A\u4E0B\u6587\u6A21\u5F0F\u63A7\u5236\u5982\u4F55\u643A\u5E26\u4F20\u5165\u6D88\u606F\u3002",
2524
2527
  lifecyclePorts: "\u53EF\u9009\u7684\u989D\u5916\u8F93\u51FA\u7AEF\u53E3\uFF0C\u5728\u51FA\u9519\u3001\u5B8C\u6210\u4EE5\u53CA\u6BCF\u6B21\u72B6\u6001\u53D8\u5316\u65F6\u89E6\u53D1\u3002",
2525
2528
  learnMore: "\u4E86\u89E3\u66F4\u591A"
2526
2529
  }
@@ -2963,12 +2966,12 @@ async function build2(clientBuildOptions, buildContext) {
2963
2966
  name = "NodeRedNodes",
2964
2967
  format = "es",
2965
2968
  licensePath = "./LICENSE",
2966
- locales,
2967
- staticDirs = {},
2969
+ publicDir,
2968
2970
  external = [],
2969
2971
  globals = {},
2970
2972
  manualChunks
2971
2973
  } = clientBuildOptions;
2974
+ const resourcesDir = buildContext.resourcesDir;
2972
2975
  const cacheDir = path13.resolve(
2973
2976
  "node_modules",
2974
2977
  ".nrg",
@@ -2989,9 +2992,7 @@ async function build2(clientBuildOptions, buildContext) {
2989
2992
  entryPath = cachedEntryPath;
2990
2993
  generatedEntry = true;
2991
2994
  }
2992
- const iconsDir = path13.resolve(
2993
- staticDirs.icons ?? path13.join(path13.dirname(path13.resolve(srcDir)), "icons")
2994
- );
2995
+ const iconsDir = path13.join(resourcesDir, "icons");
2995
2996
  const plugins = [
2996
2997
  vue(),
2997
2998
  nodeDefinitionsInliner(
@@ -3010,33 +3011,31 @@ async function build2(clientBuildOptions, buildContext) {
3010
3011
  licensePath: licensePath ? path13.resolve(licensePath) : void 0
3011
3012
  })
3012
3013
  );
3013
- if (locales) {
3014
- const { docsDir = "./locales/docs", labelsDir = "./locales/labels" } = locales;
3014
+ const localesDir = path13.join(resourcesDir, "locales");
3015
+ if (fs14.existsSync(localesDir)) {
3016
+ const docsDir = path13.join(localesDir, "docs");
3017
+ const labelsDir = path13.join(localesDir, "labels");
3015
3018
  const localesOutDir = path13.join(buildContext.outDir, "locales");
3016
3019
  plugins.push(
3017
- localesGenerator({
3018
- outDir: localesOutDir,
3019
- docsDir: path13.resolve(docsDir),
3020
- labelsDir: path13.resolve(labelsDir)
3021
- })
3020
+ localesGenerator({ outDir: localesOutDir, docsDir, labelsDir })
3022
3021
  );
3023
3022
  plugins.push(
3024
3023
  helpGenerator({
3025
3024
  outDir: buildContext.outDir,
3026
3025
  localesOutDir,
3027
- docsDir: path13.resolve(docsDir),
3028
- labelsDir: path13.resolve(labelsDir),
3026
+ docsDir,
3027
+ labelsDir,
3029
3028
  srcDir: buildContext.serverSrcDir
3030
3029
  })
3031
3030
  );
3032
3031
  }
3033
3032
  const copyTargets = [];
3034
- const publicDir = path13.resolve(
3035
- staticDirs.public ?? path13.join(srcDir, "public")
3033
+ const resolvedPublicDir = path13.resolve(
3034
+ publicDir ?? path13.join(srcDir, "public")
3036
3035
  );
3037
- if (fs14.existsSync(publicDir)) {
3036
+ if (fs14.existsSync(resolvedPublicDir)) {
3038
3037
  copyTargets.push({
3039
- src: publicDir,
3038
+ src: resolvedPublicDir,
3040
3039
  dest: path13.join(buildContext.outDir, "resources")
3041
3040
  });
3042
3041
  }
@@ -3294,21 +3293,10 @@ function serverPlugin(options) {
3294
3293
  const clientSrcDir = path14.resolve(
3295
3294
  clientBuildOptions.srcDir ?? "./client"
3296
3295
  );
3297
- const localesDocsDir = path14.resolve(
3298
- clientBuildOptions.locales?.docsDir ?? "./locales/docs"
3299
- );
3300
- const localesLabelsDir = path14.resolve(
3301
- clientBuildOptions.locales?.labelsDir ?? "./locales/labels"
3302
- );
3303
- const iconsDir = path14.resolve(
3304
- clientBuildOptions.staticDirs?.icons ?? path14.join(path14.dirname(clientSrcDir), "icons")
3305
- );
3306
3296
  const watchPaths = [
3307
3297
  serverSrcDir,
3308
3298
  clientSrcDir,
3309
- localesDocsDir,
3310
- localesLabelsDir,
3311
- iconsDir
3299
+ buildContext.resourcesDir
3312
3300
  ];
3313
3301
  watcher = chokidar.watch(watchPaths, {
3314
3302
  ignoreInitial: true,
@@ -3414,13 +3402,18 @@ function nrg(options = {}) {
3414
3402
  DEFAULT_NODE_RED_LAUNCHER_OPTIONS,
3415
3403
  server.nodeRed
3416
3404
  );
3417
- const extraFilesCopyTargets = build3.extraFilesCopyTargets ?? DEFAULT_EXTRA_FILES_COPY_TARGETS;
3405
+ const resourcesDir = path15.resolve(DEFAULT_RESOURCES_DIR);
3406
+ const extraFilesCopyTargets = [
3407
+ ...DEFAULT_EXTRA_FILES_COPY_TARGETS,
3408
+ ...discoverResourceCopyTargets(resourcesDir)
3409
+ ];
3418
3410
  const resolvedOutDir = path15.resolve(outDir);
3419
3411
  const buildContext = {
3420
3412
  outDir: resolvedOutDir,
3421
3413
  packageName: getPackageName(),
3422
3414
  isDev: process.env.NODE_ENV === "development",
3423
- serverSrcDir: path15.resolve(serverBuildOptions.srcDir ?? "./server")
3415
+ serverSrcDir: path15.resolve(serverBuildOptions.srcDir ?? "./server"),
3416
+ resourcesDir
3424
3417
  };
3425
3418
  const nodeRedLauncher = new NodeRedLauncher(
3426
3419
  resolvedOutDir,