@reliverse/dler 1.7.16 → 1.7.17

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.
Files changed (165) hide show
  1. package/README.md +134 -206
  2. package/bin/app/agg/run.js +2 -8
  3. package/bin/app/build/cmd.js +4 -4
  4. package/bin/app/build/impl.d.ts +2 -6
  5. package/bin/app/build/impl.js +2 -46
  6. package/bin/app/conv/cmd.d.ts +8 -33
  7. package/bin/app/conv/cmd.js +185 -163
  8. package/bin/app/copy/cmd.js +1 -1
  9. package/bin/app/init/init-impl.js +3 -3
  10. package/bin/app/init/init-types.d.ts +8 -8
  11. package/bin/app/merge/cmd.d.ts +10 -24
  12. package/bin/app/merge/cmd.js +47 -464
  13. package/bin/app/migrate/codemods/anything-bun.js +1 -1
  14. package/bin/app/migrate/codemods/fs-relifso.d.ts +2 -2
  15. package/bin/app/migrate/codemods/fs-relifso.js +1 -1
  16. package/bin/app/migrate/codemods/nodenext-bundler.d.ts +2 -2
  17. package/bin/app/migrate/codemods/nodenext-bundler.js +1 -1
  18. package/bin/app/migrate/codemods/path-pathkit.d.ts +2 -2
  19. package/bin/app/migrate/codemods/path-pathkit.js +1 -1
  20. package/bin/app/migrate/codemods/readdir-glob.d.ts +2 -2
  21. package/bin/app/migrate/codemods/readdir-glob.js +1 -1
  22. package/bin/app/mkdist/cmd.js +4 -2
  23. package/bin/app/pack/cmd.d.ts +44 -0
  24. package/bin/app/pack/cmd.js +313 -0
  25. package/bin/app/pub/cmd.js +4 -4
  26. package/bin/app/pub/impl.d.ts +7 -0
  27. package/bin/app/pub/impl.js +97 -0
  28. package/bin/app/rename/cmd.js +1 -1
  29. package/bin/app/spell/cmd.d.ts +14 -5
  30. package/bin/app/spell/cmd.js +33 -33
  31. package/bin/app/spell/old.js +0 -0
  32. package/bin/app/{mock → unpack}/cmd.d.ts +10 -14
  33. package/bin/app/unpack/cmd.js +200 -0
  34. package/bin/cli.js +2 -2
  35. package/bin/libs/cfg/cfg-mod.d.ts +69 -0
  36. package/bin/libs/cfg/cfg-mod.js +61 -0
  37. package/bin/libs/cfg/rse/rse-impl/rse-biome.d.ts +2 -0
  38. package/bin/libs/cfg/rse/rse-impl/rse-biome.js +34 -0
  39. package/bin/libs/cfg/rse/rse-impl/rse-consts.d.ts +35 -0
  40. package/bin/libs/cfg/rse/rse-impl/rse-consts.js +37 -0
  41. package/bin/libs/cfg/rse/rse-impl/rse-content.d.ts +14 -0
  42. package/bin/libs/cfg/rse/rse-impl/rse-content.js +15 -0
  43. package/bin/libs/cfg/rse/rse-impl/rse-core.d.ts +14 -0
  44. package/bin/libs/cfg/rse/rse-impl/rse-core.js +63 -0
  45. package/bin/libs/cfg/rse/rse-impl/rse-create.d.ts +36 -0
  46. package/bin/libs/cfg/rse/rse-impl/rse-create.js +254 -0
  47. package/bin/libs/cfg/rse/rse-impl/rse-def-utils.d.ts +6 -0
  48. package/bin/libs/cfg/rse/rse-impl/rse-def-utils.js +225 -0
  49. package/bin/libs/cfg/rse/rse-impl/rse-default.d.ts +3 -0
  50. package/bin/libs/cfg/rse/rse-impl/rse-default.js +155 -0
  51. package/bin/libs/cfg/rse/rse-impl/rse-define.d.ts +125 -0
  52. package/bin/libs/cfg/rse/rse-impl/rse-define.js +4 -0
  53. package/bin/libs/cfg/rse/rse-impl/rse-detect.d.ts +23 -0
  54. package/bin/libs/cfg/rse/rse-impl/rse-detect.js +347 -0
  55. package/bin/libs/cfg/rse/rse-impl/rse-gen-cfg.d.ts +3 -0
  56. package/bin/libs/cfg/rse/rse-impl/rse-gen-cfg.js +186 -0
  57. package/bin/libs/cfg/rse/rse-impl/rse-inject.d.ts +1 -0
  58. package/bin/libs/cfg/rse/rse-impl/rse-inject.js +57 -0
  59. package/bin/libs/cfg/rse/rse-impl/rse-migrate.d.ts +5 -0
  60. package/bin/libs/cfg/rse/rse-impl/rse-migrate.js +56 -0
  61. package/bin/libs/cfg/rse/rse-impl/rse-path.d.ts +11 -0
  62. package/bin/libs/cfg/rse/rse-impl/rse-path.js +33 -0
  63. package/bin/libs/cfg/rse/rse-impl/rse-prompts.d.ts +5 -0
  64. package/bin/libs/cfg/rse/rse-impl/rse-prompts.js +12 -0
  65. package/bin/libs/cfg/rse/rse-impl/rse-read.d.ts +11 -0
  66. package/bin/libs/cfg/rse/rse-impl/rse-read.js +84 -0
  67. package/bin/libs/cfg/rse/rse-impl/rse-repair.d.ts +16 -0
  68. package/bin/libs/cfg/rse/rse-impl/rse-repair.js +137 -0
  69. package/bin/libs/cfg/rse/rse-impl/rse-schema.d.ts +130 -0
  70. package/bin/libs/cfg/rse/rse-impl/rse-schema.js +444 -0
  71. package/bin/libs/cfg/rse/rse-impl/rse-types.d.ts +75 -0
  72. package/bin/libs/cfg/rse/rse-impl/rse-types.js +0 -0
  73. package/bin/libs/cfg/rse/rse-impl/rse-unstable.d.ts +11 -0
  74. package/bin/libs/cfg/rse/rse-impl/rse-unstable.js +41 -0
  75. package/bin/libs/cfg/rse/rse-impl/rse-update.d.ts +10 -0
  76. package/bin/libs/cfg/rse/rse-impl/rse-update.js +152 -0
  77. package/bin/libs/cfg/rse/rse-impl/rse-utils.d.ts +17 -0
  78. package/bin/libs/cfg/rse/rse-impl/rse-utils.js +86 -0
  79. package/bin/libs/cfg/rse/rse-mod.d.ts +20 -0
  80. package/bin/libs/cfg/rse/rse-mod.js +20 -0
  81. package/bin/libs/cfg/types.d.ts +533 -0
  82. package/bin/libs/cfg/types.js +0 -0
  83. package/bin/libs/sdk/sdk-impl/build/build-library.d.ts +5 -5
  84. package/bin/libs/sdk/sdk-impl/build/build-library.js +1 -174
  85. package/bin/libs/sdk/sdk-impl/build/build-regular.d.ts +2 -1
  86. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +287 -240
  87. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/loaders/vue.d.ts +4 -4
  88. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/make.d.ts +8 -5
  89. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/make.js +199 -119
  90. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/utils/spinner.d.ts +99 -0
  91. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/utils/spinner.js +206 -0
  92. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-mod.js +92 -46
  93. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/raw.d.ts +2 -2
  94. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/utils.d.ts +2 -2
  95. package/bin/libs/sdk/sdk-impl/config/default.d.ts +6 -0
  96. package/bin/libs/sdk/sdk-impl/{cfg → config}/default.js +8 -18
  97. package/bin/libs/sdk/sdk-impl/{cfg → config}/info.js +1 -1
  98. package/bin/libs/sdk/sdk-impl/{cfg → config}/init.js +53 -43
  99. package/bin/libs/sdk/sdk-impl/{cfg → config}/load.d.ts +2 -2
  100. package/bin/libs/sdk/sdk-impl/{cfg → config}/load.js +6 -6
  101. package/bin/libs/sdk/sdk-impl/config/types.d.ts +533 -0
  102. package/bin/libs/sdk/sdk-impl/config/types.js +0 -0
  103. package/bin/libs/sdk/sdk-impl/library-flow.d.ts +2 -1
  104. package/bin/libs/sdk/sdk-impl/regular-flow.d.ts +2 -1
  105. package/bin/libs/sdk/sdk-impl/rules/reliverse/dler-config-health/dler-config-health.js +2 -2
  106. package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/deps-types.d.ts +6 -6
  107. package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/filesystem.js +1 -1
  108. package/bin/libs/sdk/sdk-impl/rules/reliverse/no-index-files/no-index-files.js +1 -1
  109. package/bin/libs/sdk/sdk-impl/rules/reliverse/self-include/self-include.js +2 -2
  110. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.d.ts +38 -0
  111. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.js +474 -0
  112. package/bin/libs/sdk/sdk-impl/spell/spells.d.ts +31 -0
  113. package/bin/libs/sdk/sdk-impl/spell/spells.js +85 -0
  114. package/bin/libs/sdk/sdk-impl/utils/binary.js +1 -1
  115. package/bin/libs/sdk/sdk-impl/utils/comments.d.ts +6 -0
  116. package/bin/libs/sdk/sdk-impl/utils/comments.js +41 -0
  117. package/bin/libs/sdk/sdk-impl/utils/finalize.d.ts +2 -1
  118. package/bin/libs/sdk/sdk-impl/utils/finalize.js +1 -0
  119. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.d.ts +6 -0
  120. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.js +7 -0
  121. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.d.ts +5 -0
  122. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.js +40 -0
  123. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.d.ts +24 -0
  124. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.js +0 -0
  125. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.d.ts +17 -0
  126. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.js +46 -0
  127. package/bin/libs/sdk/sdk-impl/utils/replacements.d.ts +0 -0
  128. package/bin/libs/sdk/sdk-impl/utils/replacements.js +0 -0
  129. package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.d.ts +3 -0
  130. package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.js +194 -0
  131. package/bin/libs/sdk/sdk-impl/utils/utils-build.d.ts +1 -2
  132. package/bin/libs/sdk/sdk-impl/utils/utils-clean.d.ts +1 -1
  133. package/bin/libs/sdk/sdk-impl/utils/utils-deps.d.ts +1 -1
  134. package/bin/libs/sdk/sdk-impl/utils/utils-determine.d.ts +1 -1
  135. package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.d.ts +4 -0
  136. package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.js +1 -0
  137. package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.d.ts +1 -1
  138. package/bin/libs/sdk/sdk-impl/utils/utils-package-json-libraries.d.ts +1 -1
  139. package/bin/libs/sdk/sdk-impl/utils/utils-package-json-regular.d.ts +1 -1
  140. package/bin/libs/sdk/sdk-impl/utils/utils-security.d.ts +1 -3
  141. package/bin/libs/sdk/sdk-impl/utils/utils-security.js +11 -10
  142. package/bin/libs/sdk/sdk-mod.d.ts +1 -6
  143. package/bin/libs/sdk/sdk-mod.js +0 -31
  144. package/bin/libs/sdk/sdk-types.d.ts +39 -582
  145. package/bin/mod.d.ts +1 -1
  146. package/bin/mod.js +1 -1
  147. package/package.json +11 -4
  148. package/bin/app/mock/cmd.js +0 -284
  149. package/bin/app/mock/mock.d.ts +0 -11
  150. package/bin/app/mock/mock.js +0 -97
  151. package/bin/libs/sdk/sdk-impl/cfg/default.d.ts +0 -5
  152. package/bin/libs/sdk/sdk-impl/cfg/define.d.ts +0 -2
  153. package/bin/libs/sdk/sdk-impl/cfg/define.js +0 -4
  154. package/bin/libs/sdk/sdk-impl/spell/spell-executors.d.ts +0 -10
  155. package/bin/libs/sdk/sdk-impl/spell/spell-executors.js +0 -307
  156. package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.d.ts +0 -7
  157. package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.js +0 -74
  158. package/bin/libs/sdk/sdk-impl/spell/spell-mod.d.ts +0 -4
  159. package/bin/libs/sdk/sdk-impl/spell/spell-mod.js +0 -87
  160. package/bin/libs/sdk/sdk-impl/spell/spell-parser.d.ts +0 -4
  161. package/bin/libs/sdk/sdk-impl/spell/spell-parser.js +0 -58
  162. package/bin/libs/sdk/sdk-impl/spell/spell-types.d.ts +0 -60
  163. /package/bin/{libs/sdk/sdk-impl/spell/spell-types.js → app/spell/old.d.ts} +0 -0
  164. /package/bin/libs/sdk/sdk-impl/{cfg → config}/info.d.ts +0 -0
  165. /package/bin/libs/sdk/sdk-impl/{cfg → config}/init.d.ts +0 -0
