@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,946 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+
6
+ module.exports = function createAppCommand(program) {
7
+ program
8
+ .command('create-app')
9
+ .description('Scaffold a new Magmonium app in the Nx monorepo')
10
+ .requiredOption('--name <name>', 'App name (e.g. wallet)')
11
+ .option('--platform <platform>', 'Target platform: nx', 'nx')
12
+ .option('--magmonium <value>', 'Add m- prefix to app name: yes|no', 'yes')
13
+ .action(run);
14
+ };
15
+
16
+ function run(options) {
17
+ const { name, platform, magmonium } = options;
18
+
19
+ if (platform !== 'nx') {
20
+ console.error(`Unsupported platform: ${platform}. Only "nx" is supported.`);
21
+ process.exit(1);
22
+ }
23
+
24
+ const withPrefix = magmonium !== 'no';
25
+ const appName = withPrefix ? `m-${name}` : name;
26
+ const rootPath = findMonorepoRoot();
27
+
28
+ if (!rootPath) {
29
+ console.error(
30
+ 'Could not find monorepo root (needs package.json + apps/ dir).'
31
+ );
32
+ process.exit(1);
33
+ }
34
+
35
+ const appDir = path.join(rootPath, 'apps', appName);
36
+ if (fs.existsSync(appDir)) {
37
+ console.error(`Already exists: apps/${appName}`);
38
+ process.exit(1);
39
+ }
40
+
41
+ const port = detectNextPort(rootPath);
42
+ const ctx = buildContext({ name, appName, port });
43
+
44
+ console.log(`\n🚀 Creating Magmonium app: ${appName} (port ${port})\n`);
45
+
46
+ generateAppFiles(ctx, rootPath);
47
+ updateMagCliConfig(ctx, rootPath);
48
+ updateTsConfigBase(ctx, rootPath);
49
+ updatePackageJsonScripts(ctx, rootPath);
50
+
51
+ console.log(`\n✅ ${appName} created at apps/${appName}/`);
52
+ console.log(`\nNext steps:`);
53
+ console.log(` npm run assets:compile`);
54
+ console.log(` npx nx serve ${appName}`);
55
+ }
56
+
57
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
58
+
59
+ function findMonorepoRoot() {
60
+ let dir = process.cwd();
61
+ while (dir !== path.dirname(dir)) {
62
+ if (
63
+ fs.existsSync(path.join(dir, 'package.json')) &&
64
+ fs.existsSync(path.join(dir, 'apps'))
65
+ ) {
66
+ return dir;
67
+ }
68
+ dir = path.dirname(dir);
69
+ }
70
+ return null;
71
+ }
72
+
73
+ function detectNextPort(rootPath) {
74
+ const appsDir = path.join(rootPath, 'apps');
75
+ const usedPorts = new Set();
76
+ for (const entry of fs.readdirSync(appsDir)) {
77
+ const projectJson = path.join(appsDir, entry, 'project.json');
78
+ if (!fs.existsSync(projectJson)) continue;
79
+ try {
80
+ const raw = JSON.parse(fs.readFileSync(projectJson, 'utf8'));
81
+ const port = raw?.targets?.serve?.options?.port;
82
+ if (typeof port === 'number') usedPorts.add(port);
83
+ } catch {
84
+ // ignore parse errors
85
+ }
86
+ }
87
+ let port = 4200;
88
+ while (usedPorts.has(port)) port++;
89
+ return port;
90
+ }
91
+
92
+ function pascal(str) {
93
+ return str
94
+ .split(/[-_]/)
95
+ .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
96
+ .join('');
97
+ }
98
+
99
+ function camel(str) {
100
+ const p = pascal(str);
101
+ return p.charAt(0).toLowerCase() + p.slice(1);
102
+ }
103
+
104
+ function buildContext({ name, appName, port }) {
105
+ const className = `${pascal(name)}WebComponent`;
106
+ const camelName = camel(name);
107
+ const firstLetter = name.charAt(0).toLowerCase();
108
+ const selector = `m${firstLetter}-${name}-wc`;
109
+ const entrySelector = `app-m${name}-entry`;
110
+ const cssClass = `${name}-main`;
111
+ const providersVar = `${camelName}Providers`;
112
+ const pathAlias = `m${name}/Routes`; // e.g. mwallet/Routes
113
+
114
+ return {
115
+ name,
116
+ appName,
117
+ port,
118
+ className,
119
+ camelName,
120
+ firstLetter,
121
+ selector,
122
+ entrySelector,
123
+ cssClass,
124
+ providersVar,
125
+ pathAlias,
126
+ };
127
+ }
128
+
129
+ // ─── File generation ──────────────────────────────────────────────────────────
130
+
131
+ function writeFile(filePath, content) {
132
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
133
+ fs.writeFileSync(filePath, content, 'utf8');
134
+ console.log(` create ${path.relative(process.cwd(), filePath)}`);
135
+ }
136
+
137
+ function generateAppFiles(ctx, rootPath) {
138
+ const base = path.join(rootPath, 'apps', ctx.appName);
139
+ const {
140
+ appName,
141
+ port,
142
+ className,
143
+ selector,
144
+ entrySelector,
145
+ cssClass,
146
+ providersVar,
147
+ } = ctx;
148
+
149
+ // mag_assets
150
+ writeFile(
151
+ path.join(base, 'mag_assets', 'remote', `${appName}.yml`),
152
+ remoteYml(appName, className, selector)
153
+ );
154
+ writeFile(
155
+ path.join(base, 'mag_assets', 'theme', 'default.ts'),
156
+ defaultThemeTs()
157
+ );
158
+ writeFile(path.join(base, 'mag_assets', 'theme', 'light.ts'), lightThemeTs());
159
+
160
+ // mag_assets_env
161
+ const remoteYmlContent = remoteYml(appName, className, selector);
162
+ writeFile(
163
+ path.join(base, 'mag_assets_env', 'dev', 'remote', `${appName}.yml`),
164
+ remoteYmlContent
165
+ );
166
+ writeFile(
167
+ path.join(base, 'mag_assets_env', 'prod', 'remote', `${appName}.yml`),
168
+ remoteYmlContent
169
+ );
170
+
171
+ // public/assets dirs (compiled outputs land here)
172
+ for (const dir of ['i18n', 'remote', 'theme', 'workers']) {
173
+ fs.mkdirSync(path.join(base, 'public', 'assets', dir), { recursive: true });
174
+ }
175
+
176
+ // environments
177
+ const envTs = `export const environment = {\n production: false,\n url: 'http://localhost:8000',\n};\n`;
178
+ writeFile(path.join(base, 'src', 'environments', 'environment.ts'), envTs);
179
+ writeFile(
180
+ path.join(base, 'src', 'environments', 'environment.dev.ts'),
181
+ envTs
182
+ );
183
+
184
+ // remote-entry
185
+ writeFile(
186
+ path.join(base, 'src', 'app', 'remote-entry', 'nx-welcome.ts'),
187
+ nxWelcomeTs(appName)
188
+ );
189
+ writeFile(
190
+ path.join(base, 'src', 'app', 'remote-entry', 'entry.ts'),
191
+ entryTs(entrySelector)
192
+ );
193
+ writeFile(
194
+ path.join(base, 'src', 'app', 'remote-entry', 'entry.routes.ts'),
195
+ `import { Route } from '@angular/router';\nimport { RemoteEntry } from './entry';\n\nexport const remoteRoutes: Route[] = [{ path: '', component: RemoteEntry }];\n`
196
+ );
197
+
198
+ // app files
199
+ writeFile(path.join(base, 'src', 'app', 'app.config.ts'), appConfigTs());
200
+ writeFile(path.join(base, 'src', 'app', 'app.routes.ts'), appRoutesTs());
201
+ writeFile(
202
+ path.join(base, 'src', 'app', 'providers.ts'),
203
+ providersTs(providersVar)
204
+ );
205
+ writeFile(path.join(base, 'src', 'app', 'wc.routes.ts'), wcRoutesTs());
206
+ writeFile(
207
+ path.join(base, 'src', 'app', 'wc.config.ts'),
208
+ wcConfigTs(providersVar)
209
+ );
210
+ writeFile(
211
+ path.join(base, 'src', 'app', 'wc.ts'),
212
+ wcTs(className, selector, cssClass)
213
+ );
214
+ writeFile(
215
+ path.join(base, 'src', 'app', 'wc.sass'),
216
+ `.${cssClass}\n padding: 20px\n`
217
+ );
218
+
219
+ // src root
220
+ writeFile(
221
+ path.join(base, 'src', 'main.ts'),
222
+ `import('./bootstrap').catch((err) => console.error(err));\n`
223
+ );
224
+ writeFile(
225
+ path.join(base, 'src', 'bootstrap.ts'),
226
+ bootstrapTs(appName, className, providersVar)
227
+ );
228
+ writeFile(path.join(base, 'src', 'styles.sass'), stylesSass(selector));
229
+ writeFile(path.join(base, 'src', 'test-setup.ts'), testSetupTs());
230
+ writeFile(path.join(base, 'src', 'index.html'), indexHtml(appName));
231
+
232
+ // webpack / module federation
233
+ writeFile(path.join(base, 'webpack.config.ts'), webpackConfigTs());
234
+ writeFile(path.join(base, 'webpack.prod.config.ts'), webpackProdConfigTs());
235
+ writeFile(
236
+ path.join(base, 'module-federation.config.ts'),
237
+ moduleFederationConfigTs(appName)
238
+ );
239
+ writeFile(path.join(base, 'build-wc.ts'), buildWcTs(appName, className));
240
+
241
+ // project configs
242
+ writeFile(path.join(base, 'project.json'), projectJson(appName, port));
243
+ writeFile(path.join(base, 'tsconfig.json'), tsconfigJson());
244
+ writeFile(path.join(base, 'tsconfig.app.json'), tsconfigAppJson());
245
+ writeFile(path.join(base, 'tsconfig.spec.json'), tsconfigSpecJson());
246
+ writeFile(path.join(base, 'eslint.config.mjs'), eslintConfigMjs());
247
+ writeFile(path.join(base, 'jest.config.cts'), jestConfigCts(appName));
248
+ }
249
+
250
+ // ─── Templates ────────────────────────────────────────────────────────────────
251
+
252
+ function remoteYml(appName, className, selector) {
253
+ return [
254
+ `app: ${appName}`,
255
+ `version: 0.0.1`,
256
+ `componentPath: apps/${appName}/src/app`,
257
+ `componentName: wc`,
258
+ `className: ${className}`,
259
+ `appConfigPath: apps/${appName}/src/app/wc.config`,
260
+ `selector: ${selector}`,
261
+ '',
262
+ ].join('\n');
263
+ }
264
+
265
+ function defaultThemeTs() {
266
+ return `import { Theme } from '@magmonium/cli';
267
+
268
+ export const theme: Theme = {
269
+ name: 'default',
270
+ icon: 'hero',
271
+ mode: 'normal',
272
+ color: {
273
+ background: '#FEF6E4',
274
+ border: '#CC7700',
275
+ frame: '#FEF6E4',
276
+ backgroundLite: '#FFF8CC',
277
+ text: '#1A0A00',
278
+ textSecondary: '#CC7700',
279
+ inverseText: '#ffffff',
280
+ mm: '#FF9933',
281
+ mmLite: '#FFD199',
282
+ mmDark: '#CC7700',
283
+ header: '#1A0A00',
284
+ error: '#CC2200',
285
+ warning: '#F0A500',
286
+ success: '#6da82f',
287
+ page: '#FEF6E4',
288
+ saffron: '#FF9933',
289
+ ink: '#1A0A00',
290
+ red: '#CC2200',
291
+ parchment: '#FFF8CC',
292
+ cream: '#FEF6E4',
293
+ gold: '#F0A500',
294
+ },
295
+ };
296
+ `;
297
+ }
298
+
299
+ function lightThemeTs() {
300
+ return `import { Theme } from '@magmonium/cli';
301
+
302
+ export const theme: Theme = {
303
+ name: 'light',
304
+ icon: 'sun',
305
+ mode: 'light',
306
+ color: {
307
+ background: '#FFFFFF',
308
+ border: '#E6E6E6',
309
+ frame: '#F9F9F9',
310
+ backgroundLite: '#F5F5F5',
311
+ text: '#1A0A00',
312
+ textSecondary: '#656d76',
313
+ inverseText: '#ffffff',
314
+ mm: '#FF9933',
315
+ mmLite: '#FFB870',
316
+ mmDark: '#E67E00',
317
+ header: '#FFFFFF',
318
+ error: '#CC2200',
319
+ warning: '#F0A500',
320
+ success: '#6da82f',
321
+ page: '#FFFFFF',
322
+ saffron: '#FF9933',
323
+ ink: '#1A0A00',
324
+ red: '#CC2200',
325
+ parchment: '#F5F5F5',
326
+ cream: '#FFFFFF',
327
+ gold: '#F0A500',
328
+ },
329
+ };
330
+ `;
331
+ }
332
+
333
+ function nxWelcomeTs(appName) {
334
+ return `import { Component, ViewEncapsulation } from '@angular/core';
335
+ import { CommonModule } from '@angular/common';
336
+
337
+ @Component({
338
+ selector: 'app-nx-welcome',
339
+ imports: [CommonModule],
340
+ template: \`
341
+ <div class="wrapper">
342
+ <h1>Welcome to ${appName}!</h1>
343
+ </div>
344
+ \`,
345
+ styles: [],
346
+ encapsulation: ViewEncapsulation.None,
347
+ })
348
+ export class NxWelcome {}
349
+ `;
350
+ }
351
+
352
+ function entryTs(entrySelector) {
353
+ return `import { Component } from '@angular/core';
354
+ import { NxWelcome } from './nx-welcome';
355
+
356
+ @Component({
357
+ imports: [NxWelcome],
358
+ selector: '${entrySelector}',
359
+ template: \`<app-nx-welcome></app-nx-welcome>\`,
360
+ })
361
+ export class RemoteEntry {}
362
+ `;
363
+ }
364
+
365
+ function appConfigTs() {
366
+ return `import {
367
+ ApplicationConfig,
368
+ provideBrowserGlobalErrorListeners,
369
+ } from '@angular/core';
370
+ import { provideRouter } from '@angular/router';
371
+ import { appRoutes } from './app.routes';
372
+
373
+ export const appConfig: ApplicationConfig = {
374
+ providers: [provideBrowserGlobalErrorListeners(), provideRouter(appRoutes)],
375
+ };
376
+ `;
377
+ }
378
+
379
+ function appRoutesTs() {
380
+ return `import { Route } from '@angular/router';
381
+
382
+ export const appRoutes: Route[] = [
383
+ {
384
+ path: '',
385
+ loadChildren: () =>
386
+ import('./remote-entry/entry.routes').then((m) => m.remoteRoutes),
387
+ },
388
+ ];
389
+ `;
390
+ }
391
+
392
+ function providersTs(providersVar) {
393
+ return `import { ApplicationConfig } from '@angular/core';
394
+
395
+ export const ${providersVar}: ApplicationConfig['providers'] = [];
396
+ `;
397
+ }
398
+
399
+ function wcRoutesTs() {
400
+ return `import { Route } from '@angular/router';
401
+
402
+ export const wcRoutes: Route[] = [
403
+ {
404
+ path: '',
405
+ loadComponent: () =>
406
+ import('./remote-entry/nx-welcome').then((m) => m.NxWelcome),
407
+ },
408
+ ];
409
+ `;
410
+ }
411
+
412
+ function wcConfigTs(providersVar) {
413
+ return `import { ApplicationConfig } from '@angular/core';
414
+ import { provideMagWcConfig, provideMagWcRoutes, RouteContainer } from '@magmonium/one';
415
+ import { wcRoutes } from './wc.routes';
416
+ import { environment } from '../environments/environment';
417
+ import { ${providersVar} } from './providers';
418
+
419
+ export const appConfig: ApplicationConfig = provideMagWcConfig({
420
+ backend: environment.url,
421
+ routes: provideMagWcRoutes({
422
+ component: RouteContainer,
423
+ children: wcRoutes,
424
+ }),
425
+ providers: ${providersVar},
426
+ });
427
+ `;
428
+ }
429
+
430
+ function wcTs(className, selector, cssClass) {
431
+ return `import { Component, OnInit } from '@angular/core';
432
+ import { RouterOutlet } from '@angular/router';
433
+ import { BaseRootWebComponent } from '@magmonium/one';
434
+ import { CommonModule } from '@angular/common';
435
+
436
+ @Component({
437
+ selector: '${selector}',
438
+ imports: [CommonModule, RouterOutlet],
439
+ template: \`
440
+ <main class="${cssClass}">
441
+ <router-outlet></router-outlet>
442
+ </main>
443
+ \`,
444
+ styleUrl: './wc.sass',
445
+ })
446
+ export class ${className} extends BaseRootWebComponent implements OnInit {
447
+ ngOnInit() {
448
+ console.log('✔ ${className} ngOnInit');
449
+ }
450
+ }
451
+ `;
452
+ }
453
+
454
+ function bootstrapTs(appName, className, providersVar) {
455
+ return `import '@angular/compiler';
456
+ import { bootstrapMagApp } from '@magmonium/one';
457
+ import { wcRoutes } from './app/wc.routes';
458
+ import { environment } from './environments/environment';
459
+ import { ${providersVar} } from './app/providers';
460
+ import { ${className} } from './app/wc';
461
+
462
+ console.log('🚀 ${appName} bootstrapping...');
463
+ bootstrapMagApp({
464
+ backend: environment.url,
465
+ root: ${className},
466
+ children: wcRoutes,
467
+ providers: ${providersVar},
468
+ });
469
+ `;
470
+ }
471
+
472
+ function stylesSass(selector) {
473
+ return `@use 'index' as m
474
+ @use 'reset'
475
+
476
+ *
477
+ box-sizing: border-box
478
+
479
+ body
480
+ background: m.$background
481
+ color: m.$text
482
+ font-family: 'Outfit', 'Inter', sans-serif
483
+ margin: 0
484
+ padding: 0
485
+
486
+ p, h1, h2, h3, h4, h5, h6
487
+ font-family: inherit
488
+
489
+ m-one-root, m-frame, ${selector}, m-carousel, m-one-carousel
490
+ display: block
491
+ `;
492
+ }
493
+
494
+ function testSetupTs() {
495
+ return `import { setupZonelessTestEnv } from 'jest-preset-angular/setup-env/zoneless';
496
+
497
+ setupZonelessTestEnv({
498
+ errorOnUnknownElements: true,
499
+ errorOnUnknownProperties: true,
500
+ });
501
+ `;
502
+ }
503
+
504
+ function indexHtml(appName) {
505
+ return `<!doctype html>
506
+ <html lang="en">
507
+ <head>
508
+ <meta charset="utf-8" />
509
+ <title>${appName}</title>
510
+ <base href="/" />
511
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
512
+ <link rel="icon" type="image/x-icon" href="favicon.ico" />
513
+ <link rel="preconnect" href="https://fonts.googleapis.com">
514
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
515
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet">
516
+ </head>
517
+ <body>
518
+ <m-one-root></m-one-root>
519
+ </body>
520
+ </html>
521
+ `;
522
+ }
523
+
524
+ function webpackConfigTs() {
525
+ return `import { withModuleFederation } from '@nx/module-federation/angular';
526
+ import config from './module-federation.config';
527
+
528
+ export default withModuleFederation(config, { dts: false });
529
+ `;
530
+ }
531
+
532
+ function webpackProdConfigTs() {
533
+ return `import { withModuleFederation } from '@nx/module-federation/angular';
534
+ import config from './module-federation.config';
535
+
536
+ export default withModuleFederation(
537
+ {
538
+ ...config,
539
+ /*
540
+ * Remote overrides for production.
541
+ * remotes: [
542
+ * ['app1', 'https://app1.example.com'],
543
+ * ]
544
+ */
545
+ },
546
+ { dts: false }
547
+ );
548
+ `;
549
+ }
550
+
551
+ function moduleFederationConfigTs(appName) {
552
+ return `import { ModuleFederationConfig } from '@nx/module-federation';
553
+
554
+ const config: ModuleFederationConfig = {
555
+ name: '${appName}',
556
+ remotes: [],
557
+ exposes: {
558
+ './App': 'apps/${appName}/src/bootstrap.ts',
559
+ },
560
+ shared: () => false,
561
+ };
562
+
563
+ export default config;
564
+ `;
565
+ }
566
+
567
+ function buildWcTs(appName) {
568
+ return `import { WebComponentBuilder } from '@magmonium/cli';
569
+
570
+ const src = process.argv[2] ?? 'apps/${appName}/mag_assets/remote';
571
+ const dest = process.argv[3] ?? 'dist/apps/${appName}-wc';
572
+
573
+ new WebComponentBuilder(src, dest)
574
+ .compile()
575
+ .then(() => console.log('✔ ${appName} web component built'))
576
+ .catch(err => { console.error(err); process.exit(1); });
577
+ `;
578
+ }
579
+
580
+ function projectJson(appName, port) {
581
+ return (
582
+ JSON.stringify(
583
+ {
584
+ name: appName,
585
+ $schema: '../../node_modules/nx/schemas/project-schema.json',
586
+ projectType: 'application',
587
+ prefix: 'mc',
588
+ sourceRoot: `apps/${appName}/src`,
589
+ tags: [],
590
+ targets: {
591
+ build: {
592
+ executor: '@nx/angular:webpack-browser',
593
+ outputs: ['{options.outputPath}'],
594
+ options: {
595
+ outputPath: `dist/apps/${appName}`,
596
+ index: `apps/${appName}/src/index.html`,
597
+ main: `apps/${appName}/src/main.ts`,
598
+ tsConfig: `apps/${appName}/tsconfig.app.json`,
599
+ inlineStyleLanguage: 'sass',
600
+ assets: [
601
+ { glob: '**/*', input: `apps/${appName}/public` },
602
+ {
603
+ glob: '**/*',
604
+ input: `apps/${appName}/public/assets`,
605
+ output: 'assets',
606
+ },
607
+ {
608
+ glob: '**/*',
609
+ input: 'libs/one/assets',
610
+ output: 'assets/one',
611
+ },
612
+ ],
613
+ styles: [`apps/${appName}/src/styles.sass`],
614
+ scripts: [],
615
+ customWebpackConfig: {
616
+ path: `apps/${appName}/webpack.config.ts`,
617
+ },
618
+ stylePreprocessorOptions: {
619
+ includePaths: ['libs/one/src/lib/shared/sass', '.'],
620
+ },
621
+ },
622
+ configurations: {
623
+ production: {
624
+ budgets: [
625
+ {
626
+ type: 'initial',
627
+ maximumWarning: '1mb',
628
+ maximumError: '2mb',
629
+ },
630
+ {
631
+ type: 'anyComponentStyle',
632
+ maximumWarning: '25kb',
633
+ maximumError: '40kb',
634
+ },
635
+ ],
636
+ outputHashing: 'all',
637
+ },
638
+ development: {
639
+ buildOptimizer: false,
640
+ optimization: false,
641
+ vendorChunk: true,
642
+ extractLicenses: false,
643
+ sourceMap: true,
644
+ namedChunks: true,
645
+ },
646
+ dev: {
647
+ fileReplacements: [
648
+ {
649
+ replace: `apps/${appName}/src/environments/environment.ts`,
650
+ with: `apps/${appName}/src/environments/environment.dev.ts`,
651
+ },
652
+ ],
653
+ outputHashing: 'all',
654
+ },
655
+ },
656
+ defaultConfiguration: 'production',
657
+ },
658
+ serve: {
659
+ executor: '@angular-devkit/build-angular:dev-server',
660
+ configurations: {
661
+ production: { buildTarget: `${appName}:build:production` },
662
+ development: { buildTarget: `${appName}:build:development` },
663
+ },
664
+ defaultConfiguration: 'development',
665
+ options: { port },
666
+ dependsOn: ['cli:build', 'sass:build', 'one:build'],
667
+ },
668
+ 'extract-i18n': {
669
+ executor: '@angular-devkit/build-angular:extract-i18n',
670
+ options: { buildTarget: `${appName}:build` },
671
+ },
672
+ lint: { executor: '@nx/eslint:lint' },
673
+ test: {
674
+ executor: '@nx/jest:jest',
675
+ outputs: ['{workspaceRoot}/coverage/{projectRoot}'],
676
+ options: {
677
+ jestConfig: `apps/${appName}/jest.config.cts`,
678
+ tsConfig: `apps/${appName}/tsconfig.spec.json`,
679
+ },
680
+ },
681
+ 'serve-static': {
682
+ continuous: true,
683
+ executor: '@nx/web:file-server',
684
+ options: { buildTarget: `${appName}:build`, port, spa: true },
685
+ },
686
+ 'build:wc': {
687
+ executor: 'nx:run-commands',
688
+ options: { command: `npx tsx apps/${appName}/build-wc.ts` },
689
+ dependsOn: ['cli:build', 'sass:build', 'one:build'],
690
+ },
691
+ },
692
+ },
693
+ null,
694
+ 2
695
+ ) + '\n'
696
+ );
697
+ }
698
+
699
+ function tsconfigJson() {
700
+ return (
701
+ JSON.stringify(
702
+ {
703
+ extends: '../../tsconfig.base.json',
704
+ compilerOptions: {
705
+ strict: true,
706
+ noImplicitOverride: true,
707
+ noPropertyAccessFromIndexSignature: true,
708
+ noImplicitReturns: true,
709
+ noFallthroughCasesInSwitch: true,
710
+ isolatedModules: true,
711
+ target: 'es2022',
712
+ moduleResolution: 'bundler',
713
+ emitDecoratorMetadata: false,
714
+ module: 'preserve',
715
+ },
716
+ angularCompilerOptions: {
717
+ enableI18nLegacyMessageIdFormat: false,
718
+ strictInjectionParameters: true,
719
+ strictInputAccessModifiers: true,
720
+ strictTemplates: true,
721
+ },
722
+ files: [],
723
+ include: [],
724
+ references: [
725
+ { path: './tsconfig.app.json' },
726
+ { path: './tsconfig.spec.json' },
727
+ ],
728
+ },
729
+ null,
730
+ 2
731
+ ) + '\n'
732
+ );
733
+ }
734
+
735
+ function tsconfigAppJson() {
736
+ return (
737
+ JSON.stringify(
738
+ {
739
+ extends: './tsconfig.json',
740
+ compilerOptions: {
741
+ outDir: '../../dist/out-tsc',
742
+ types: [],
743
+ target: 'ES2020',
744
+ },
745
+ include: ['src/**/*.ts'],
746
+ exclude: [
747
+ 'src/**/*.spec.ts',
748
+ 'src/**/*.test.ts',
749
+ 'vite.config.ts',
750
+ 'vite.config.mts',
751
+ 'vitest.config.ts',
752
+ 'vitest.config.mts',
753
+ 'src/**/*.test.tsx',
754
+ 'src/**/*.spec.tsx',
755
+ 'src/**/*.test.js',
756
+ 'src/**/*.spec.js',
757
+ 'src/**/*.test.jsx',
758
+ 'src/**/*.spec.jsx',
759
+ 'src/test-setup.ts',
760
+ ],
761
+ files: ['src/app/remote-entry/entry.routes.ts'],
762
+ },
763
+ null,
764
+ 2
765
+ ) + '\n'
766
+ );
767
+ }
768
+
769
+ function tsconfigSpecJson() {
770
+ return (
771
+ JSON.stringify(
772
+ {
773
+ extends: './tsconfig.json',
774
+ compilerOptions: {
775
+ outDir: '../../dist/out-tsc',
776
+ types: [
777
+ 'vitest/globals',
778
+ 'vitest/importMeta',
779
+ 'vite/client',
780
+ 'node',
781
+ 'vitest',
782
+ ],
783
+ },
784
+ include: [
785
+ 'vite.config.ts',
786
+ 'vite.config.mts',
787
+ 'vitest.config.ts',
788
+ 'vitest.config.mts',
789
+ 'src/**/*.test.ts',
790
+ 'src/**/*.spec.ts',
791
+ 'src/**/*.test.tsx',
792
+ 'src/**/*.spec.tsx',
793
+ 'src/**/*.test.js',
794
+ 'src/**/*.spec.js',
795
+ 'src/**/*.test.jsx',
796
+ 'src/**/*.spec.jsx',
797
+ 'src/**/*.d.ts',
798
+ ],
799
+ files: ['src/test-setup.ts'],
800
+ },
801
+ null,
802
+ 2
803
+ ) + '\n'
804
+ );
805
+ }
806
+
807
+ function eslintConfigMjs() {
808
+ return `import nx from '@nx/eslint-plugin';
809
+ import baseConfig from '../../eslint.config.mjs';
810
+
811
+ export default [
812
+ ...baseConfig,
813
+ ...nx.configs['flat/angular'],
814
+ ...nx.configs['flat/angular-template'],
815
+ {
816
+ files: ['**/*.ts'],
817
+ rules: {
818
+ '@angular-eslint/directive-selector': [
819
+ 'error',
820
+ { type: 'attribute', prefix: 'mc', style: 'camelCase' },
821
+ ],
822
+ '@angular-eslint/component-selector': [
823
+ 'error',
824
+ { type: 'element', prefix: 'mc', style: 'kebab-case' },
825
+ ],
826
+ },
827
+ },
828
+ {
829
+ files: ['**/*.html'],
830
+ rules: {},
831
+ },
832
+ ];
833
+ `;
834
+ }
835
+
836
+ function jestConfigCts(appName) {
837
+ return `module.exports = {
838
+ displayName: '${appName}',
839
+ preset: '../../jest.preset.js',
840
+ setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
841
+ coverageDirectory: '../../coverage/apps/${appName}',
842
+ transform: {
843
+ '^.+\\\\.(ts|mjs|js|html)$': [
844
+ 'jest-preset-angular',
845
+ {
846
+ tsconfig: '<rootDir>/tsconfig.spec.json',
847
+ stringifyContentPathRegex: '\\\\.(html|svg)$',
848
+ },
849
+ ],
850
+ },
851
+ transformIgnorePatterns: ['node_modules/(?!.*\\\\.mjs$)'],
852
+ snapshotSerializers: [
853
+ 'jest-preset-angular/build/serializers/no-ng-attributes',
854
+ 'jest-preset-angular/build/serializers/ng-snapshot',
855
+ 'jest-preset-angular/build/serializers/html-comment',
856
+ ],
857
+ };
858
+ `;
859
+ }
860
+
861
+ // ─── Monorepo config updates ──────────────────────────────────────────────────
862
+
863
+ function updateMagCliConfig(ctx, rootPath) {
864
+ const configPath = path.join(rootPath, 'mag-cli.config.js');
865
+ if (!fs.existsSync(configPath)) {
866
+ console.log(' skip mag-cli.config.js (not found)');
867
+ return;
868
+ }
869
+
870
+ let content = fs.readFileSync(configPath, 'utf8');
871
+ if (content.includes(`'apps/${ctx.appName}/mag_assets'`)) {
872
+ console.log(' skip mag-cli.config.js (entry already present)');
873
+ return;
874
+ }
875
+
876
+ const entry = ` {\n source: 'apps/${ctx.appName}/mag_assets',\n output: 'apps/${ctx.appName}/public/assets',\n isRemote: true,\n },`;
877
+ // Insert before the closing ], of the paths array
878
+ content = content.replace(/(\s*\],?\s*\};\s*)$/, `\n${entry}\n$1`);
879
+ fs.writeFileSync(configPath, content, 'utf8');
880
+ console.log(' update mag-cli.config.js');
881
+ }
882
+
883
+ function updateTsConfigBase(ctx, rootPath) {
884
+ const configPath = path.join(rootPath, 'tsconfig.base.json');
885
+ if (!fs.existsSync(configPath)) {
886
+ console.log(' skip tsconfig.base.json (not found)');
887
+ return;
888
+ }
889
+
890
+ const tsconfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
891
+ const paths = tsconfig.compilerOptions?.paths ?? {};
892
+
893
+ if (paths[ctx.pathAlias]) {
894
+ console.log(' skip tsconfig.base.json (alias already present)');
895
+ return;
896
+ }
897
+
898
+ paths[ctx.pathAlias] = [
899
+ `apps/${ctx.appName}/src/app/remote-entry/entry.routes.ts`,
900
+ ];
901
+ tsconfig.compilerOptions.paths = paths;
902
+ fs.writeFileSync(
903
+ configPath,
904
+ JSON.stringify(tsconfig, null, 2) + '\n',
905
+ 'utf8'
906
+ );
907
+ console.log(' update tsconfig.base.json');
908
+ }
909
+
910
+ function updatePackageJsonScripts(ctx, rootPath) {
911
+ const pkgPath = path.join(rootPath, 'package.json');
912
+ if (!fs.existsSync(pkgPath)) {
913
+ console.log(' skip package.json (not found)');
914
+ return;
915
+ }
916
+
917
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
918
+ const n = ctx.name; // e.g. "wallet"
919
+ const a = ctx.appName; // e.g. "m-wallet"
920
+
921
+ const newScripts = {
922
+ [`start:${n}`]: `nx serve ${a}`,
923
+ [`build:${n}`]: `nx build ${a}`,
924
+ [`prebuild:${n}:dev`]: `npm run assets:compile && BUILD_CONFIG=dev node scripts/patch-wc-env.js`,
925
+ [`build:${n}:dev`]: `BUILD_CONFIG=dev nx build ${a} --configuration=dev --verbose`,
926
+ [`build:${n}:prod`]: `BUILD_CONFIG=production nx build ${a} --configuration=production --verbose`,
927
+ [`test:${n}`]: `nx test ${a}`,
928
+ [`lint:${n}`]: `nx lint ${a}`,
929
+ [`build:wc:${a}`]: `npx nx run ${a}:build:wc`,
930
+ };
931
+
932
+ let updated = false;
933
+ for (const [key, val] of Object.entries(newScripts)) {
934
+ if (!pkg.scripts[key]) {
935
+ pkg.scripts[key] = val;
936
+ updated = true;
937
+ }
938
+ }
939
+
940
+ if (updated) {
941
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
942
+ console.log(' update package.json');
943
+ } else {
944
+ console.log(' skip package.json (scripts already present)');
945
+ }
946
+ }