@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,249 @@
1
+ const { execSync } = require('child_process');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const YAML = require('yaml');
5
+ const { WebComponentBuilder, buildPwa } = require('../../src/index.js');
6
+
7
+ function extractVersion(yamlContent) {
8
+ const match = yamlContent.match(/^version:\s*(.+)$/m);
9
+ return match ? match[1].trim() : '';
10
+ }
11
+
12
+ function bumpPatchVersion(version) {
13
+ const parts = String(version).split('.');
14
+ const major = parseInt(parts[0], 10) || 0;
15
+ const minor = parseInt(parts[1], 10) || 0;
16
+ const patch = (parseInt(parts[2], 10) || 0) + 1;
17
+ return `${major}.${minor}.${patch}`;
18
+ }
19
+
20
+ function assetsWcCommand(program) {
21
+ program
22
+ .command('assets-wc')
23
+ .description(
24
+ "Compile all assets then copy each WC app's public/assets to dist/apps/{appName}-wc/"
25
+ )
26
+ .option('-c, --config <path>', 'Config file path', './mag-cli.config.js')
27
+ .option('-a, --app <name>', 'Target app name (e.g., m-comics)')
28
+ .option(
29
+ '--version-check',
30
+ 'Skip apps whose version has not changed since last commit',
31
+ false
32
+ )
33
+ .action(async (options) => {
34
+ const configPath = path.resolve(options.config);
35
+
36
+ // ── 1. Load config ──────────────────────────────────────────────────
37
+ let config = {};
38
+ try {
39
+ config = require(configPath);
40
+ } catch {
41
+ /* ignore config load error */
42
+ }
43
+
44
+ const allPaths = Array.isArray(config.paths) ? config.paths : [];
45
+
46
+ // ── 2. Run assets compile (filtered to target app + libs/one) ────────
47
+ const cliScript = process.argv[1];
48
+ let compileConfigPath = configPath;
49
+ let tempConfigPath = null;
50
+
51
+ if (options.app && allPaths.length > 0) {
52
+ const filteredPaths = allPaths.filter(({ source }) => {
53
+ const appDir = path.dirname(source);
54
+ const appName = path.basename(appDir);
55
+ // Always include libs/one assets; include only the target app
56
+ return appName === 'one' || appName === options.app;
57
+ });
58
+
59
+ if (filteredPaths.length > 0) {
60
+ tempConfigPath = path.resolve(`mag-cli.config.wc-${options.app}.tmp.js`);
61
+ const filteredConfig = { ...config, paths: filteredPaths };
62
+ fs.writeFileSync(
63
+ tempConfigPath,
64
+ `module.exports = ${JSON.stringify(filteredConfig, null, 2)};\n`
65
+ );
66
+ compileConfigPath = tempConfigPath;
67
+ }
68
+ }
69
+
70
+ console.log(
71
+ options.app
72
+ ? `šŸ”Ø Compiling assets for ${options.app} + libs/one...\n`
73
+ : 'šŸ”Ø Compiling all assets...\n'
74
+ );
75
+ try {
76
+ execSync(`node "${cliScript}" assets --config "${compileConfigPath}"`, {
77
+ stdio: 'inherit',
78
+ });
79
+ } catch {
80
+ if (tempConfigPath && fs.existsSync(tempConfigPath)) fs.unlinkSync(tempConfigPath);
81
+ console.error('\nāŒ Asset compilation failed — see errors above.');
82
+ process.exit(1);
83
+ }
84
+
85
+ if (tempConfigPath && fs.existsSync(tempConfigPath)) fs.unlinkSync(tempConfigPath);
86
+
87
+ // ── 3. Reload config and find WC-enabled apps ─────────────────────────
88
+ try {
89
+ // Clear require cache so we get fresh config after compile
90
+ delete require.cache[configPath];
91
+ config = require(configPath);
92
+ } catch {
93
+ /* ignore config load error */
94
+ }
95
+
96
+ const paths = Array.isArray(config.paths) ? config.paths : [];
97
+ const results = []; // { appName, status: 'ok'|'skipped'|'failed', error? }
98
+
99
+ console.log('\nšŸ“¦ Checking for WC-enabled apps...');
100
+
101
+ for (const { source, output } of paths) {
102
+ const remoteDir = path.join(source, 'remote');
103
+ if (!fs.existsSync(remoteDir)) continue;
104
+
105
+ // Derive appName: apps/m-comics/mag_assets → m-comics
106
+ const appDir = path.dirname(source);
107
+ const appName = path.basename(appDir);
108
+
109
+ if (options.app && options.app !== appName) continue;
110
+
111
+ const expectedYml = `${appName}.yml`;
112
+ const remoteFiles = fs.readdirSync(remoteDir);
113
+ if (!remoteFiles.includes(expectedYml)) continue;
114
+
115
+ try {
116
+ if (!process.env.CI) {
117
+ const yamlFile = path.join(remoteDir, expectedYml);
118
+ const content = fs.readFileSync(yamlFile, 'utf8');
119
+ const currVersion = extractVersion(content);
120
+ const newVersion = bumpPatchVersion(currVersion);
121
+ fs.writeFileSync(
122
+ yamlFile,
123
+ content.replace(/^(version:\s*)(.+)$/m, `$1${newVersion}`),
124
+ 'utf8'
125
+ );
126
+ console.log(
127
+ `\n šŸ“ ${appName}: version bumped ${currVersion} → ${newVersion}`
128
+ );
129
+ }
130
+
131
+ if (options.versionCheck) {
132
+ const yamlFile = path.join(remoteDir, expectedYml);
133
+ const currVersion = extractVersion(
134
+ fs.readFileSync(yamlFile, 'utf8')
135
+ );
136
+ let prevVersion = '';
137
+ try {
138
+ const relPath = path
139
+ .relative(process.cwd(), yamlFile)
140
+ .replace(/\\/g, '/');
141
+ const out = execSync(`git show HEAD~1:${relPath}`, {
142
+ encoding: 'utf8',
143
+ stdio: ['pipe', 'pipe', 'pipe'],
144
+ });
145
+ prevVersion = extractVersion(out);
146
+ } catch {
147
+ /* first commit or new file — treat as changed */
148
+ }
149
+ if (currVersion === prevVersion) {
150
+ console.log(
151
+ `\n ā­ļø ${appName}: version unchanged (${currVersion}), skipping`
152
+ );
153
+ results.push({ appName, status: 'skipped' });
154
+ continue;
155
+ }
156
+ console.log(
157
+ `\n šŸ†• ${appName}: version ${prevVersion || 'new'} → ${currVersion}`
158
+ );
159
+ }
160
+
161
+ // Destination: dist/apps/m-comics-wc (for CI/CD bundle)
162
+ const distDestDir = path.join('dist', 'apps', `${appName}-wc`);
163
+
164
+ console.log(`\n ${appName}`);
165
+ console.log(` source : ${output}`);
166
+ console.log(` dist : ${distDestDir}`);
167
+
168
+ if (!fs.existsSync(output)) {
169
+ throw new Error(
170
+ `assets source dir not found: ${output} — run assets:compile first`
171
+ );
172
+ }
173
+
174
+ // Clean and recreate dist destination
175
+ if (fs.existsSync(distDestDir))
176
+ fs.rmSync(distDestDir, { recursive: true, force: true });
177
+ fs.mkdirSync(distDestDir, { recursive: true });
178
+
179
+ copyDirSync(output, distDestDir);
180
+ console.log(` āœ… assets copied to ${distDestDir}`);
181
+
182
+ // ── WC JS bundle ─────────────────────────────────────────────────
183
+ const remoteDistDir = path.join(distDestDir, 'remote');
184
+ console.log(` šŸ”§ Building WC JS bundle...`);
185
+ await new WebComponentBuilder(remoteDir, remoteDistDir).compile();
186
+ console.log(` āœ… WC bundle → ${remoteDistDir}`);
187
+
188
+ // ── PWA build (if pwa: key present in YAML) ─────────────────────
189
+ const yamlFilePath = path.join(remoteDir, expectedYml);
190
+ const yamlContent = fs.readFileSync(yamlFilePath, 'utf8');
191
+ const appConfig = YAML.parse(yamlContent);
192
+ if (appConfig.pwa) {
193
+ await buildPwa(appName, appConfig);
194
+ }
195
+
196
+ results.push({ appName, status: 'ok' });
197
+ } catch (err) {
198
+ console.error(` āŒ ${appName}: failed — ${err.message}`);
199
+ results.push({ appName, status: 'failed', error: err.message });
200
+ }
201
+ }
202
+
203
+ // ── Summary ────────────────────────────────────────────────────────
204
+ const built = results.filter((r) => r.status === 'ok');
205
+ const skipped = results.filter((r) => r.status === 'skipped');
206
+ const failed = results.filter((r) => r.status === 'failed');
207
+
208
+ console.log('\n──────────────────────────────────────');
209
+ if (results.length === 0) {
210
+ console.log(' ā„¹ļø No WC-enabled apps found.');
211
+ } else {
212
+ for (const r of results) {
213
+ if (r.status === 'ok') console.log(` āœ… ${r.appName}`);
214
+ else if (r.status === 'skipped')
215
+ console.log(` ā­ļø ${r.appName} (skipped — version unchanged)`);
216
+ else console.log(` āŒ ${r.appName} — ${r.error}`);
217
+ }
218
+ console.log('──────────────────────────────────────');
219
+ const parts = [];
220
+ if (built.length) parts.push(`${built.length} built`);
221
+ if (skipped.length) parts.push(`${skipped.length} skipped`);
222
+ if (failed.length) parts.push(`${failed.length} failed`);
223
+ console.log(
224
+ failed.length
225
+ ? `\nāš ļø Done with errors: ${parts.join(', ')}`
226
+ : `\nšŸŽ‰ Done: ${parts.join(', ')}`
227
+ );
228
+ }
229
+
230
+ if (failed.length > 0) process.exit(1);
231
+ });
232
+ }
233
+
234
+ function copyDirSync(src, dest) {
235
+ if (!fs.existsSync(src)) return;
236
+ const entries = fs.readdirSync(src, { withFileTypes: true });
237
+ for (const entry of entries) {
238
+ const srcPath = path.join(src, entry.name);
239
+ const destPath = path.join(dest, entry.name);
240
+ if (entry.isDirectory()) {
241
+ fs.mkdirSync(destPath, { recursive: true });
242
+ copyDirSync(srcPath, destPath);
243
+ } else {
244
+ fs.copyFileSync(srcPath, destPath);
245
+ }
246
+ }
247
+ }
248
+
249
+ module.exports = assetsWcCommand;