@@ -14,6 +14,7 @@ import { Bundle } from "magic-string";
14
14
  import pMap from "p-map";
15
15
  import prettyMilliseconds from "pretty-ms";
16
16
  import { isBinaryExt } from "../../libs/sdk/sdk-impl/utils/binary.js";
17
+ import { getCommentPrefix } from "../../libs/sdk/sdk-impl/utils/comments.js";
17
18
  import { createPerfTimer, getElapsedPerfTime } from "../../libs/sdk/sdk-impl/utils/utils-perf.js";
18
19
  import {
19
20
  checkPermissions,
@@ -21,44 +22,13 @@ import {
21
22
  handleError,
22
23
  validateFileExists,
23
24
  sanitizeInput,
24
- validateMergeOperation
25
+ validateMergeOperation,
26
+ setFileSizeLimits,
27
+ validatePath,
28
+ validateFileType,
29
+ validateContent
25
30
  } from "../../libs/sdk/sdk-impl/utils/utils-security.js";
26
31
  const DEFAULT_IGNORES = ["**/.git/**", "**/node_modules/**"];
27
- const COMMENT_MAP = {
28
- js: "// ",
29
- jsx: "// ",
30
- ts: "// ",
31
- tsx: "// ",
32
- c: "// ",
33
- cpp: "// ",
34
- h: "// ",
35
- java: "// ",
36
- go: "// ",
37
- kt: "// ",
38
- swift: "// ",
39
- rs: "// ",
40
- cs: "// ",
41
- json: "// ",
42
- proto: "// ",
43
- dart: "// ",
44
- py: "# ",
45
- rb: "# ",
46
- sh: "# ",
47
- pl: "# ",
48
- r: "# ",
49
- yml: "# ",
50
- yaml: "# ",
51
- sql: "-- ",
52
- lua: "-- ",
53
- css: "/* ",
54
- scss: "/* ",
55
- less: "/* ",
56
- html: "<!-- ",
57
- htm: "<!-- ",
58
- xml: "<!-- ",
59
- md: "<!-- "
60
- };
61
- const DEFAULT_COMMENT = "// ";
62
32
  const DEFAULT_SEPARATOR_RAW = "\\n\\n";
63
33
  const normalizeGlobPattern = (pattern) => {
64
34
  const sanitizedPattern = sanitizeInput(pattern);
@@ -82,12 +52,22 @@ const collectFiles = async (include, extraIgnore, recursive, sortBy, depth) => {
82
52
  onlyFiles: true,
83
53
  deep: recursive ? void 0 : 1
84
54
  });
55
+ const validFiles = [];
56
+ let binaryFilesDetected = false;
85
57
  for (const file of files) {
86
58
  await validateFileExists(file, "merge");
87
59
  await checkFileSize(file);
88
60
  await checkPermissions(file, "read");
61
+ if (await isBinaryExt(file)) {
62
+ binaryFilesDetected = true;
63
+ continue;
64
+ }
65
+ validFiles.push(file);
66
+ }
67
+ if (binaryFilesDetected) {
68
+ relinka("info", "Binary files were detected and skipped");
89
69
  }
90
- let filtered = [...new Set(files)];
70
+ let filtered = [...new Set(validFiles)];
91
71
  if (depth > 0) {
92
72
  const fileGroups = /* @__PURE__ */ new Map();
93
73
  for (const file of filtered) {
@@ -97,7 +77,10 @@ const collectFiles = async (include, extraIgnore, recursive, sortBy, depth) => {
97
77
  if (!fileGroups.has(groupKey)) {
98
78
  fileGroups.set(groupKey, []);
99
79
  }
100
- fileGroups.get(groupKey)?.push(file);
80
+ const group = fileGroups.get(groupKey);
81
+ if (group) {
82
+ group.push(file);
83
+ }
101
84
  }
102
85
  filtered = Array.from(fileGroups.values()).flat();
103
86
  }
@@ -120,6 +103,7 @@ const writeResult = async (sections, _separator, toFile, toStdout, dryRun, backu
120
103
  try {
121
104
  const bundle = new Bundle();
122
105
  for (const section of sections) {
106
+ validateContent(section, "text");
123
107
  bundle.addSource({
124
108
  content: new MagicString(section)
125
109
  });
@@ -144,6 +128,8 @@ const writeResult = async (sections, _separator, toFile, toStdout, dryRun, backu
144
128
  }
145
129
  if (!dryRun) {
146
130
  await checkPermissions(sanitizedPath, "write");
131
+ validatePath(sanitizedPath, process.cwd());
132
+ validateFileType("text");
147
133
  await fs.writeFile(sanitizedPath, finalContent, "utf8");
148
134
  if (generateSourceMap) {
149
135
  const map = bundle.generateMap({
@@ -227,107 +213,14 @@ ${prefix}${rel}`);
227
213
  }
228
214
  return magic.toString();
229
215
  };
230
- const updateTemplateInFile = async (templateName, templateContent, targetFile, dryRun, backup, generateSourceMap = false) => {
231
- try {
232
- const fileContent = await fs.readFile(targetFile, "utf8");
233
- const magic = new MagicString(fileContent);
234
- const templateStart = fileContent.indexOf(`export const ${templateName}: Template = {`);
235
- if (templateStart === -1) {
236
- throw new Error(`Template ${templateName} not found in file ${targetFile}`);
237
- }
238
- let currentBracketCount = 0;
239
- let endIndex = templateStart;
240
- for (let i = templateStart; i < fileContent.length; i++) {
241
- const char = fileContent[i];
242
- if (char === "{") {
243
- currentBracketCount++;
244
- } else if (char === "}") {
245
- currentBracketCount--;
246
- if (currentBracketCount === 0) {
247
- endIndex = i + 1;
248
- break;
249
- }
250
- }
251
- }
252
- magic.overwrite(templateStart, endIndex, templateContent);
253
- if (dryRun) {
254
- relinka("verbose", `[DRY RUN] Would update template ${templateName} in ${targetFile}`);
255
- return;
256
- }
257
- if (backup) {
258
- const backupPath = `${targetFile}.${Date.now()}.bak`;
259
- await fs.copyFile(targetFile, backupPath);
260
- }
261
- await fs.writeFile(targetFile, magic.toString(), "utf8");
262
- if (generateSourceMap) {
263
- const map = magic.generateMap({
264
- file: path.basename(targetFile),
265
- source: targetFile,
266
- includeContent: true,
267
- hires: true
268
- });
269
- const mapPath = `${targetFile}.map`;
270
- await fs.writeFile(mapPath, map.toString(), "utf8");
271
- const sourceMapRef = `
272
- //# sourceMappingURL=${path.basename(mapPath)}`;
273
- await fs.appendFile(targetFile, sourceMapRef, "utf8");
274
- }
275
- } catch (error) {
276
- handleError(error, "updateTemplateInFile");
277
- }
278
- };
279
- const generateTemplateContent = (template, templateConstName, templateKey, whitelabel, isDev) => {
280
- return `import type { Template } from "${isDev ? "~/libs/sdk/sdk-types" : "@reliverse/dler-sdk"}";
281
- ${(() => {
282
- const files = template.config.files;
283
- if (!files) return "";
284
- const hasPackageJson = Object.values(files).some(
285
- (f) => f.type === "json" && f.content
286
- );
287
- const hasTSConfig = Object.values(files).some(
288
- (f) => f.type === "json" && f.content
289
- );
290
- if (!hasPackageJson && !hasTSConfig) return "";
291
- const imports = [];
292
- if (hasPackageJson) imports.push("PackageJson");
293
- if (hasTSConfig) imports.push("TSConfig");
294
- return `import type { ${imports.join(", ")} } from "pkg-types";
295
- `;
296
- })()}
297
- export const ${templateConstName}: Template = ${JSON.stringify(template, null, 2).replace(
298
- /"([^"]+)":/g,
299
- (_, key) => {
300
- return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key) ? `${key}:` : `"${key}":`;
301
- }
302
- )};
303
- export const ${whitelabel}_TEMPLATES = {
304
- ${templateKey}: ${templateConstName},
305
- } as const;
306
- export type ${whitelabel}_TEMPLATE_NAMES = keyof typeof ${whitelabel}_TEMPLATES;
307
- export const ${whitelabel.toLowerCase()}TemplatesMap: Record<string, ${whitelabel}_TEMPLATE_NAMES> = {
308
- ${templateConstName}: "${templateKey}",
309
- };`;
310
- };
311
- const generateAggregatorContent = (templateNames, whitelabel, isDev) => {
312
- return `import type { Template } from "${isDev ? "~/libs/sdk/sdk-types" : "@reliverse/dler-sdk"}";
313
- ${templateNames.map((name) => `import { ${name}, ${whitelabel}_TEMPLATES as ${name}_TEMPLATES, ${whitelabel}_TEMPLATE_NAMES as ${name}_TEMPLATE_NAMES, ${whitelabel.toLowerCase()}TemplatesMap as ${name.toLowerCase()}TemplatesMap } from "./${name}";`).join("\n")}
314
- export const ${whitelabel}_TEMPLATES = {
315
- ${templateNames.map((name) => ` ...${name}_TEMPLATES,`).join("\n")}
316
- } as const;
317
- export type ${whitelabel}_TEMPLATE_NAMES = ${templateNames.map((name) => `${name}_TEMPLATE_NAMES`).join(" | ")};
318
- export const ${whitelabel.toLowerCase()}TemplatesMap: Record<string, ${whitelabel}_TEMPLATE_NAMES> = {
319
- ${templateNames.map((name) => ` ...${name.toLowerCase()}TemplatesMap,`).join("\n")}
320
- };`;
321
- };
322
216
  export default defineCommand({
323
217
  meta: {
324
218
  name: "merge",
325
- version: "1.0.0",
219
+ version: "1.2.1",
326
220
  description: "Merge text files with optional commented path header/footer, skips binaries/media, built for CI & interactive use. Supports copy-like patterns and advanced options."
327
221
  },
328
222
  args: defineArgs({
329
223
  /* ===== GENERAL ARGS ===== */
330
- dev: { type: "boolean", description: "Generate template for development" },
331
224
  s: { type: "array", description: "Input glob patterns" },
332
225
  d: { type: "string", description: "Output file path or directory" },
333
226
  ignore: { type: "array", description: "Extra ignore patterns" },
@@ -336,6 +229,14 @@ export default defineCommand({
336
229
  default: "txt",
337
230
  description: "Fallback extension when output path is omitted"
338
231
  },
232
+ "max-file-size": {
233
+ type: "number",
234
+ description: "Maximum size of a single file in bytes (default: 10MB)"
235
+ },
236
+ "max-merge-size": {
237
+ type: "number",
238
+ description: "Maximum total size of all files to merge in bytes (default: 100MB)"
239
+ },
339
240
  stdout: { type: "boolean", description: "Print to stdout" },
340
241
  noPath: {
341
242
  type: "boolean",
@@ -423,42 +324,27 @@ export default defineCommand({
423
324
  type: "boolean",
424
325
  description: "Generate source map for the merged output"
425
326
  },
426
- /* ===== TEMPLATE GENERATION ARGS ===== */
427
- "as-template": {
428
- type: "boolean",
429
- description: "Generate a TypeScript file with MOCK_TEMPLATES structure"
430
- },
431
- "template-whitelabel": {
432
- type: "string",
433
- description: "Custom prefix to use instead of 'DLER' in template generation",
434
- default: "DLER",
435
- dependencies: ["as-template"]
436
- },
437
- "template-update": {
438
- type: "string",
439
- description: "Update specific template in existing mock template file",
440
- dependencies: ["as-template"]
441
- },
442
- "template-multi": {
327
+ verbose: {
443
328
  type: "boolean",
444
- description: "Create multiple templates based on directory structure (default: true)",
445
- default: true,
446
- dependencies: ["as-template"]
329
+ description: "Enable verbose logging"
447
330
  },
448
- "template-per-file": {
331
+ force: {
449
332
  type: "boolean",
450
- description: "Create separate files for each template with an aggregator (default: false)",
451
- default: false,
452
- dependencies: ["as-template", "template-multi"]
333
+ description: "Overwrite or delete existing paths when conflicts are detected (default: true)",
334
+ default: true
453
335
  }
454
336
  }),
455
337
  async run({ args }) {
456
338
  try {
457
339
  const timer = createPerfTimer();
458
340
  const interactive = args.interactive ?? false;
459
- const isDev = args.dev ?? false;
460
- const whitelabel = args["template-whitelabel"] ?? "DLER";
461
341
  const depth = args.depth ?? 0;
342
+ const verbose = args.verbose ?? false;
343
+ const force = args.force ?? true;
344
+ if (verbose) {
345
+ relinka("log", "Verbose logging enabled");
346
+ relinka("log", `Force mode: ${force ? "enabled" : "disabled"}`);
347
+ }
462
348
  let include = args.s ?? [];
463
349
  if (include.length === 0) {
464
350
  const raw = await maybePrompt(
@@ -547,10 +433,10 @@ export default defineCommand({
547
433
  const header = args.header;
548
434
  const footer = args.footer;
549
435
  const selectFiles = args["select-files"] ?? false;
550
- const asTemplate = args["as-template"] ?? false;
436
+ setFileSizeLimits(args["max-file-size"], args["max-merge-size"]);
551
437
  let files = await collectFiles(include, ignore, recursive, sortBy, depth);
552
438
  if (files.length === 0) {
553
- throw new Error("No text files matched given patterns (binary/media files are skipped)");
439
+ throw new Error("No files matched given patterns");
554
440
  }
555
441
  if (selectFiles && interactive) {
556
442
  const selected = await multiselectPrompt({
@@ -565,312 +451,9 @@ export default defineCommand({
565
451
  throw new Error("No files selected for merging");
566
452
  }
567
453
  }
568
- if (args["template-update"]) {
569
- if (!outFile) {
570
- throw new Error("Output file path required for template update");
571
- }
572
- const templateName = args["template-update"];
573
- const templateData = {
574
- name: templateName.replace(/_DLER_TEMPLATE$/, "").replace(/_/g, " ").toLowerCase(),
575
- // Convert REACT_DLER_TEMPLATE to "react"
576
- description: `Template generated from ${files.length} files`,
577
- config: {
578
- files: {}
579
- }
580
- };
581
- for (const file of files) {
582
- const relPath = path.relative(process.cwd(), file);
583
- const ext = path.extname(file).slice(1).toLowerCase();
584
- const isBinary = await isBinaryExt(file);
585
- const fileName = path.basename(file).toLowerCase();
586
- let content = "";
587
- let type = "binary";
588
- if (!isBinary) {
589
- try {
590
- const fileContent = await fs.readFile(file, "utf8");
591
- if (ext === "json") {
592
- const jsonContent = JSON.parse(fileContent);
593
- if (fileName === "package.json") {
594
- content = jsonContent;
595
- type = "json";
596
- const magic = new MagicString(JSON.stringify(jsonContent, null, 2));
597
- magic.append(" satisfies PackageJson");
598
- content = magic.toString();
599
- } else if (fileName === "tsconfig.json") {
600
- content = jsonContent;
601
- type = "json";
602
- const magic = new MagicString(JSON.stringify(jsonContent, null, 2));
603
- magic.append(" satisfies TSConfig");
604
- content = magic.toString();
605
- } else {
606
- content = jsonContent;
607
- type = "json";
608
- }
609
- } else {
610
- content = fileContent;
611
- type = "text";
612
- }
613
- } catch (error) {
614
- type = "binary";
615
- if (asTemplate || args["template-update"]) {
616
- relinka(
617
- "warn",
618
- `Skipped file "${relPath}" due to error: ${error instanceof Error ? error.message : "unknown error"}`
619
- );
620
- }
621
- }
622
- } else if (asTemplate || args["template-update"]) {
623
- relinka("warn", `Skipped binary file "${relPath}"`);
624
- }
625
- templateData.config.files[relPath] = {
626
- content,
627
- type
628
- };
629
- }
630
- const templateContent = `export const ${templateName}: Template = ${JSON.stringify(
631
- templateData,
632
- null,
633
- 2
634
- ).replace(/"([^"]+)":/g, (_, key) => {
635
- return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key) ? `${key}:` : `"${key}":`;
636
- })};`;
637
- await updateTemplateInFile(
638
- templateName,
639
- templateContent,
640
- outFile,
641
- dryRun,
642
- backup,
643
- args.sourcemap
644
- );
645
- const elapsed2 = getElapsedPerfTime(timer);
646
- relinka(
647
- "success",
648
- `Successfully ${dryRun ? "would update" : "updated"} template "${templateName}" in "${outFile}" (in ${prettyMilliseconds(elapsed2)})`
649
- );
650
- return;
651
- }
652
- if (asTemplate) {
653
- const timer2 = {
654
- startTime: performance.now(),
655
- pausedAt: null,
656
- pausedDuration: 0
657
- };
658
- const templateMulti = args["template-multi"] ?? true;
659
- const templatePerFile = args["template-per-file"] ?? false;
660
- if (!outFile) {
661
- outFile = templatePerFile ? "templates/index.ts" : "templates.ts";
662
- } else if (!outFile.endsWith(".ts")) {
663
- outFile = `${outFile}.ts`;
664
- }
665
- const baseDir = path.dirname(outFile);
666
- if (templateMulti) {
667
- const fileGroups = /* @__PURE__ */ new Map();
668
- const templateDepth = depth;
669
- for (const file of files) {
670
- const relPath = path.relative(process.cwd(), file);
671
- const parts = relPath.split(path.sep);
672
- const groupKey = parts.slice(0, templateDepth + 1).join(path.sep);
673
- if (!fileGroups.has(groupKey)) {
674
- fileGroups.set(groupKey, []);
675
- }
676
- fileGroups.get(groupKey)?.push(file);
677
- }
678
- const templateNames = [];
679
- for (const [groupKey, groupFiles] of fileGroups) {
680
- const templateName = groupKey.split(path.sep).pop() || groupKey;
681
- const templateConstName = templateName.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "").replace(/[A-Z]/g, (letter) => `_${letter}`).replace(/^_/, "").toUpperCase() + `_${whitelabel}_TEMPLATE`;
682
- const templateKey = templateName.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "").toLowerCase();
683
- const template = {
684
- name: templateName.toLowerCase(),
685
- description: `Template generated from ${groupFiles.length} files in ${groupKey}`,
686
- config: {
687
- files: {}
688
- }
689
- };
690
- for (const file of groupFiles) {
691
- const relPath = path.relative(process.cwd(), file);
692
- const ext = path.extname(file).slice(1).toLowerCase();
693
- const isBinary = await isBinaryExt(file);
694
- const fileName = path.basename(file).toLowerCase();
695
- let content = "";
696
- let type = "binary";
697
- if (!isBinary) {
698
- try {
699
- const fileContent = await fs.readFile(file, "utf8");
700
- if (ext === "json") {
701
- const jsonContent = JSON.parse(fileContent);
702
- if (fileName === "package.json") {
703
- content = jsonContent;
704
- type = "json";
705
- const magic = new MagicString(JSON.stringify(jsonContent, null, 2));
706
- magic.append(" satisfies PackageJson");
707
- content = magic.toString();
708
- } else if (fileName === "tsconfig.json") {
709
- content = jsonContent;
710
- type = "json";
711
- const magic = new MagicString(JSON.stringify(jsonContent, null, 2));
712
- magic.append(" satisfies TSConfig");
713
- content = magic.toString();
714
- } else {
715
- content = jsonContent;
716
- type = "json";
717
- }
718
- } else {
719
- content = fileContent;
720
- type = "text";
721
- }
722
- } catch (error) {
723
- type = "binary";
724
- if (asTemplate || args["template-update"]) {
725
- relinka(
726
- "warn",
727
- `Skipped file "${relPath}" due to error: ${error instanceof Error ? error.message : "unknown error"}`
728
- );
729
- }
730
- }
731
- } else if (asTemplate || args["template-update"]) {
732
- relinka("warn", `Skipped binary file "${relPath}"`);
733
- }
734
- template.config.files[relPath] = {
735
- content,
736
- type
737
- };
738
- }
739
- const templateContent = generateTemplateContent(
740
- template,
741
- templateConstName,
742
- templateKey,
743
- whitelabel,
744
- isDev
745
- );
746
- if (templatePerFile) {
747
- const templateFileName = `${templateKey}.ts`;
748
- const templateFilePath = path.join(baseDir, templateFileName);
749
- if (dryRun) {
750
- relinka("verbose", `[DRY RUN] Would write template file: ${templateFilePath}`);
751
- } else {
752
- await fs.ensureDir(path.dirname(templateFilePath));
753
- if (backup && await fs.pathExists(templateFilePath)) {
754
- const backupPath = `${templateFilePath}.${Date.now()}.bak`;
755
- await fs.copyFile(templateFilePath, backupPath);
756
- }
757
- await fs.writeFile(templateFilePath, templateContent, "utf8");
758
- }
759
- templateNames.push(templateKey);
760
- } else {
761
- if (!dryRun) {
762
- await fs.ensureDir(path.dirname(outFile));
763
- if (backup && await fs.pathExists(outFile)) {
764
- const backupPath = `${outFile}.${Date.now()}.bak`;
765
- await fs.copyFile(outFile, backupPath);
766
- }
767
- await fs.appendFile(outFile, templateContent + "\n\n", "utf8");
768
- }
769
- templateNames.push(templateKey);
770
- }
771
- }
772
- if (templatePerFile) {
773
- const aggregatorContent = generateAggregatorContent(templateNames, whitelabel, isDev);
774
- if (dryRun) {
775
- relinka("verbose", `[DRY RUN] Would write aggregator file: ${outFile}`);
776
- } else {
777
- await fs.ensureDir(path.dirname(outFile));
778
- if (backup && await fs.pathExists(outFile)) {
779
- const backupPath = `${outFile}.${Date.now()}.bak`;
780
- await fs.copyFile(outFile, backupPath);
781
- }
782
- await fs.writeFile(outFile, aggregatorContent, "utf8");
783
- }
784
- }
785
- } else {
786
- const templateName = path.basename(outFile, ".ts");
787
- const templateConstName = templateName.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "").replace(/[A-Z]/g, (letter) => `_${letter}`).replace(/^_/, "").toUpperCase() + `_${whitelabel}_TEMPLATE`;
788
- const templateKey = templateName.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "").toLowerCase();
789
- const template = {
790
- name: templateName.toLowerCase(),
791
- description: `Template generated from ${files.length} files`,
792
- config: {
793
- files: {}
794
- }
795
- };
796
- for (const file of files) {
797
- const relPath = path.relative(process.cwd(), file);
798
- const ext = path.extname(file).slice(1).toLowerCase();
799
- const isBinary = await isBinaryExt(file);
800
- const fileName = path.basename(file).toLowerCase();
801
- let content = "";
802
- let type = "binary";
803
- if (!isBinary) {
804
- try {
805
- const fileContent = await fs.readFile(file, "utf8");
806
- if (ext === "json") {
807
- const jsonContent = JSON.parse(fileContent);
808
- if (fileName === "package.json") {
809
- content = jsonContent;
810
- type = "json";
811
- const magic = new MagicString(JSON.stringify(jsonContent, null, 2));
812
- magic.append(" satisfies PackageJson");
813
- content = magic.toString();
814
- } else if (fileName === "tsconfig.json") {
815
- content = jsonContent;
816
- type = "json";
817
- const magic = new MagicString(JSON.stringify(jsonContent, null, 2));
818
- magic.append(" satisfies TSConfig");
819
- content = magic.toString();
820
- } else {
821
- content = jsonContent;
822
- type = "json";
823
- }
824
- } else {
825
- content = fileContent;
826
- type = "text";
827
- }
828
- } catch (error) {
829
- type = "binary";
830
- if (asTemplate || args["template-update"]) {
831
- relinka(
832
- "warn",
833
- `Skipped file "${relPath}" due to error: ${error instanceof Error ? error.message : "unknown error"}`
834
- );
835
- }
836
- }
837
- } else if (asTemplate || args["template-update"]) {
838
- relinka("warn", `Skipped binary file "${relPath}"`);
839
- }
840
- template.config.files[relPath] = {
841
- content,
842
- type
843
- };
844
- }
845
- const templateContent = generateTemplateContent(
846
- template,
847
- templateConstName,
848
- templateKey,
849
- whitelabel,
850
- isDev
851
- );
852
- if (dryRun) {
853
- relinka("verbose", `[DRY RUN] Would write template file: ${outFile}`);
854
- } else {
855
- await fs.ensureDir(path.dirname(outFile));
856
- if (backup && await fs.pathExists(outFile)) {
857
- const backupPath = `${outFile}.${Date.now()}.bak`;
858
- await fs.copyFile(outFile, backupPath);
859
- }
860
- await fs.writeFile(outFile, templateContent, "utf8");
861
- }
862
- }
863
- const elapsed2 = getElapsedPerfTime(timer2);
864
- relinka(
865
- "success",
866
- `Successfully ${dryRun ? "would generate" : "generated"} template file(s) (in ${prettyMilliseconds(elapsed2)})`
867
- );
868
- return;
869
- }
870
454
  const getPrefix = (filePath) => {
871
455
  if (forceComment && customComment) return customComment;
872
- const ext = path.extname(filePath).slice(1).toLowerCase();
873
- return COMMENT_MAP[ext] ?? customComment ?? DEFAULT_COMMENT;
456
+ return getCommentPrefix(filePath, forceComment, customComment);
874
457
  };
875
458
  if (outFile && await fs.pathExists(outFile) && (await fs.stat(outFile)).isDirectory()) {
876
459
  await writeFilesPreserveStructure(
@@ -1,7 +1,7 @@
1
+ import { join, resolve } from "@reliverse/pathkit";
1
2
  import { relinka } from "@reliverse/relinka";
2
3
  import { existsSync } from "node:fs";
3
4
  import { mkdir, writeFile, readFile } from "node:fs/promises";
4
- import { join, resolve } from "node:path";
5
5
  import { readPackageJSON } from "pkg-types";
6
6
  import { glob } from "tinyglobby";
7
7
  const NODE_MODULES = [
@@ -1,8 +1,8 @@
1
- type MigrationResult = {
1
+ interface MigrationResult {
2
2
  file: string;
3
3
  success: boolean;
4
4
  message: string;
5
5
  changes?: string[];
6
- };
6
+ }
7
7
  export declare function migrateFsToRelifso(dryRun?: boolean): Promise<MigrationResult[]>;
8
8
  export {};
@@ -1,6 +1,6 @@
1
+ import { join, extname } from "@reliverse/pathkit";
1
2
  import { existsSync } from "node:fs";
2
3
  import { readFile, writeFile, readdir, stat } from "node:fs/promises";
3
- import { join, extname } from "node:path";
4
4
  async function getAllTsFiles(dir) {
5
5
  const files = [];
6
6
  try {
@@ -1,9 +1,9 @@
1
- type MigrationResult = {
1
+ interface MigrationResult {
2
2
  file: string;
3
3
  success: boolean;
4
4
  message: string;
5
5
  changes?: string[];
6
- };
6
+ }
7
7
  export declare function migrateToNodeNext(dryRun?: boolean): Promise<MigrationResult[]>;
8
8
  export declare function migrateToBundler(dryRun?: boolean): Promise<MigrationResult[]>;
9
9
  export declare function migrateModuleResolution(target: "nodenext" | "bundler", dryRun?: boolean): Promise<MigrationResult[]>;
@@ -1,7 +1,7 @@
1
1
  import { getFileImportsExports } from "@reliverse/pathkit";
2
+ import { join, extname } from "@reliverse/pathkit";
2
3
  import { existsSync } from "node:fs";
3
4
  import { readFile, writeFile, readdir, stat } from "node:fs/promises";
4
- import { join, extname } from "node:path";
5
5
  async function getAllTsFiles(dir) {
6
6
  const files = [];
7
7
  try {
@@ -1,8 +1,8 @@
1
- type MigrationResult = {
1
+ interface MigrationResult {
2
2
  file: string;
3
3
  success: boolean;
4
4
  message: string;
5
5
  changes?: string[];
6
- };
6
+ }
7
7
  export declare function migratePathToPathkit(dryRun?: boolean): Promise<MigrationResult[]>;
8
8
  export {};
@@ -1,6 +1,6 @@
1
+ import { join, extname } from "@reliverse/pathkit";
1
2
  import { existsSync } from "node:fs";
2
3
  import { readFile, writeFile, readdir, stat } from "node:fs/promises";
3
- import { join, extname } from "node:path";
4
4
  async function getAllTsFiles(dir) {
5
5
  const files = [];
6
6
  try {