@reliverse/dler 1.7.15 → 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 (167) hide show
  1. package/README.md +164 -191
  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 +17 -17
  12. package/bin/app/merge/cmd.js +70 -310
  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/pub/pub-library.js +7 -0
  105. package/bin/libs/sdk/sdk-impl/pub/pub-regular.js +4 -8
  106. package/bin/libs/sdk/sdk-impl/regular-flow.d.ts +2 -1
  107. package/bin/libs/sdk/sdk-impl/rules/reliverse/dler-config-health/dler-config-health.js +2 -2
  108. package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/deps-types.d.ts +6 -6
  109. package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/filesystem.js +1 -1
  110. package/bin/libs/sdk/sdk-impl/rules/reliverse/no-index-files/no-index-files.js +1 -1
  111. package/bin/libs/sdk/sdk-impl/rules/reliverse/self-include/self-include.js +2 -2
  112. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.d.ts +38 -0
  113. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.js +474 -0
  114. package/bin/libs/sdk/sdk-impl/spell/spells.d.ts +31 -0
  115. package/bin/libs/sdk/sdk-impl/spell/spells.js +85 -0
  116. package/bin/libs/sdk/sdk-impl/utils/binary.js +1 -1
  117. package/bin/libs/sdk/sdk-impl/utils/comments.d.ts +6 -0
  118. package/bin/libs/sdk/sdk-impl/utils/comments.js +41 -0
  119. package/bin/libs/sdk/sdk-impl/utils/finalize.d.ts +2 -1
  120. package/bin/libs/sdk/sdk-impl/utils/finalize.js +1 -0
  121. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.d.ts +6 -0
  122. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.js +7 -0
  123. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.d.ts +5 -0
  124. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.js +40 -0
  125. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.d.ts +24 -0
  126. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.js +0 -0
  127. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.d.ts +17 -0
  128. package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.js +46 -0
  129. package/bin/libs/sdk/sdk-impl/utils/replacements.d.ts +0 -0
  130. package/bin/libs/sdk/sdk-impl/utils/replacements.js +0 -0
  131. package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.d.ts +3 -0
  132. package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.js +194 -0
  133. package/bin/libs/sdk/sdk-impl/utils/utils-build.d.ts +1 -2
  134. package/bin/libs/sdk/sdk-impl/utils/utils-clean.d.ts +1 -1
  135. package/bin/libs/sdk/sdk-impl/utils/utils-deps.d.ts +1 -1
  136. package/bin/libs/sdk/sdk-impl/utils/utils-determine.d.ts +1 -1
  137. package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.d.ts +4 -0
  138. package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.js +1 -0
  139. package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.d.ts +1 -1
  140. package/bin/libs/sdk/sdk-impl/utils/utils-package-json-libraries.d.ts +1 -1
  141. package/bin/libs/sdk/sdk-impl/utils/utils-package-json-regular.d.ts +1 -1
  142. package/bin/libs/sdk/sdk-impl/utils/utils-security.d.ts +1 -3
  143. package/bin/libs/sdk/sdk-impl/utils/utils-security.js +11 -10
  144. package/bin/libs/sdk/sdk-mod.d.ts +1 -6
  145. package/bin/libs/sdk/sdk-mod.js +0 -31
  146. package/bin/libs/sdk/sdk-types.d.ts +39 -582
  147. package/bin/mod.d.ts +1 -1
  148. package/bin/mod.js +1 -1
  149. package/package.json +11 -4
  150. package/bin/app/mock/cmd.js +0 -284
  151. package/bin/app/mock/mock.d.ts +0 -11
  152. package/bin/app/mock/mock.js +0 -97
  153. package/bin/libs/sdk/sdk-impl/cfg/default.d.ts +0 -5
  154. package/bin/libs/sdk/sdk-impl/cfg/define.d.ts +0 -2
  155. package/bin/libs/sdk/sdk-impl/cfg/define.js +0 -4
  156. package/bin/libs/sdk/sdk-impl/spell/spell-executors.d.ts +0 -10
  157. package/bin/libs/sdk/sdk-impl/spell/spell-executors.js +0 -307
  158. package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.d.ts +0 -7
  159. package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.js +0 -74
  160. package/bin/libs/sdk/sdk-impl/spell/spell-mod.d.ts +0 -4
  161. package/bin/libs/sdk/sdk-impl/spell/spell-mod.js +0 -87
  162. package/bin/libs/sdk/sdk-impl/spell/spell-parser.d.ts +0 -4
  163. package/bin/libs/sdk/sdk-impl/spell/spell-parser.js +0 -58
  164. package/bin/libs/sdk/sdk-impl/spell/spell-types.d.ts +0 -60
  165. /package/bin/{libs/sdk/sdk-impl/spell/spell-types.js → app/spell/old.d.ts} +0 -0
  166. /package/bin/libs/sdk/sdk-impl/{cfg → config}/info.d.ts +0 -0
  167. /package/bin/libs/sdk/sdk-impl/{cfg → config}/init.d.ts +0 -0
