@magmonium/cli 0.7.8

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 (204) hide show
  1. package/README.md +392 -0
  2. package/bin/README.md +244 -0
  3. package/bin/cli.js +55 -0
  4. package/bin/commands/assets-wc.js +249 -0
  5. package/bin/commands/assets.js +943 -0
  6. package/bin/commands/build.js +242 -0
  7. package/bin/commands/clean.js +621 -0
  8. package/bin/commands/compile-i18n.js +91 -0
  9. package/bin/commands/config-ci.js +266 -0
  10. package/bin/commands/configure-wc.js +167 -0
  11. package/bin/commands/connect.js +188 -0
  12. package/bin/commands/create-app.js +946 -0
  13. package/bin/commands/deploy.js +100 -0
  14. package/bin/commands/fix-i18n.js +40 -0
  15. package/bin/commands/generate.js +765 -0
  16. package/bin/commands/init/config-files.js +1114 -0
  17. package/bin/commands/init/mag-assets.js +541 -0
  18. package/bin/commands/init/mag-cli-config.js +120 -0
  19. package/bin/commands/init/monorepo-structure.js +735 -0
  20. package/bin/commands/init/package-json.js +308 -0
  21. package/bin/commands/init/project-structure.js +189 -0
  22. package/bin/commands/init/pwa-files.js +204 -0
  23. package/bin/commands/init/source-files.js +2596 -0
  24. package/bin/commands/init.js +591 -0
  25. package/bin/commands/lib.js +508 -0
  26. package/bin/commands/patch-wc-env.js +136 -0
  27. package/bin/commands/refractor.js +51 -0
  28. package/bin/commands/sanitize-i18n.js +41 -0
  29. package/bin/commands/translate.js +32 -0
  30. package/bin/commands/zip.js +540 -0
  31. package/package.json +53 -0
  32. package/src/compilers/button-group-compiler.d.ts +18 -0
  33. package/src/compilers/button-group-compiler.d.ts.map +1 -0
  34. package/src/compilers/button-group-compiler.js +151 -0
  35. package/src/compilers/button-group-compiler.js.map +1 -0
  36. package/src/compilers/copy-compiler.d.ts +14 -0
  37. package/src/compilers/copy-compiler.d.ts.map +1 -0
  38. package/src/compilers/copy-compiler.js +170 -0
  39. package/src/compilers/copy-compiler.js.map +1 -0
  40. package/src/compilers/field-compiler.d.ts +15 -0
  41. package/src/compilers/field-compiler.d.ts.map +1 -0
  42. package/src/compilers/field-compiler.js +153 -0
  43. package/src/compilers/field-compiler.js.map +1 -0
  44. package/src/compilers/form-compiler.d.ts +15 -0
  45. package/src/compilers/form-compiler.d.ts.map +1 -0
  46. package/src/compilers/form-compiler.js +220 -0
  47. package/src/compilers/form-compiler.js.map +1 -0
  48. package/src/compilers/logo-compiler.d.ts +14 -0
  49. package/src/compilers/logo-compiler.d.ts.map +1 -0
  50. package/src/compilers/logo-compiler.js +114 -0
  51. package/src/compilers/logo-compiler.js.map +1 -0
  52. package/src/compilers/options-compiler.d.ts +46 -0
  53. package/src/compilers/options-compiler.d.ts.map +1 -0
  54. package/src/compilers/options-compiler.js +329 -0
  55. package/src/compilers/options-compiler.js.map +1 -0
  56. package/src/compilers/pwa-build.d.ts +7 -0
  57. package/src/compilers/pwa-build.d.ts.map +1 -0
  58. package/src/compilers/pwa-build.js +62 -0
  59. package/src/compilers/pwa-build.js.map +1 -0
  60. package/src/compilers/svg-compiler.d.ts +12 -0
  61. package/src/compilers/svg-compiler.d.ts.map +1 -0
  62. package/src/compilers/svg-compiler.js +123 -0
  63. package/src/compilers/svg-compiler.js.map +1 -0
  64. package/src/compilers/tabs-compiler.d.ts +25 -0
  65. package/src/compilers/tabs-compiler.d.ts.map +1 -0
  66. package/src/compilers/tabs-compiler.js +422 -0
  67. package/src/compilers/tabs-compiler.js.map +1 -0
  68. package/src/compilers/theme-compiler.d.ts +14 -0
  69. package/src/compilers/theme-compiler.d.ts.map +1 -0
  70. package/src/compilers/theme-compiler.js +144 -0
  71. package/src/compilers/theme-compiler.js.map +1 -0
  72. package/src/compilers/translation-compiler.d.ts +17 -0
  73. package/src/compilers/translation-compiler.d.ts.map +1 -0
  74. package/src/compilers/translation-compiler.js +232 -0
  75. package/src/compilers/translation-compiler.js.map +1 -0
  76. package/src/compilers/web-component/index.d.ts +3 -0
  77. package/src/compilers/web-component/index.d.ts.map +1 -0
  78. package/src/compilers/web-component/index.js +6 -0
  79. package/src/compilers/web-component/index.js.map +1 -0
  80. package/src/compilers/web-component/lib/builder.d.ts +45 -0
  81. package/src/compilers/web-component/lib/builder.d.ts.map +1 -0
  82. package/src/compilers/web-component/lib/builder.js +341 -0
  83. package/src/compilers/web-component/lib/builder.js.map +1 -0
  84. package/src/compilers/web-component/lib/class-name.d.ts +4 -0
  85. package/src/compilers/web-component/lib/class-name.d.ts.map +1 -0
  86. package/src/compilers/web-component/lib/class-name.js +24 -0
  87. package/src/compilers/web-component/lib/class-name.js.map +1 -0
  88. package/src/compilers/web-component/lib/config-data.d.ts +9 -0
  89. package/src/compilers/web-component/lib/config-data.d.ts.map +1 -0
  90. package/src/compilers/web-component/lib/config-data.js +14 -0
  91. package/src/compilers/web-component/lib/config-data.js.map +1 -0
  92. package/src/compilers/web-component/lib/ng-build.d.ts +8 -0
  93. package/src/compilers/web-component/lib/ng-build.d.ts.map +1 -0
  94. package/src/compilers/web-component/lib/ng-build.js +685 -0
  95. package/src/compilers/web-component/lib/ng-build.js.map +1 -0
  96. package/src/compilers/web-component/lib/resource-inliner.d.ts +9 -0
  97. package/src/compilers/web-component/lib/resource-inliner.d.ts.map +1 -0
  98. package/src/compilers/web-component/lib/resource-inliner.js +355 -0
  99. package/src/compilers/web-component/lib/resource-inliner.js.map +1 -0
  100. package/src/compilers/web-component/lib/web-component-name.d.ts +3 -0
  101. package/src/compilers/web-component/lib/web-component-name.d.ts.map +1 -0
  102. package/src/compilers/web-component/lib/web-component-name.js +47 -0
  103. package/src/compilers/web-component/lib/web-component-name.js.map +1 -0
  104. package/src/compilers/web-component/lib/web-component-wrapper.d.ts +3 -0
  105. package/src/compilers/web-component/lib/web-component-wrapper.d.ts.map +1 -0
  106. package/src/compilers/web-component/lib/web-component-wrapper.js +335 -0
  107. package/src/compilers/web-component/lib/web-component-wrapper.js.map +1 -0
  108. package/src/compilers/web-component/model/type.d.ts +29 -0
  109. package/src/compilers/web-component/model/type.d.ts.map +1 -0
  110. package/src/compilers/web-component/model/type.js +3 -0
  111. package/src/compilers/web-component/model/type.js.map +1 -0
  112. package/src/compilers/worker-compiler.d.ts +12 -0
  113. package/src/compilers/worker-compiler.d.ts.map +1 -0
  114. package/src/compilers/worker-compiler.js +123 -0
  115. package/src/compilers/worker-compiler.js.map +1 -0
  116. package/src/compilers/yaml-compiler.d.ts +18 -0
  117. package/src/compilers/yaml-compiler.d.ts.map +1 -0
  118. package/src/compilers/yaml-compiler.js +139 -0
  119. package/src/compilers/yaml-compiler.js.map +1 -0
  120. package/src/core/base-compiler.d.ts +17 -0
  121. package/src/core/base-compiler.d.ts.map +1 -0
  122. package/src/core/base-compiler.js +78 -0
  123. package/src/core/base-compiler.js.map +1 -0
  124. package/src/core/config.d.ts +640 -0
  125. package/src/core/config.d.ts.map +1 -0
  126. package/src/core/config.js +432 -0
  127. package/src/core/config.js.map +1 -0
  128. package/src/core/file-watcher.d.ts +23 -0
  129. package/src/core/file-watcher.d.ts.map +1 -0
  130. package/src/core/file-watcher.js +63 -0
  131. package/src/core/file-watcher.js.map +1 -0
  132. package/src/index.d.ts +31 -0
  133. package/src/index.d.ts.map +1 -0
  134. package/src/index.js +34 -0
  135. package/src/index.js.map +1 -0
  136. package/src/types/asset-configs.d.ts +189 -0
  137. package/src/types/asset-configs.d.ts.map +1 -0
  138. package/src/types/asset-configs.js +7 -0
  139. package/src/types/asset-configs.js.map +1 -0
  140. package/src/types/theme.d.ts +67 -0
  141. package/src/types/theme.d.ts.map +1 -0
  142. package/src/types/theme.js +3 -0
  143. package/src/types/theme.js.map +1 -0
  144. package/src/utils/file-utils.d.ts +16 -0
  145. package/src/utils/file-utils.d.ts.map +1 -0
  146. package/src/utils/file-utils.js +58 -0
  147. package/src/utils/file-utils.js.map +1 -0
  148. package/src/utils/i18n-compile-validator.d.ts +20 -0
  149. package/src/utils/i18n-compile-validator.d.ts.map +1 -0
  150. package/src/utils/i18n-compile-validator.js +198 -0
  151. package/src/utils/i18n-compile-validator.js.map +1 -0
  152. package/src/utils/i18n-fixer.d.ts +39 -0
  153. package/src/utils/i18n-fixer.d.ts.map +1 -0
  154. package/src/utils/i18n-fixer.js +396 -0
  155. package/src/utils/i18n-fixer.js.map +1 -0
  156. package/src/utils/i18n-sanitizer.d.ts +17 -0
  157. package/src/utils/i18n-sanitizer.d.ts.map +1 -0
  158. package/src/utils/i18n-sanitizer.js +101 -0
  159. package/src/utils/i18n-sanitizer.js.map +1 -0
  160. package/src/utils/i18n-utils.d.ts +21 -0
  161. package/src/utils/i18n-utils.d.ts.map +1 -0
  162. package/src/utils/i18n-utils.js +89 -0
  163. package/src/utils/i18n-utils.js.map +1 -0
  164. package/src/utils/interactive-translator.d.ts +18 -0
  165. package/src/utils/interactive-translator.d.ts.map +1 -0
  166. package/src/utils/interactive-translator.js +401 -0
  167. package/src/utils/interactive-translator.js.map +1 -0
  168. package/src/utils/llama-cpp-translator.d.ts +33 -0
  169. package/src/utils/llama-cpp-translator.d.ts.map +1 -0
  170. package/src/utils/llama-cpp-translator.js +267 -0
  171. package/src/utils/llama-cpp-translator.js.map +1 -0
  172. package/src/utils/logger.d.ts +14 -0
  173. package/src/utils/logger.d.ts.map +1 -0
  174. package/src/utils/logger.js +42 -0
  175. package/src/utils/logger.js.map +1 -0
  176. package/src/utils/ollama-translator.d.ts +38 -0
  177. package/src/utils/ollama-translator.d.ts.map +1 -0
  178. package/src/utils/ollama-translator.js +371 -0
  179. package/src/utils/ollama-translator.js.map +1 -0
  180. package/src/utils/option-utils.d.ts +58 -0
  181. package/src/utils/option-utils.d.ts.map +1 -0
  182. package/src/utils/option-utils.js +123 -0
  183. package/src/utils/option-utils.js.map +1 -0
  184. package/src/utils/platform-utils.d.ts +33 -0
  185. package/src/utils/platform-utils.d.ts.map +1 -0
  186. package/src/utils/platform-utils.js +114 -0
  187. package/src/utils/platform-utils.js.map +1 -0
  188. package/src/utils/pwa-utils.d.ts +28 -0
  189. package/src/utils/pwa-utils.d.ts.map +1 -0
  190. package/src/utils/pwa-utils.js +48 -0
  191. package/src/utils/pwa-utils.js.map +1 -0
  192. package/src/utils/translation-manager.d.ts +43 -0
  193. package/src/utils/translation-manager.d.ts.map +1 -0
  194. package/src/utils/translation-manager.js +302 -0
  195. package/src/utils/translation-manager.js.map +1 -0
  196. package/src/utils/web-translation-providers.d.ts +53 -0
  197. package/src/utils/web-translation-providers.d.ts.map +1 -0
  198. package/src/utils/web-translation-providers.js +190 -0
  199. package/src/utils/web-translation-providers.js.map +1 -0
  200. package/src/utils/yaml-utils.d.ts +9 -0
  201. package/src/utils/yaml-utils.d.ts.map +1 -0
  202. package/src/utils/yaml-utils.js +26 -0
  203. package/src/utils/yaml-utils.js.map +1 -0
  204. package/templates/mag-compile.config.js +77 -0