@@ -1,307 +0,0 @@
1
- import path from "@reliverse/pathkit";
2
- import * as fs from "./spell-filesystem.js";
3
- export const replaceLineExecutor = async (spell, filePath, content) => {
4
- if (!spell.lineNumber) {
5
- return {
6
- spell,
7
- file: filePath,
8
- success: false,
9
- message: "Line number not provided"
10
- };
11
- }
12
- if (!spell.value) {
13
- return {
14
- spell,
15
- file: filePath,
16
- success: false,
17
- message: "Target file not specified"
18
- };
19
- }
20
- const includeFilePath = path.resolve(path.dirname(filePath), spell.value);
21
- try {
22
- const includeContent = await fs.readFile(includeFilePath);
23
- const lines = content.split("\n");
24
- const originalLine = lines[spell.lineNumber - 1];
25
- lines[spell.lineNumber - 1] = includeContent.trim();
26
- const newContent = lines.join("\n");
27
- await fs.writeFile(filePath, newContent);
28
- return {
29
- spell,
30
- file: filePath,
31
- success: true,
32
- message: `Line replaced with content from ${includeFilePath}`,
33
- changes: {
34
- before: originalLine ?? "",
35
- after: includeContent.trim()
36
- }
37
- };
38
- } catch (error) {
39
- return {
40
- spell,
41
- file: filePath,
42
- success: false,
43
- message: `Failed to replace line: ${error}`
44
- };
45
- }
46
- };
47
- export const renameFileExecutor = async (spell, filePath) => {
48
- if (!spell.value) {
49
- return {
50
- spell,
51
- file: filePath,
52
- success: false,
53
- message: "New filename not provided"
54
- };
55
- }
56
- const newPath = path.resolve(path.dirname(filePath), spell.value);
57
- try {
58
- await fs.renameFile(filePath, newPath);
59
- return {
60
- spell,
61
- file: filePath,
62
- success: true,
63
- message: `File renamed to ${newPath}`
64
- };
65
- } catch (error) {
66
- return {
67
- spell,
68
- file: filePath,
69
- success: false,
70
- message: `Failed to rename file: ${error}`
71
- };
72
- }
73
- };
74
- export const removeCommentExecutor = async (spell, filePath, content) => {
75
- if (!spell.lineNumber || !spell.fullMatch) {
76
- return {
77
- spell,
78
- file: filePath,
79
- success: false,
80
- message: "Line number or full match not provided"
81
- };
82
- }
83
- try {
84
- const lines = content.split("\n");
85
- const originalLine = lines[spell.lineNumber - 1];
86
- lines[spell.lineNumber - 1] = (originalLine ?? "").replace(spell.fullMatch, "").trim();
87
- const newContent = lines.join("\n");
88
- await fs.writeFile(filePath, newContent);
89
- return {
90
- spell,
91
- file: filePath,
92
- success: true,
93
- message: "Comment removed",
94
- changes: {
95
- before: originalLine ?? "",
96
- after: lines[spell.lineNumber - 1] ?? ""
97
- }
98
- };
99
- } catch (error) {
100
- return {
101
- spell,
102
- file: filePath,
103
- success: false,
104
- message: `Failed to remove comment: ${error}`
105
- };
106
- }
107
- };
108
- export const removeLineExecutor = async (spell, filePath, content) => {
109
- if (!spell.lineNumber) {
110
- return {
111
- spell,
112
- file: filePath,
113
- success: false,
114
- message: "Line number not provided"
115
- };
116
- }
117
- try {
118
- const lines = content.split("\n");
119
- const originalLine = lines[spell.lineNumber - 1];
120
- lines.splice(spell.lineNumber - 1, 1);
121
- const newContent = lines.join("\n");
122
- await fs.writeFile(filePath, newContent);
123
- return {
124
- spell,
125
- file: filePath,
126
- success: true,
127
- message: "Line removed",
128
- changes: {
129
- before: originalLine ?? "",
130
- after: ""
131
- }
132
- };
133
- } catch (error) {
134
- return {
135
- spell,
136
- file: filePath,
137
- success: false,
138
- message: `Failed to remove line: ${error}`
139
- };
140
- }
141
- };
142
- export const removeFileExecutor = async (spell, filePath) => {
143
- try {
144
- await fs.removeFile(filePath);
145
- return {
146
- spell,
147
- file: filePath,
148
- success: true,
149
- message: "File removed"
150
- };
151
- } catch (error) {
152
- return {
153
- spell,
154
- file: filePath,
155
- success: false,
156
- message: `Failed to remove file: ${error}`
157
- };
158
- }
159
- };
160
- export const copyFileExecutor = async (spell, filePath) => {
161
- if (!spell.value) {
162
- return {
163
- spell,
164
- file: filePath,
165
- success: false,
166
- message: "Target path not provided"
167
- };
168
- }
169
- const targetPath = path.resolve(path.dirname(filePath), spell.value);
170
- try {
171
- await fs.copyFile(filePath, targetPath, true);
172
- return {
173
- spell,
174
- file: filePath,
175
- success: true,
176
- message: `File copied to ${targetPath}`
177
- };
178
- } catch (error) {
179
- return {
180
- spell,
181
- file: filePath,
182
- success: false,
183
- message: `Failed to copy file: ${error}`
184
- };
185
- }
186
- };
187
- export const moveFileExecutor = async (spell, filePath) => {
188
- if (!spell.value) {
189
- return {
190
- spell,
191
- file: filePath,
192
- success: false,
193
- message: "Target path not provided"
194
- };
195
- }
196
- const targetPath = path.resolve(path.dirname(filePath), spell.value);
197
- try {
198
- await fs.renameFile(filePath, targetPath);
199
- return {
200
- spell,
201
- file: filePath,
202
- success: true,
203
- message: `File moved to ${targetPath}`
204
- };
205
- } catch (error) {
206
- return {
207
- spell,
208
- file: filePath,
209
- success: false,
210
- message: `Failed to move file: ${error}`
211
- };
212
- }
213
- };
214
- export const transformContentExecutor = async (spell, filePath, content) => {
215
- if (!spell.value) {
216
- return {
217
- spell,
218
- file: filePath,
219
- success: false,
220
- message: "Transform function not provided"
221
- };
222
- }
223
- try {
224
- let newContent = content;
225
- switch (spell.value) {
226
- case "trim-empty-lines":
227
- newContent = content.split("\n").filter((line) => line.trim() !== "").join("\n");
228
- break;
229
- case "normalize-imports":
230
- newContent = content.replace(
231
- /import\s+{([^}]+)}\s+from\s+['"]([^'"]+)['"]/g,
232
- (_, imports, source) => {
233
- const normalizedImports = imports.split(",").map((i) => i.trim()).sort().join(", ");
234
- return `import { ${normalizedImports} } from "${source}"`;
235
- }
236
- );
237
- break;
238
- default:
239
- return {
240
- spell,
241
- file: filePath,
242
- success: false,
243
- message: `Unknown transformation: ${spell.value}`
244
- };
245
- }
246
- await fs.writeFile(filePath, newContent);
247
- return {
248
- spell,
249
- file: filePath,
250
- success: true,
251
- message: `Content transformed with ${spell.value}`,
252
- changes: {
253
- before: content,
254
- after: newContent
255
- }
256
- };
257
- } catch (error) {
258
- return {
259
- spell,
260
- file: filePath,
261
- success: false,
262
- message: `Failed to transform content: ${error}`
263
- };
264
- }
265
- };
266
- export const insertAtExecutor = async (spell, filePath, content) => {
267
- if (!spell.value || !spell.params.content) {
268
- return {
269
- spell,
270
- file: filePath,
271
- success: false,
272
- message: "Position or content not provided"
273
- };
274
- }
275
- try {
276
- const lines = content.split("\n");
277
- const position = Number(spell.value);
278
- if (Number.isNaN(position) || position < 0 || position > lines.length) {
279
- return {
280
- spell,
281
- file: filePath,
282
- success: false,
283
- message: `Invalid position: ${spell.value}`
284
- };
285
- }
286
- lines.splice(position, 0, spell.params.content);
287
- const newContent = lines.join("\n");
288
- await fs.writeFile(filePath, newContent);
289
- return {
290
- spell,
291
- file: filePath,
292
- success: true,
293
- message: `Content inserted at position ${position}`,
294
- changes: {
295
- before: content,
296
- after: newContent
297
- }
298
- };
299
- } catch (error) {
300
- return {
301
- spell,
302
- file: filePath,
303
- success: false,
304
- message: `Failed to insert content: ${error}`
305
- };
306
- }
307
- };
@@ -1,7 +0,0 @@
1
- export declare const fileExists: (filePath: string) => Promise<boolean>;
2
- export declare const readFile: (filePath: string) => Promise<string>;
3
- export declare const writeFile: (filePath: string, content: string) => Promise<void>;
4
- export declare const removeFile: (filePath: string) => Promise<void>;
5
- export declare const renameFile: (oldPath: string, newPath: string) => Promise<void>;
6
- export declare const copyFile: (sourcePath: string, targetPath: string, overwrite?: boolean) => Promise<void>;
7
- export declare const findFiles: (patterns: string[], cwd?: string) => Promise<string[]>;
@@ -1,74 +0,0 @@
1
- import path from "@reliverse/pathkit";
2
- import fs from "@reliverse/relifso";
3
- export const fileExists = async (filePath) => {
4
- try {
5
- await fs.access(filePath);
6
- return true;
7
- } catch {
8
- return false;
9
- }
10
- };
11
- export const readFile = async (filePath) => {
12
- return await fs.readFile(filePath, "utf8");
13
- };
14
- export const writeFile = async (filePath, content) => {
15
- const dir = path.dirname(filePath);
16
- try {
17
- await fs.mkdir(dir, { recursive: true });
18
- await fs.writeFile(filePath, content, "utf8");
19
- } catch (error) {
20
- throw new Error(`Failed to write file ${filePath}: ${error}`);
21
- }
22
- };
23
- export const removeFile = async (filePath) => {
24
- try {
25
- await fs.unlink(filePath);
26
- } catch (error) {
27
- throw new Error(`Failed to remove file ${filePath}: ${error}`);
28
- }
29
- };
30
- export const renameFile = async (oldPath, newPath) => {
31
- try {
32
- const dir = path.dirname(newPath);
33
- await fs.mkdir(dir, { recursive: true });
34
- await fs.rename(oldPath, newPath);
35
- } catch (error) {
36
- throw new Error(`Failed to rename file ${oldPath} to ${newPath}: ${error}`);
37
- }
38
- };
39
- export const copyFile = async (sourcePath, targetPath, overwrite = true) => {
40
- try {
41
- const dir = path.dirname(targetPath);
42
- await fs.mkdir(dir, { recursive: true });
43
- const exists = await fileExists(targetPath);
44
- if (exists && !overwrite) {
45
- throw new Error(`Destination ${targetPath} already exists and overwrite is false.`);
46
- }
47
- await fs.copyFile(sourcePath, targetPath);
48
- } catch (error) {
49
- throw new Error(`Failed to copy file ${sourcePath} to ${targetPath}: ${error}`);
50
- }
51
- };
52
- export const findFiles = async (patterns, cwd = process.cwd()) => {
53
- const results = [];
54
- const scanDir = async (dir) => {
55
- const entries = await fs.readdir(dir, { withFileTypes: true });
56
- for (const entry of entries) {
57
- const fullPath = path.join(dir, entry.name);
58
- if (entry.isDirectory()) {
59
- await scanDir(fullPath);
60
- } else if (matchesAnyPattern(fullPath, patterns)) {
61
- results.push(fullPath);
62
- }
63
- }
64
- };
65
- await scanDir(cwd);
66
- return results;
67
- };
68
- const matchesAnyPattern = (filePath, patterns) => {
69
- if (patterns.length === 0) return true;
70
- return patterns.some((pattern) => {
71
- if (pattern === "*") return true;
72
- return filePath.includes(pattern);
73
- });
74
- };
@@ -1,4 +0,0 @@
1
- import type { Spell, SpellExecutionOptions, SpellResult } from "./spell-types";
2
- export declare const executeSpell: (spell: Spell, filePath: string, content: string) => Promise<SpellResult>;
3
- export declare const processFile: (filePath: string, options?: SpellExecutionOptions) => Promise<SpellResult[]>;
4
- export declare const spells: (options?: SpellExecutionOptions) => Promise<SpellResult[]>;
@@ -1,87 +0,0 @@
1
- import * as executors from "./spell-executors.js";
2
- import * as fs from "./spell-filesystem.js";
3
- import { extractSpellsFromFile } from "./spell-parser.js";
4
- export const executeSpell = async (spell, filePath, content) => {
5
- if (spell.params.hooked) {
6
- return {
7
- spell,
8
- file: filePath,
9
- success: true,
10
- message: "Skipped (hooked=true)"
11
- };
12
- }
13
- switch (spell.type) {
14
- case "replace-line":
15
- return await executors.replaceLineExecutor(spell, filePath, content);
16
- case "rename-file":
17
- return await executors.renameFileExecutor(spell, filePath);
18
- case "remove-comment":
19
- return await executors.removeCommentExecutor(spell, filePath, content);
20
- case "remove-line":
21
- return await executors.removeLineExecutor(spell, filePath, content);
22
- case "remove-file":
23
- return await executors.removeFileExecutor(spell, filePath);
24
- case "transform-content":
25
- return await executors.transformContentExecutor(spell, filePath, content);
26
- case "copy-file":
27
- return await executors.copyFileExecutor(spell, filePath);
28
- case "move-file":
29
- return await executors.moveFileExecutor(spell, filePath);
30
- case "insert-at":
31
- return await executors.insertAtExecutor(spell, filePath, content);
32
- default:
33
- return {
34
- spell,
35
- file: filePath,
36
- success: false,
37
- message: `Unknown spell type: ${spell.type}`
38
- };
39
- }
40
- };
41
- export const processFile = async (filePath, options = {}) => {
42
- const results = [];
43
- try {
44
- const content = await fs.readFile(filePath);
45
- const spells2 = await extractSpellsFromFile(filePath, content);
46
- for (const spell of spells2) {
47
- if (options.spells && options.spells.length > 0 && !options.spells.includes("all") && !options.spells.includes(spell.type)) {
48
- continue;
49
- }
50
- const result = await executeSpell(spell, filePath, content);
51
- results.push(result);
52
- if (result.success && (spell.type === "remove-file" || spell.type === "rename-file")) {
53
- break;
54
- }
55
- }
56
- return results;
57
- } catch (error) {
58
- return [
59
- {
60
- spell: { type: "unknown", params: { hooked: false } },
61
- file: filePath,
62
- success: false,
63
- message: `Failed to process file: ${error}`
64
- }
65
- ];
66
- }
67
- };
68
- export const spells = async (options = {}) => {
69
- const results = [];
70
- try {
71
- const filesToProcess = options.files?.length ? options.files : await fs.findFiles(["*"], process.cwd());
72
- for (const filePath of filesToProcess) {
73
- const fileResults = await processFile(filePath, options);
74
- results.push(...fileResults);
75
- }
76
- return results;
77
- } catch (error) {
78
- return [
79
- {
80
- spell: { type: "unknown", params: { hooked: false } },
81
- file: "unknown",
82
- success: false,
83
- message: `Failed to trigger spells: ${error}`
84
- }
85
- ];
86
- }
87
- };
@@ -1,4 +0,0 @@
1
- import type { Spell, SpellParams } from "./spell-types.js";
2
- export declare const parseParams: (paramsStr: string | undefined) => SpellParams;
3
- export declare const parseSpellFromComment: (line: string, lineNumber: number, fileName: string) => Spell | null;
4
- export declare const extractSpellsFromFile: (filePath: string, content: string) => Promise<Spell[]>;
@@ -1,58 +0,0 @@
1
- const SPELL_REGEX = /dler-([a-z-]+)-(?:"([^"]+)")?-?(?:{([^}]+)})?/;
2
- export const parseParams = (paramsStr) => {
3
- const defaultParams = {
4
- hooked: true
5
- };
6
- if (!paramsStr) return defaultParams;
7
- const params = { ...defaultParams };
8
- for (const param of paramsStr.split(",")) {
9
- const [key, value] = param.trim().split("=");
10
- if (key && value !== void 0) {
11
- if (value === "true") params[key] = true;
12
- else if (value === "false") params[key] = false;
13
- else if (!Number.isNaN(Number(value))) params[key] = Number(value);
14
- else params[key] = value;
15
- }
16
- }
17
- return params;
18
- };
19
- export const parseSpellFromComment = (line, lineNumber, fileName) => {
20
- const match = line.match(SPELL_REGEX);
21
- if (!match) return null;
22
- const [fullMatch, spellType, value, paramsStr] = match;
23
- if (!spellType || !isValidSpellType(spellType)) {
24
- console.warn(`Unknown spell type: ${spellType} in file ${fileName}:${lineNumber}`);
25
- return null;
26
- }
27
- return {
28
- type: spellType,
29
- params: parseParams(paramsStr),
30
- value,
31
- lineNumber,
32
- fullMatch,
33
- fileName
34
- };
35
- };
36
- export const extractSpellsFromFile = async (filePath, content) => {
37
- const lines = content.split("\n");
38
- const spells = [];
39
- lines.forEach((line, index) => {
40
- const spell = parseSpellFromComment(line, index + 1, filePath);
41
- if (spell) spells.push(spell);
42
- });
43
- return spells;
44
- };
45
- const isValidSpellType = (type) => {
46
- const validTypes = [
47
- "replace-line",
48
- "rename-file",
49
- "remove-comment",
50
- "remove-line",
51
- "remove-file",
52
- "transform-content",
53
- "copy-file",
54
- "move-file",
55
- "insert-at"
56
- ];
57
- return validTypes.includes(type);
58
- };
@@ -1,60 +0,0 @@
1
- export type SpellType = "replace-line" | "replace-range" | "rename-file" | "remove-comment" | "remove-line" | "remove-file" | "transform-content" | "transform-line" | "copy-file" | "move-file" | "insert-at" | "insert-before" | "insert-after" | "conditional-execute";
2
- export type SpellParams = {
3
- /** Whether the spell should be executed manually (true) or automatically at postbuild (false) */
4
- hooked: boolean;
5
- /** Line number to start the operation (for range operations) */
6
- startLine?: number;
7
- /** Line number to end the operation (for range operations) */
8
- endLine?: number;
9
- /** Condition to check before executing the spell */
10
- condition?: string;
11
- /** Whether to skip the spell if the target file doesn't exist */
12
- skipIfMissing?: boolean;
13
- /** Whether to create the target directory if it doesn't exist */
14
- createDir?: boolean;
15
- /** Custom parameters for specific spell types */
16
- [key: string]: any;
17
- };
18
- export type Spell = {
19
- type: SpellType;
20
- params: SpellParams;
21
- value?: string;
22
- lineNumber?: number;
23
- fullMatch?: string;
24
- fileName?: string;
25
- /** Optional array of spells that must be executed before this one */
26
- dependsOn?: Spell[];
27
- };
28
- export type SpellExecutionOptions = {
29
- spells?: (SpellType | "all")[];
30
- files?: string[];
31
- dryRun?: boolean;
32
- /** Whether to show detailed changes in the output */
33
- showChanges?: boolean;
34
- /** Whether to validate spell parameters before execution */
35
- validate?: boolean;
36
- };
37
- export type FileOperation = {
38
- type: "read" | "write" | "rename" | "remove" | "copy" | "move";
39
- sourcePath: string;
40
- targetPath?: string;
41
- content?: string;
42
- /** Whether to create parent directories if they don't exist */
43
- createDir?: boolean;
44
- };
45
- export type SpellResult = {
46
- spell: Spell;
47
- file: string;
48
- success: boolean;
49
- message?: string;
50
- changes?: {
51
- before: string;
52
- after: string;
53
- };
54
- /** Detailed information about the changes made */
55
- details?: {
56
- linesAffected?: number[];
57
- filesAffected?: string[];
58
- validationErrors?: string[];
59
- };
60
- };
File without changes
File without changes