@@ -0,0 +1,621 @@
1
+ const { execSync } = require('child_process');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const inquirer = require('inquirer');
5
+
6
+ // Cross-platform directory deletion function
7
+ async function deleteDirectory(dirPath, options = {}) {
8
+ const { verbose } = options;
9
+
10
+ try {
11
+ if (verbose) {
12
+ console.log(` Deleting: ${dirPath}`);
13
+ }
14
+
15
+ // Check if directory exists
16
+ try {
17
+ await fs.promises.access(dirPath);
18
+ } catch {
19
+ // Directory doesn't exist, nothing to delete
20
+ return;
21
+ }
22
+
23
+ // Use fs.rm() for Node.js 14.14+ (cross-platform)
24
+ try {
25
+ await fs.promises.rm(dirPath, { recursive: true, force: true });
26
+ } catch (error) {
27
+ // Fallback to manual recursive deletion for older Node versions
28
+ if (error.code === 'ENOENT') {
29
+ return; // Already deleted
30
+ }
31
+
32
+ // Try alternative approach using execSync with cross-platform command
33
+ const isWindows = process.platform === 'win32';
34
+ const deleteCommand = isWindows
35
+ ? `rmdir /s /q "${dirPath}"`
36
+ : `rm -rf "${dirPath}"`;
37
+
38
+ execSync(deleteCommand, { stdio: verbose ? 'inherit' : 'pipe' });
39
+ }
40
+ } catch (error) {
41
+ if (error.code !== 'ENOENT') {
42
+ throw new Error(
43
+ `Failed to delete directory ${dirPath}: ${error.message}`
44
+ );
45
+ }
46
+ }
47
+ }
48
+
49
+ function cleanCommand(program) {
50
+ program
51
+ .command('clean')
52
+ .description('Clean build artifacts and dependencies')
53
+ .option('--dist-only', 'Clean only dist folders, preserve node_modules')
54
+ .option('--force', 'Skip confirmation prompts')
55
+ .option('-v, --verbose', 'Verbose output')
56
+ .option(
57
+ '--company <name>',
58
+ 'Company name for monorepo lookup (when outside monorepo)'
59
+ )
60
+ .action(async (options) => {
61
+ try {
62
+ const context = await determineCleanContext(options);
63
+
64
+ if (options.distOnly) {
65
+ await handleDistOnlyClean(context, options);
66
+ } else {
67
+ await handleFullClean(context, options);
68
+ }
69
+
70
+ console.log('🎉 Clean completed successfully!');
71
+ } catch (error) {
72
+ console.error(`❌ Clean failed: ${error.message}`);
73
+ process.exit(1);
74
+ }
75
+ });
76
+
77
+ // Add dist-clean command as alias for --dist-only
78
+ program
79
+ .command('dist-clean')
80
+ .description('Clean only dist folders, preserve node_modules')
81
+ .option('--force', 'Skip confirmation prompts')
82
+ .option('-v, --verbose', 'Verbose output')
83
+ .option(
84
+ '--company <name>',
85
+ 'Company name for monorepo lookup (when outside monorepo)'
86
+ )
87
+ .action(async (options) => {
88
+ // Set dist-only flag and call main clean function
89
+ options.distOnly = true;
90
+ try {
91
+ const context = await determineCleanContext(options);
92
+ await handleDistOnlyClean(context, options);
93
+ console.log('🎉 Dist clean completed successfully!');
94
+ } catch (error) {
95
+ console.error(`❌ Dist clean failed: ${error.message}`);
96
+ process.exit(1);
97
+ }
98
+ });
99
+ }
100
+
101
+ async function determineCleanContext(options) {
102
+ const cwd = process.cwd();
103
+ const packageJsonPath = path.join(cwd, 'package.json');
104
+
105
+ // Check if we're in a monorepo app directory
106
+ if (fs.existsSync(packageJsonPath)) {
107
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
108
+
109
+ // Check if we're in an apps/ directory structure (monorepo app)
110
+ const isInAppsDir = cwd.includes('/apps/');
111
+ const isScopedApp = packageJson.name.startsWith('@');
112
+
113
+ if (isInAppsDir) {
114
+ // Try to find monorepo root by going up two levels
115
+ const potentialMonorepoRoot = path.resolve(cwd, '../..');
116
+ const rootPackageJsonPath = path.join(
117
+ potentialMonorepoRoot,
118
+ 'package.json'
119
+ );
120
+
121
+ if (fs.existsSync(rootPackageJsonPath)) {
122
+ const rootPackageJson = JSON.parse(
123
+ fs.readFileSync(rootPackageJsonPath, 'utf-8')
124
+ );
125
+ if (
126
+ rootPackageJson.workspaces &&
127
+ fs.existsSync(path.join(potentialMonorepoRoot, 'apps'))
128
+ ) {
129
+ // This is definitely a monorepo app
130
+ if (isScopedApp) {
131
+ return {
132
+ type: 'monorepo-app',
133
+ appName: packageJson.name.split('/')[1],
134
+ companyName: packageJson.name.split('/')[0].replace('@', ''),
135
+ monorepoRoot: potentialMonorepoRoot,
136
+ currentApp: cwd,
137
+ };
138
+ } else {
139
+ // Non-scoped app in monorepo
140
+ return {
141
+ type: 'monorepo-app',
142
+ appName: packageJson.name,
143
+ companyName:
144
+ rootPackageJson.name.replace('-monorepo', '') || 'company',
145
+ monorepoRoot: potentialMonorepoRoot,
146
+ currentApp: cwd,
147
+ };
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+
154
+ // Check if we're in monorepo root
155
+ const rootPackageJsonPath = path.join(cwd, 'package.json');
156
+ if (fs.existsSync(rootPackageJsonPath)) {
157
+ const rootPackageJson = JSON.parse(
158
+ fs.readFileSync(rootPackageJsonPath, 'utf-8')
159
+ );
160
+ if (rootPackageJson.workspaces && fs.existsSync(path.join(cwd, 'apps'))) {
161
+ return {
162
+ type: 'monorepo-root',
163
+ monorepoRoot: cwd,
164
+ companyName: rootPackageJson.name.replace('-monorepo', ''),
165
+ };
166
+ }
167
+ }
168
+
169
+ // External to monorepo - try to find it
170
+ if (options.company) {
171
+ return await findMonorepoExternal(options.company, cwd);
172
+ }
173
+
174
+ // Standalone app
175
+ return {
176
+ type: 'standalone',
177
+ currentDir: cwd,
178
+ };
179
+ }
180
+
181
+ async function findMonorepoExternal(companyName, currentDir) {
182
+ const possiblePaths = [
183
+ path.join(currentDir, `${companyName}-monorepo`),
184
+ path.join(currentDir, '..', `${companyName}-monorepo`),
185
+ path.join(currentDir, '..', '..', `${companyName}-monorepo`),
186
+ ];
187
+
188
+ for (const possiblePath of possiblePaths) {
189
+ if (
190
+ fs.existsSync(possiblePath) &&
191
+ fs.existsSync(path.join(possiblePath, 'apps'))
192
+ ) {
193
+ return {
194
+ type: 'monorepo-external',
195
+ monorepoRoot: possiblePath,
196
+ companyName: companyName,
197
+ currentDir: currentDir,
198
+ };
199
+ }
200
+ }
201
+
202
+ throw new Error(
203
+ `Monorepo not found for company: ${companyName}. Searched: ${possiblePaths.join(
204
+ ', '
205
+ )}`
206
+ );
207
+ }
208
+
209
+ async function handleDistOnlyClean(context, options) {
210
+ if (!options.force) {
211
+ const confirmation = await inquirer.prompt([
212
+ {
213
+ type: 'confirm',
214
+ name: 'proceed',
215
+ message: '🗑️ This will remove all dist folders. Continue?',
216
+ default: false,
217
+ },
218
+ ]);
219
+
220
+ if (!confirmation.proceed) {
221
+ console.log('❌ Clean cancelled');
222
+ return;
223
+ }
224
+ }
225
+
226
+ console.log('🧹 Cleaning dist folders...');
227
+
228
+ switch (context.type) {
229
+ case 'monorepo-root':
230
+ case 'monorepo-external':
231
+ await cleanMonorepoDistOnly(context, options);
232
+ break;
233
+ case 'monorepo-app':
234
+ await cleanMonorepoAppDistOnly(context, options);
235
+ break;
236
+ case 'standalone':
237
+ await cleanStandaloneDistOnly(context, options);
238
+ break;
239
+ }
240
+ }
241
+
242
+ async function handleFullClean(context, options) {
243
+ if (!options.force) {
244
+ const cleanTargets = getCleanTargets(context);
245
+ const confirmation = await inquirer.prompt([
246
+ {
247
+ type: 'confirm',
248
+ name: 'proceed',
249
+ message: `🗑️ This will remove:\n${cleanTargets
250
+ .map((t) => ` - ${t}`)
251
+ .join('\n')}\n\n Continue?`,
252
+ default: false,
253
+ },
254
+ ]);
255
+
256
+ if (!confirmation.proceed) {
257
+ console.log('❌ Clean cancelled');
258
+ return;
259
+ }
260
+ }
261
+
262
+ console.log('🧹 Performing full clean...');
263
+
264
+ switch (context.type) {
265
+ case 'monorepo-root':
266
+ case 'monorepo-external':
267
+ await cleanMonorepoFull(context, options);
268
+ break;
269
+ case 'monorepo-app':
270
+ await cleanMonorepoAppFull(context, options);
271
+ break;
272
+ case 'standalone':
273
+ await cleanStandaloneFull(context, options);
274
+ break;
275
+ }
276
+ }
277
+
278
+ function getCleanTargets(context) {
279
+ switch (context.type) {
280
+ case 'monorepo-root':
281
+ case 'monorepo-external':
282
+ return [
283
+ 'Root node_modules',
284
+ 'All app node_modules (apps/*/node_modules)',
285
+ 'Shared dist folder',
286
+ 'Build cache files (*.tsbuildinfo)',
287
+ 'App zip files (apps/*/*.zip)',
288
+ ];
289
+ case 'monorepo-app':
290
+ return [
291
+ 'App dist folder (../../dist/app-name)',
292
+ 'App node_modules (if exists)',
293
+ 'App zip files',
294
+ 'Build cache files',
295
+ ];
296
+ case 'standalone':
297
+ return [
298
+ 'Local node_modules',
299
+ 'Local dist folder',
300
+ 'Build cache files',
301
+ 'Zip files',
302
+ ];
303
+ }
304
+ }
305
+
306
+ async function cleanMonorepoDistOnly(context, options) {
307
+ const monorepoRoot = context.monorepoRoot;
308
+
309
+ try {
310
+ // Clean shared dist folder
311
+ const distPath = path.join(monorepoRoot, 'dist');
312
+ if (fs.existsSync(distPath)) {
313
+ console.log(`🗑️ Removing shared dist folder: ${distPath}`);
314
+ await deleteDirectory(distPath, { verbose: options.verbose });
315
+ }
316
+
317
+ // Clean individual app zip files
318
+ const appsPath = path.join(monorepoRoot, 'apps');
319
+ if (fs.existsSync(appsPath)) {
320
+ const apps = fs
321
+ .readdirSync(appsPath)
322
+ .filter((item) => fs.statSync(path.join(appsPath, item)).isDirectory());
323
+
324
+ for (const app of apps) {
325
+ const appPath = path.join(appsPath, app);
326
+ const zipFiles = fs
327
+ .readdirSync(appPath)
328
+ .filter((file) => file.endsWith('.zip'));
329
+
330
+ for (const zipFile of zipFiles) {
331
+ const zipPath = path.join(appPath, zipFile);
332
+ console.log(`🗑️ Removing app zip: ${zipPath}`);
333
+ if (options.verbose) console.log(` rm ${zipPath}`);
334
+ fs.unlinkSync(zipPath);
335
+ }
336
+ }
337
+ }
338
+
339
+ console.log('✅ Monorepo dist cleanup completed');
340
+ } catch (error) {
341
+ throw new Error(`Failed to clean monorepo dist: ${error.message}`);
342
+ }
343
+ }
344
+
345
+ async function cleanMonorepoAppDistOnly(context, options) {
346
+ try {
347
+ // Clean app's dist folder in shared dist
348
+ const appDistPath = path.join(
349
+ context.monorepoRoot,
350
+ 'dist',
351
+ context.appName
352
+ );
353
+ if (fs.existsSync(appDistPath)) {
354
+ console.log(`🗑️ Removing app dist folder: ${appDistPath}`);
355
+ await deleteDirectory(appDistPath, { verbose: options.verbose });
356
+ }
357
+
358
+ // Clean app zip files
359
+ const zipFiles = fs
360
+ .readdirSync(context.currentApp)
361
+ .filter((file) => file.endsWith('.zip'));
362
+ for (const zipFile of zipFiles) {
363
+ const zipPath = path.join(context.currentApp, zipFile);
364
+ console.log(`🗑️ Removing app zip: ${zipPath}`);
365
+ if (options.verbose) console.log(` rm ${zipPath}`);
366
+ fs.unlinkSync(zipPath);
367
+ }
368
+
369
+ console.log('✅ App dist cleanup completed');
370
+ } catch (error) {
371
+ throw new Error(`Failed to clean app dist: ${error.message}`);
372
+ }
373
+ }
374
+
375
+ async function cleanStandaloneDistOnly(context, options) {
376
+ try {
377
+ const distPath = path.join(context.currentDir, 'dist');
378
+ if (fs.existsSync(distPath)) {
379
+ console.log(`🗑️ Removing dist folder: ${distPath}`);
380
+ if (options.verbose) console.log(` rm -rf ${distPath}`);
381
+ execSync(`rm -rf "${distPath}"`, {
382
+ stdio: options.verbose ? 'inherit' : 'pipe',
383
+ });
384
+ }
385
+
386
+ // Clean zip files
387
+ const zipFiles = fs
388
+ .readdirSync(context.currentDir)
389
+ .filter((file) => file.endsWith('.zip'));
390
+ for (const zipFile of zipFiles) {
391
+ const zipPath = path.join(context.currentDir, zipFile);
392
+ console.log(`🗑️ Removing zip: ${zipPath}`);
393
+ if (options.verbose) console.log(` rm ${zipPath}`);
394
+ fs.unlinkSync(zipPath);
395
+ }
396
+
397
+ console.log('✅ Standalone dist cleanup completed');
398
+ } catch (error) {
399
+ throw new Error(`Failed to clean standalone dist: ${error.message}`);
400
+ }
401
+ }
402
+
403
+ async function cleanMonorepoFull(context, options) {
404
+ const monorepoRoot = context.monorepoRoot;
405
+
406
+ try {
407
+ // Clean root node_modules
408
+ const rootNodeModules = path.join(monorepoRoot, 'node_modules');
409
+ if (fs.existsSync(rootNodeModules)) {
410
+ console.log(`🗑️ Removing root node_modules: ${rootNodeModules}`);
411
+ if (options.verbose) console.log(` rm -rf ${rootNodeModules}`);
412
+ execSync(`rm -rf "${rootNodeModules}"`, {
413
+ stdio: options.verbose ? 'inherit' : 'pipe',
414
+ });
415
+ }
416
+
417
+ // Clean all app node_modules and other artifacts
418
+ const appsPath = path.join(monorepoRoot, 'apps');
419
+ if (fs.existsSync(appsPath)) {
420
+ const apps = fs
421
+ .readdirSync(appsPath)
422
+ .filter((item) => fs.statSync(path.join(appsPath, item)).isDirectory());
423
+
424
+ for (const app of apps) {
425
+ const appPath = path.join(appsPath, app);
426
+
427
+ // Clean app node_modules
428
+ const appNodeModules = path.join(appPath, 'node_modules');
429
+ if (fs.existsSync(appNodeModules)) {
430
+ console.log(`🗑️ Removing app node_modules: ${appNodeModules}`);
431
+ if (options.verbose) console.log(` rm -rf ${appNodeModules}`);
432
+ execSync(`rm -rf "${appNodeModules}"`, {
433
+ stdio: options.verbose ? 'inherit' : 'pipe',
434
+ });
435
+ }
436
+
437
+ // Clean app dist if it exists locally (shouldn't with new structure but just in case)
438
+ const appDist = path.join(appPath, 'dist');
439
+ if (fs.existsSync(appDist)) {
440
+ console.log(`🗑️ Removing app local dist: ${appDist}`);
441
+ if (options.verbose) console.log(` rm -rf ${appDist}`);
442
+ execSync(`rm -rf "${appDist}"`, {
443
+ stdio: options.verbose ? 'inherit' : 'pipe',
444
+ });
445
+ }
446
+
447
+ // Clean zip files
448
+ const zipFiles = fs
449
+ .readdirSync(appPath)
450
+ .filter((file) => file.endsWith('.zip'));
451
+ for (const zipFile of zipFiles) {
452
+ const zipPath = path.join(appPath, zipFile);
453
+ console.log(`🗑️ Removing app zip: ${zipPath}`);
454
+ if (options.verbose) console.log(` rm ${zipPath}`);
455
+ fs.unlinkSync(zipPath);
456
+ }
457
+
458
+ // Clean TypeScript build info
459
+ const tsBuildInfo = path.join(appPath, 'tsconfig.tsbuildinfo');
460
+ if (fs.existsSync(tsBuildInfo)) {
461
+ console.log(`🗑️ Removing TypeScript build info: ${tsBuildInfo}`);
462
+ if (options.verbose) console.log(` rm ${tsBuildInfo}`);
463
+ fs.unlinkSync(tsBuildInfo);
464
+ }
465
+ }
466
+ }
467
+
468
+ // Clean shared dist folder
469
+ const distPath = path.join(monorepoRoot, 'dist');
470
+ if (fs.existsSync(distPath)) {
471
+ console.log(`🗑️ Removing shared dist folder: ${distPath}`);
472
+ if (options.verbose) console.log(` rm -rf ${distPath}`);
473
+ execSync(`rm -rf "${distPath}"`, {
474
+ stdio: options.verbose ? 'inherit' : 'pipe',
475
+ });
476
+ }
477
+
478
+ // Clean root build artifacts
479
+ const rootTsBuildInfo = path.join(monorepoRoot, 'tsconfig.tsbuildinfo');
480
+ if (fs.existsSync(rootTsBuildInfo)) {
481
+ console.log(
482
+ `🗑️ Removing root TypeScript build info: ${rootTsBuildInfo}`
483
+ );
484
+ if (options.verbose) console.log(` rm ${rootTsBuildInfo}`);
485
+ fs.unlinkSync(rootTsBuildInfo);
486
+ }
487
+
488
+ console.log('✅ Full monorepo cleanup completed');
489
+ } catch (error) {
490
+ throw new Error(`Failed to clean monorepo: ${error.message}`);
491
+ }
492
+ }
493
+
494
+ async function cleanMonorepoAppFull(context, options) {
495
+ try {
496
+ // When in an app, we can only clean app-specific things
497
+ // The shared resources should be cleaned from monorepo root
498
+
499
+ // Clean app's dist folder in shared dist
500
+ const appDistPath = path.join(
501
+ context.monorepoRoot,
502
+ 'dist',
503
+ context.appName
504
+ );
505
+ if (fs.existsSync(appDistPath)) {
506
+ console.log(`🗑️ Removing app dist folder: ${appDistPath}`);
507
+ if (options.verbose) console.log(` rm -rf ${appDistPath}`);
508
+ execSync(`rm -rf "${appDistPath}"`, {
509
+ stdio: options.verbose ? 'inherit' : 'pipe',
510
+ });
511
+ }
512
+
513
+ // Clean app node_modules if it exists (shouldn't in monorepo but just in case)
514
+ const appNodeModules = path.join(context.currentApp, 'node_modules');
515
+ if (fs.existsSync(appNodeModules)) {
516
+ console.log(`🗑️ Removing app node_modules: ${appNodeModules}`);
517
+ if (options.verbose) console.log(` rm -rf ${appNodeModules}`);
518
+ execSync(`rm -rf "${appNodeModules}"`, {
519
+ stdio: options.verbose ? 'inherit' : 'pipe',
520
+ });
521
+ }
522
+
523
+ // Clean local dist if it exists
524
+ const localDist = path.join(context.currentApp, 'dist');
525
+ if (fs.existsSync(localDist)) {
526
+ console.log(`🗑️ Removing local dist folder: ${localDist}`);
527
+ if (options.verbose) console.log(` rm -rf ${localDist}`);
528
+ execSync(`rm -rf "${localDist}"`, {
529
+ stdio: options.verbose ? 'inherit' : 'pipe',
530
+ });
531
+ }
532
+
533
+ // Clean zip files
534
+ const zipFiles = fs
535
+ .readdirSync(context.currentApp)
536
+ .filter((file) => file.endsWith('.zip'));
537
+ for (const zipFile of zipFiles) {
538
+ const zipPath = path.join(context.currentApp, zipFile);
539
+ console.log(`🗑️ Removing app zip: ${zipPath}`);
540
+ if (options.verbose) console.log(` rm ${zipPath}`);
541
+ fs.unlinkSync(zipPath);
542
+ }
543
+
544
+ // Clean TypeScript build info
545
+ const tsBuildInfo = path.join(context.currentApp, 'tsconfig.tsbuildinfo');
546
+ if (fs.existsSync(tsBuildInfo)) {
547
+ console.log(`🗑️ Removing TypeScript build info: ${tsBuildInfo}`);
548
+ if (options.verbose) console.log(` rm ${tsBuildInfo}`);
549
+ fs.unlinkSync(tsBuildInfo);
550
+ }
551
+
552
+ console.log('✅ App cleanup completed');
553
+ console.log(
554
+ '💡 To clean shared monorepo resources, run from monorepo root'
555
+ );
556
+ } catch (error) {
557
+ throw new Error(`Failed to clean app: ${error.message}`);
558
+ }
559
+ }
560
+
561
+ async function cleanStandaloneFull(context, options) {
562
+ try {
563
+ // Clean node_modules
564
+ const nodeModules = path.join(context.currentDir, 'node_modules');
565
+ if (fs.existsSync(nodeModules)) {
566
+ console.log(`🗑️ Removing node_modules: ${nodeModules}`);
567
+ if (options.verbose) console.log(` rm -rf ${nodeModules}`);
568
+ execSync(`rm -rf "${nodeModules}"`, {
569
+ stdio: options.verbose ? 'inherit' : 'pipe',
570
+ });
571
+ }
572
+
573
+ // Clean dist
574
+ const distPath = path.join(context.currentDir, 'dist');
575
+ if (fs.existsSync(distPath)) {
576
+ console.log(`🗑️ Removing dist folder: ${distPath}`);
577
+ if (options.verbose) console.log(` rm -rf ${distPath}`);
578
+ execSync(`rm -rf "${distPath}"`, {
579
+ stdio: options.verbose ? 'inherit' : 'pipe',
580
+ });
581
+ }
582
+
583
+ // Clean zip files
584
+ const zipFiles = fs
585
+ .readdirSync(context.currentDir)
586
+ .filter((file) => file.endsWith('.zip'));
587
+ for (const zipFile of zipFiles) {
588
+ const zipPath = path.join(context.currentDir, zipFile);
589
+ console.log(`🗑️ Removing zip: ${zipPath}`);
590
+ if (options.verbose) console.log(` rm ${zipPath}`);
591
+ fs.unlinkSync(zipPath);
592
+ }
593
+
594
+ // Clean TypeScript build info
595
+ const tsBuildInfo = path.join(context.currentDir, 'tsconfig.tsbuildinfo');
596
+ if (fs.existsSync(tsBuildInfo)) {
597
+ console.log(`🗑️ Removing TypeScript build info: ${tsBuildInfo}`);
598
+ if (options.verbose) console.log(` rm ${tsBuildInfo}`);
599
+ fs.unlinkSync(tsBuildInfo);
600
+ }
601
+
602
+ // Clean other common build artifacts
603
+ const artifacts = ['coverage', '.nyc_output', '*.log'];
604
+ for (const artifact of artifacts) {
605
+ const artifactPath = path.join(context.currentDir, artifact);
606
+ if (fs.existsSync(artifactPath)) {
607
+ console.log(`🗑️ Removing ${artifact}: ${artifactPath}`);
608
+ if (options.verbose) console.log(` rm -rf ${artifactPath}`);
609
+ execSync(`rm -rf "${artifactPath}"`, {
610
+ stdio: options.verbose ? 'inherit' : 'pipe',
611
+ });
612
+ }
613
+ }
614
+
615
+ console.log('✅ Standalone cleanup completed');
616
+ } catch (error) {
617
+ throw new Error(`Failed to clean standalone: ${error.message}`);
618
+ }
619
+ }
620
+
621
+ module.exports = cleanCommand;
@@ -0,0 +1,91 @@
1
+ const path = require('path');
2
+ const fs = require('fs').promises;
3
+
4
+ function compileI18nCommand(program) {
5
+ program
6
+ .command('compile-i18n')
7
+ .description(
8
+ 'Validate i18n YAML files, auto-fix syntax/duplicates, and compile to JSON.'
9
+ )
10
+ .option('--app <name>', 'Limit to a specific app (e.g., m-comics)', null)
11
+ .option('--config <path>', 'Path to mag-cli.config.js', 'mag-cli.config.js')
12
+ .option('--dry-run', 'Validate and fix without writing files', false)
13
+ .option('-v, --verbose', 'Verbose logging', false)
14
+ .option('--root <path>', 'Workspace root', process.cwd())
15
+ .action(async (options) => {
16
+ const { I18nCompileValidator } = require('../../src/index.js');
17
+ const root = path.resolve(options.root);
18
+ const configPath = path.resolve(root, options.config);
19
+
20
+ let config;
21
+ try {
22
+ config = require(configPath);
23
+ } catch (e) {
24
+ console.error(`Error: Could not load config from ${configPath}: ${e.message}`);
25
+ process.exit(1);
26
+ }
27
+
28
+ const validator = new I18nCompileValidator(options.verbose);
29
+ const logPath = path.join(root, 'i18n-compile-errors.log');
30
+
31
+ const allResults = [];
32
+ let totalScanned = 0;
33
+
34
+ const appPaths = options.app
35
+ ? config.paths.filter(p => p.source.includes(`apps/${options.app}`) || p.source.includes(`libs/${options.app}`))
36
+ : config.paths;
37
+
38
+ if (options.app && appPaths.length === 0) {
39
+ console.error(`Error: App "${options.app}" not found in config.`);
40
+ process.exit(1);
41
+ }
42
+
43
+ for (const p of appPaths) {
44
+ const sourceRoot = path.join(root, p.source, 'i18n');
45
+ const outputRoot = path.join(root, p.output, 'i18n');
46
+
47
+ try {
48
+ await fs.access(sourceRoot);
49
+ } catch {
50
+ if (options.verbose) console.log(`Skipping: ${sourceRoot} (not found)`);
51
+ continue;
52
+ }
53
+
54
+ console.log(`Processing: ${sourceRoot} -> ${outputRoot}`);
55
+ const results = await validator.validateAndCompile(sourceRoot, outputRoot, options.dryRun);
56
+ allResults.push(...results);
57
+ totalScanned += results.length;
58
+ }
59
+
60
+ const fixed = allResults.filter(r => r.fixed).length;
61
+ const failed = allResults.filter(r => r.unfixable);
62
+
63
+ // Write error log
64
+ if (failed.length > 0) {
65
+ const logContent = failed.map(r => {
66
+ const autoFixStr = r.autoFixAttempts.length > 0
67
+ ? `(Auto-fix attempted: ${r.autoFixAttempts.join(', ')})`
68
+ : '(No auto-fix attempted)';
69
+ const errorMsg = String(r.error).replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
70
+ return `${r.file}: ${errorMsg} ${autoFixStr}`;
71
+ }).join('\n');
72
+ await fs.writeFile(logPath, logContent, 'utf-8');
73
+ } else {
74
+ try {
75
+ await fs.unlink(logPath);
76
+ } catch {
77
+ // Ignore if file doesn't exist
78
+ }
79
+ }
80
+
81
+ console.log(`\nDone. Scanned: ${totalScanned}, Auto-fixed: ${fixed}, Failed: ${failed.length}`);
82
+ if (failed.length > 0) {
83
+ console.log(`Errors logged to: ${logPath}`);
84
+ process.exit(1);
85
+ }
86
+
87
+ process.exit(0);
88
+ });
89
+ }
90
+
91
+ module.exports = compileI18nCommand;