@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,2596 @@
1
+ const fs = require('fs');
2
+
3
+ async function createSourceFiles(
4
+ projectName,
5
+ companyName = null,
6
+ technology = 'angular'
7
+ ) {
8
+ if (technology === 'react') {
9
+ await createReactFSDSourceFiles(projectName, companyName);
10
+ } else {
11
+ await createAngularFSDSourceFiles(projectName, companyName);
12
+ }
13
+ }
14
+
15
+ async function createAngularFSDSourceFiles(projectName, companyName = null) {
16
+ // Create src/index.html with PWA meta tags
17
+ const indexHtml = `<!DOCTYPE html>
18
+ <html lang="en">
19
+ <head>
20
+ <meta charset="utf-8" />
21
+ <title>${projectName.charAt(0).toUpperCase() + projectName.slice(1)}</title>
22
+ <base href="/" />
23
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
24
+ <link rel="icon" type="image/x-icon" href="favicon.ico" />
25
+ <link rel="manifest" href="manifest.webmanifest" />
26
+ <meta name="theme-color" content="#1976d2" />
27
+ <!-- iOS meta tags -->
28
+ <meta name="apple-mobile-web-app-capable" content="yes" />
29
+ <meta name="apple-mobile-web-app-status-bar-style" content="default" />
30
+ <meta name="apple-mobile-web-app-title" content="${
31
+ projectName.charAt(0).toUpperCase() + projectName.slice(1)
32
+ }" />
33
+ <link rel="apple-touch-icon" href="assets/icons/icon-192x192.svg" />
34
+ <!-- Windows meta tags -->
35
+ <meta name="msapplication-TileImage" content="assets/icons/icon-144x144.svg" />
36
+ <meta name="msapplication-TileColor" content="#1976d2" />
37
+ </head>
38
+ <body>
39
+ <app-root></app-root>
40
+ </body>
41
+ </html>
42
+ `;
43
+
44
+ fs.writeFileSync('src/index.html', indexHtml);
45
+
46
+ // Create Web App Manifest
47
+ const manifest = {
48
+ name: `${projectName.charAt(0).toUpperCase() + projectName.slice(1)} App`,
49
+ short_name: projectName.charAt(0).toUpperCase() + projectName.slice(1),
50
+ theme_color: '#1976d2',
51
+ background_color: '#fafafa',
52
+ display: 'standalone',
53
+ scope: './',
54
+ start_url: './',
55
+ icons: [
56
+ {
57
+ src: 'assets/icons/icon-72x72.svg',
58
+ sizes: '72x72',
59
+ type: 'image/svg+xml',
60
+ purpose: 'maskable any',
61
+ },
62
+ {
63
+ src: 'assets/icons/icon-96x96.svg',
64
+ sizes: '96x96',
65
+ type: 'image/svg+xml',
66
+ purpose: 'maskable any',
67
+ },
68
+ {
69
+ src: 'assets/icons/icon-128x128.svg',
70
+ sizes: '128x128',
71
+ type: 'image/svg+xml',
72
+ purpose: 'maskable any',
73
+ },
74
+ {
75
+ src: 'assets/icons/icon-144x144.svg',
76
+ sizes: '144x144',
77
+ type: 'image/svg+xml',
78
+ purpose: 'maskable any',
79
+ },
80
+ {
81
+ src: 'assets/icons/icon-152x152.svg',
82
+ sizes: '152x152',
83
+ type: 'image/svg+xml',
84
+ purpose: 'maskable any',
85
+ },
86
+ {
87
+ src: 'assets/icons/icon-192x192.svg',
88
+ sizes: '192x192',
89
+ type: 'image/svg+xml',
90
+ purpose: 'maskable any',
91
+ },
92
+ {
93
+ src: 'assets/icons/icon-384x384.svg',
94
+ sizes: '384x384',
95
+ type: 'image/svg+xml',
96
+ purpose: 'maskable any',
97
+ },
98
+ {
99
+ src: 'assets/icons/icon-512x512.svg',
100
+ sizes: '512x512',
101
+ type: 'image/svg+xml',
102
+ purpose: 'maskable any',
103
+ },
104
+ ],
105
+ };
106
+
107
+ fs.writeFileSync(
108
+ 'src/manifest.webmanifest',
109
+ JSON.stringify(manifest, null, 2)
110
+ );
111
+
112
+ // Create src/main.ts
113
+ const mainTs = `import { bootstrapApplication } from '@angular/platform-browser';
114
+ import { appConfig } from './app/app.config';
115
+ import { AppComponent } from './app/app.component';
116
+
117
+ bootstrapApplication(AppComponent, appConfig)
118
+ .catch((err) => console.error(err));
119
+ `;
120
+
121
+ fs.writeFileSync('src/main.ts', mainTs);
122
+
123
+ // Create src/bootstrap.ts
124
+ const bootstrapTs = `import { initFederation } from '@angular-architects/native-federation';
125
+
126
+ initFederation()
127
+ .catch(err => console.error(err))
128
+ .then(_ => import('./main'))
129
+ .catch(err => console.error(err));
130
+ `;
131
+
132
+ fs.writeFileSync('src/bootstrap.ts', bootstrapTs);
133
+
134
+ // Create src/routes.ts with dynamic path based on company and app name
135
+ if (companyName) {
136
+ const routesTs = `import { Routes } from '@angular/router';
137
+ import { AppComponent } from './app/app.component';
138
+ import { appRoutes } from './app/app.routes';
139
+
140
+ export const routes: Routes = [
141
+ {
142
+ path: 'a/${companyName}/${projectName}',
143
+ component: AppComponent,
144
+ children: appRoutes,
145
+ },
146
+ ];
147
+ `;
148
+ fs.writeFileSync('src/routes.ts', routesTs);
149
+ }
150
+
151
+ // Create src/styles.scss
152
+ const stylesScss = `/* You can add global styles to this file, and also import other style files */
153
+
154
+ /* PWA Install Button Styles */
155
+ .pwa-install-button {
156
+ position: fixed;
157
+ top: 1rem;
158
+ right: 1rem;
159
+ background: #1976d2;
160
+ color: white;
161
+ border: none;
162
+ padding: 0.75rem 1rem;
163
+ border-radius: 0.5rem;
164
+ cursor: pointer;
165
+ font-size: 0.875rem;
166
+ font-weight: 500;
167
+ box-shadow: 0 2px 8px rgba(25, 118, 210, 0.3);
168
+ z-index: 1000;
169
+ transition: all 0.2s ease;
170
+ }
171
+
172
+ .pwa-install-button:hover {
173
+ background: #1565c0;
174
+ box-shadow: 0 4px 12px rgba(25, 118, 210, 0.4);
175
+ transform: translateY(-2px);
176
+ }
177
+
178
+ .pwa-install-button:active {
179
+ transform: translateY(0);
180
+ }
181
+ `;
182
+
183
+ fs.writeFileSync('src/styles.scss', stylesScss);
184
+
185
+ // Create app config with service worker and routing
186
+ const appConfigTs = `import { ApplicationConfig, provideZoneChangeDetection, isDevMode } from '@angular/core';
187
+ import { provideRouter } from '@angular/router';
188
+ import { provideServiceWorker } from '@angular/service-worker';
189
+ import { provideHttpClient, withInterceptors } from '@angular/common/http';
190
+
191
+ import { appRoutes } from './app.routes';
192
+
193
+ export const appConfig: ApplicationConfig = {
194
+ providers: [
195
+ provideZoneChangeDetection({ eventCoalescing: true }),
196
+ provideRouter(appRoutes),
197
+ provideHttpClient(withInterceptors([])),
198
+ provideServiceWorker('ngsw-worker.js', {
199
+ enabled: !isDevMode(),
200
+ registrationStrategy: 'registerWhenStable:30000'
201
+ })
202
+ ]
203
+ };
204
+ `;
205
+
206
+ fs.writeFileSync('src/app/app.config.ts', appConfigTs);
207
+
208
+ // Create FSD-structured Angular files
209
+ await createFSDFiles(projectName, companyName);
210
+
211
+ // Create environment files for browser builder
212
+ fs.mkdirSync('src/environments', { recursive: true });
213
+
214
+ const environmentTs = `export const environment = {
215
+ production: false
216
+ };
217
+ `;
218
+ fs.writeFileSync('src/environments/environment.ts', environmentTs);
219
+
220
+ const environmentProdTs = `export const environment = {
221
+ production: true
222
+ };
223
+ `;
224
+ fs.writeFileSync('src/environments/environment.prod.ts', environmentProdTs);
225
+
226
+ // Create web component structure if in monorepo
227
+ if (companyName) {
228
+ fs.mkdirSync('src/web/main', { recursive: true });
229
+
230
+ // Create main.component.ts with connectRouter utility
231
+ const mainComponentTs = `import { Component, inject } from '@angular/core';
232
+ import { Router, RouterOutlet } from '@angular/router';
233
+
234
+ export function connectRouter(router = inject(Router), useHash = false): void {
235
+ let url: string;
236
+ if (!useHash) {
237
+ url = \`\${location.pathname.substring(1)}\${location.search}\`;
238
+ router.navigateByUrl(url);
239
+ window.addEventListener('popstate', () => {
240
+ console.log('popstate', url);
241
+ router.navigateByUrl(url);
242
+ });
243
+ } else {
244
+ url = \`\${location.hash.substring(1)}\${location.search}\`;
245
+ router.navigateByUrl(url);
246
+ window.addEventListener('hashchange', () => {
247
+ router.navigateByUrl(url);
248
+ });
249
+ }
250
+ }
251
+
252
+ @Component({
253
+ selector: 'app-main',
254
+ standalone: true,
255
+ imports: [RouterOutlet],
256
+ template: '<router-outlet></router-outlet>',
257
+ })
258
+ export class MainComponent {
259
+ constructor() {
260
+ connectRouter();
261
+ }
262
+ }
263
+ `;
264
+ fs.writeFileSync('src/web/main/main.component.ts', mainComponentTs);
265
+
266
+ // Create main.web-component.ts with dynamic custom element name
267
+ const camelCaseProjectName = projectName
268
+ .split('-')
269
+ .map((word, index) =>
270
+ index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)
271
+ )
272
+ .join('');
273
+
274
+ const mainWebComponentTs = `import { createApplication } from '@angular/platform-browser';
275
+ import { createCustomElement } from '@angular/elements';
276
+ import { isDevMode, NgZone } from '@angular/core';
277
+ import { routes } from '../../routes';
278
+ import { provideRouter } from '@angular/router';
279
+ import { MainComponent } from './main.component';
280
+ import { provideServiceWorker } from '@angular/service-worker';
281
+
282
+ (async () => {
283
+ try {
284
+ const app = await createApplication({
285
+ providers: [
286
+ (globalThis as any).ngZone
287
+ ? { provide: NgZone, useValue: (globalThis as any).ngZone }
288
+ : [],
289
+ provideRouter(routes),
290
+ provideServiceWorker('ngsw-worker.js', {
291
+ enabled: !isDevMode(),
292
+ registrationStrategy: 'registerWhenStable:30000',
293
+ }),
294
+ ],
295
+ });
296
+ const ${camelCaseProjectName}WebComponent = createCustomElement(MainComponent, {
297
+ injector: app.injector,
298
+ });
299
+ customElements.define('mag-${companyName}-${projectName}-main-app', ${camelCaseProjectName}WebComponent);
300
+ } catch (error) {
301
+ console.error('Error creating ${
302
+ projectName.charAt(0).toUpperCase() + projectName.slice(1)
303
+ } Web Component:', error);
304
+ }
305
+ })();
306
+ `;
307
+ fs.writeFileSync('src/web/main/main.web-component.ts', mainWebComponentTs);
308
+ }
309
+ }
310
+
311
+ // Create FSD-structured Angular files with Angular 20 naming conventions
312
+ async function createFSDFiles(projectName, companyName = null) {
313
+ // APP LAYER - Main application setup
314
+ await createAppLayer(projectName, companyName);
315
+
316
+ // PAGES LAYER - Route components
317
+ await createPagesLayer(projectName);
318
+
319
+ // WIDGETS LAYER - Complex UI components
320
+ await createWidgetsLayer();
321
+
322
+ // FEATURES LAYER - Business logic features
323
+ await createFeaturesLayer();
324
+
325
+ // ENTITIES LAYER - Business entities
326
+ await createEntitiesLayer();
327
+
328
+ // SHARED LAYER - Reusable components and utilities
329
+ await createSharedLayer();
330
+ }
331
+
332
+ // App Layer - Main application files
333
+ async function createAppLayer(projectName) {
334
+ // Main app component with Angular 20 conventions
335
+ const appComponentTs = `import { Component } from '@angular/core';
336
+ import { CommonModule } from '@angular/common';
337
+ import { RouterOutlet } from '@angular/router';
338
+ import { HeaderWidget } from '../widgets/header/ui/header';
339
+
340
+ @Component({
341
+ selector: 'app-root',
342
+ imports: [CommonModule, RouterOutlet, HeaderWidget],
343
+ template: \`
344
+ <div class="app">
345
+ <header-widget></header-widget>
346
+ <main class="main-content">
347
+ <router-outlet></router-outlet>
348
+ </main>
349
+ </div>
350
+ \`,
351
+ styleUrl: './app.component.scss'
352
+ })
353
+ export class AppComponent {
354
+ title = '${projectName}';
355
+ }
356
+ `;
357
+ fs.writeFileSync('src/app/app.component.ts', appComponentTs);
358
+
359
+ // App component styles
360
+ const appComponentScss = `.app {
361
+ min-height: 100vh;
362
+ display: flex;
363
+ flex-direction: column;
364
+ }
365
+
366
+ .main-content {
367
+ flex: 1;
368
+ padding: 1rem;
369
+ }
370
+ `;
371
+ fs.writeFileSync('src/app/app.component.scss', appComponentScss);
372
+
373
+ // App routes using Angular 20 conventions
374
+ const appRoutesTs = `import { Routes } from '@angular/router';
375
+
376
+ export const appRoutes: Routes = [
377
+ {
378
+ path: '',
379
+ loadComponent: () => import('../pages/home/ui/home').then(m => m.HomePage)
380
+ },
381
+ {
382
+ path: 'about',
383
+ loadComponent: () => import('../pages/about/ui/about').then(m => m.AboutPage)
384
+ },
385
+ {
386
+ path: '**',
387
+ loadComponent: () => import('../pages/not-found/ui/not-found').then(m => m.NotFoundPage)
388
+ }
389
+ ];
390
+ `;
391
+ fs.writeFileSync('src/app/app.routes.ts', appRoutesTs);
392
+
393
+ // App component spec
394
+ const appComponentSpecTs = `import { TestBed } from '@angular/core/testing';
395
+ import { AppComponent } from './app.component';
396
+ import { provideRouter } from '@angular/router';
397
+
398
+ describe('AppComponent', () => {
399
+ beforeEach(async () => {
400
+ await TestBed.configureTestingModule({
401
+ imports: [AppComponent],
402
+ providers: [provideRouter([])]
403
+ }).compileComponents();
404
+ });
405
+
406
+ it('should create the app', () => {
407
+ const fixture = TestBed.createComponent(AppComponent);
408
+ const app = fixture.componentInstance;
409
+ expect(app).toBeTruthy();
410
+ });
411
+
412
+ it(\`should have the '${projectName}' title\`, () => {
413
+ const fixture = TestBed.createComponent(AppComponent);
414
+ const app = fixture.componentInstance;
415
+ expect(app.title).toEqual('${projectName}');
416
+ });
417
+ });
418
+ `;
419
+ fs.writeFileSync('src/app/app.component.spec.ts', appComponentSpecTs);
420
+ }
421
+
422
+ // Pages Layer
423
+ async function createPagesLayer(projectName) {
424
+ // Home Page
425
+ const homePageTs = `import { Component } from '@angular/core';
426
+ import { CommonModule } from '@angular/common';
427
+
428
+ @Component({
429
+ selector: 'home-page',
430
+ imports: [CommonModule],
431
+ template: \`
432
+ <div class="home-page">
433
+ <h1>Welcome to ${projectName}!</h1>
434
+ <p>This is your Angular 20 application with FSD architecture.</p>
435
+
436
+ <section class="features">
437
+ <h2>Features included:</h2>
438
+ <ul>
439
+ <li>✅ Angular 20</li>
440
+ <li>✅ FSD (Feature-Sliced Design) Architecture</li>
441
+ <li>✅ Module Federation with Native Federation</li>
442
+ <li>✅ Progressive Web App (PWA) capabilities</li>
443
+ <li>✅ TypeScript 5.8</li>
444
+ <li>✅ Angular 20 naming conventions</li>
445
+ </ul>
446
+ </section>
447
+ </div>
448
+ \`,
449
+ styleUrl: './home.scss'
450
+ })
451
+ export class HomePage {}
452
+ `;
453
+ fs.writeFileSync('src/pages/home/ui/home.ts', homePageTs);
454
+
455
+ const homePageScss = `.home-page {
456
+ max-width: 800px;
457
+ margin: 0 auto;
458
+ padding: 2rem;
459
+ }
460
+
461
+ .features {
462
+ margin-top: 2rem;
463
+
464
+ ul {
465
+ list-style: none;
466
+ padding: 0;
467
+
468
+ li {
469
+ padding: 0.5rem 0;
470
+ font-size: 1.1rem;
471
+ }
472
+ }
473
+ }
474
+ `;
475
+ fs.writeFileSync('src/pages/home/ui/home.scss', homePageScss);
476
+
477
+ // About Page
478
+ const aboutPageTs = `import { Component } from '@angular/core';
479
+ import { CommonModule } from '@angular/common';
480
+
481
+ @Component({
482
+ selector: 'about-page',
483
+ imports: [CommonModule],
484
+ template: \`
485
+ <div class="about-page">
486
+ <h1>About ${projectName}</h1>
487
+ <p>This application follows the FSD (Feature-Sliced Design) architecture.</p>
488
+ </div>
489
+ \`,
490
+ styleUrl: './about.scss'
491
+ })
492
+ export class AboutPage {}
493
+ `;
494
+ fs.writeFileSync('src/pages/about/ui/about.ts', aboutPageTs);
495
+
496
+ const aboutPageScss = `.about-page {
497
+ max-width: 800px;
498
+ margin: 0 auto;
499
+ padding: 2rem;
500
+ }
501
+ `;
502
+ fs.writeFileSync('src/pages/about/ui/about.scss', aboutPageScss);
503
+
504
+ // Not Found Page
505
+ const notFoundPageTs = `import { Component } from '@angular/core';
506
+ import { CommonModule } from '@angular/common';
507
+ import { RouterModule } from '@angular/router';
508
+
509
+ @Component({
510
+ selector: 'not-found-page',
511
+ imports: [CommonModule, RouterModule],
512
+ template: \`
513
+ <div class="not-found-page">
514
+ <h1>404 - Page Not Found</h1>
515
+ <p>The page you're looking for doesn't exist.</p>
516
+ <a routerLink="/" class="home-link">Go Home</a>
517
+ </div>
518
+ \`,
519
+ styleUrl: './not-found.scss'
520
+ })
521
+ export class NotFoundPage {}
522
+ `;
523
+ fs.writeFileSync('src/pages/not-found/ui/not-found.ts', notFoundPageTs);
524
+
525
+ const notFoundPageScss = `.not-found-page {
526
+ max-width: 800px;
527
+ margin: 0 auto;
528
+ padding: 2rem;
529
+ text-align: center;
530
+ }
531
+
532
+ .home-link {
533
+ display: inline-block;
534
+ margin-top: 1rem;
535
+ padding: 0.5rem 1rem;
536
+ background: #1976d2;
537
+ color: white;
538
+ text-decoration: none;
539
+ border-radius: 4px;
540
+
541
+ &:hover {
542
+ background: #1565c0;
543
+ }
544
+ }
545
+ `;
546
+ fs.writeFileSync('src/pages/not-found/ui/not-found.scss', notFoundPageScss);
547
+ }
548
+
549
+ // Widgets Layer
550
+ async function createWidgetsLayer() {
551
+ // Header Widget
552
+ const headerWidgetTs = `import { Component } from '@angular/core';
553
+ import { CommonModule } from '@angular/common';
554
+ import { RouterModule } from '@angular/router';
555
+
556
+ @Component({
557
+ selector: 'header-widget',
558
+ imports: [CommonModule, RouterModule],
559
+ template: \`
560
+ <header class="header">
561
+ <nav class="nav">
562
+ <div class="nav-brand">
563
+ <a routerLink="/" class="brand-link">App</a>
564
+ </div>
565
+ <ul class="nav-links">
566
+ <li><a routerLink="/" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">Home</a></li>
567
+ <li><a routerLink="/about" routerLinkActive="active">About</a></li>
568
+ </ul>
569
+ </nav>
570
+ </header>
571
+ \`,
572
+ styleUrl: './header.scss'
573
+ })
574
+ export class HeaderWidget {}
575
+ `;
576
+ fs.writeFileSync('src/widgets/header/ui/header.ts', headerWidgetTs);
577
+
578
+ const headerWidgetScss = `.header {
579
+ background: #1976d2;
580
+ color: white;
581
+ padding: 1rem;
582
+ }
583
+
584
+ .nav {
585
+ display: flex;
586
+ justify-content: space-between;
587
+ align-items: center;
588
+ max-width: 1200px;
589
+ margin: 0 auto;
590
+ }
591
+
592
+ .brand-link {
593
+ color: white;
594
+ text-decoration: none;
595
+ font-size: 1.5rem;
596
+ font-weight: bold;
597
+ }
598
+
599
+ .nav-links {
600
+ display: flex;
601
+ list-style: none;
602
+ margin: 0;
603
+ padding: 0;
604
+ gap: 1rem;
605
+
606
+ a {
607
+ color: white;
608
+ text-decoration: none;
609
+ padding: 0.5rem 1rem;
610
+ border-radius: 4px;
611
+
612
+ &:hover {
613
+ background: rgba(255, 255, 255, 0.1);
614
+ }
615
+
616
+ &.active {
617
+ background: rgba(255, 255, 255, 0.2);
618
+ }
619
+ }
620
+ }
621
+ `;
622
+ fs.writeFileSync('src/widgets/header/ui/header.scss', headerWidgetScss);
623
+ }
624
+
625
+ // Features Layer
626
+ async function createFeaturesLayer() {
627
+ // Theme Toggle Feature
628
+ const themeToggleTs = `import { Component, signal } from '@angular/core';
629
+ import { CommonModule } from '@angular/common';
630
+
631
+ @Component({
632
+ selector: 'theme-toggle',
633
+ imports: [CommonModule],
634
+ template: \`
635
+ <button
636
+ class="theme-toggle"
637
+ (click)="toggleTheme()"
638
+ [attr.aria-label]="'Switch to ' + (isDark() ? 'light' : 'dark') + ' mode'"
639
+ >
640
+ {{ isDark() ? '☀️' : '🌙' }}
641
+ </button>
642
+ \`,
643
+ styleUrl: './theme-toggle.scss'
644
+ })
645
+ export class ThemeToggle {
646
+ isDark = signal(false);
647
+
648
+ toggleTheme() {
649
+ this.isDark.update(value => !value);
650
+ document.body.classList.toggle('dark-theme', this.isDark());
651
+ }
652
+ }
653
+ `;
654
+ fs.writeFileSync(
655
+ 'src/features/theme-toggle/ui/theme-toggle.ts',
656
+ themeToggleTs
657
+ );
658
+
659
+ const themeToggleScss = `.theme-toggle {
660
+ background: none;
661
+ border: 2px solid currentColor;
662
+ border-radius: 50%;
663
+ width: 40px;
664
+ height: 40px;
665
+ cursor: pointer;
666
+ font-size: 1.2rem;
667
+ transition: all 0.2s ease;
668
+
669
+ &:hover {
670
+ transform: scale(1.1);
671
+ }
672
+ }
673
+ `;
674
+ fs.writeFileSync(
675
+ 'src/features/theme-toggle/ui/theme-toggle.scss',
676
+ themeToggleScss
677
+ );
678
+ }
679
+
680
+ // Entities Layer
681
+ async function createEntitiesLayer() {
682
+ // User Entity Model
683
+ const userModelTs = `export interface User {
684
+ id: string;
685
+ name: string;
686
+ email: string;
687
+ avatar?: string;
688
+ role: 'admin' | 'user';
689
+ }
690
+
691
+ export interface CreateUserDto {
692
+ name: string;
693
+ email: string;
694
+ role?: 'admin' | 'user';
695
+ }
696
+
697
+ export interface UpdateUserDto extends Partial<CreateUserDto> {
698
+ id: string;
699
+ }
700
+ `;
701
+ fs.writeFileSync('src/entities/user/model/user.model.ts', userModelTs);
702
+
703
+ // User API Service
704
+ const userApiTs = `import { Injectable, inject } from '@angular/core';
705
+ import { HttpClient } from '@angular/common/http';
706
+ import { Observable } from 'rxjs';
707
+ import { User, CreateUserDto, UpdateUserDto } from '../model/user.model';
708
+
709
+ @Injectable({
710
+ providedIn: 'root'
711
+ })
712
+ export class UserApi {
713
+ private http = inject(HttpClient);
714
+ private readonly apiUrl = '/api/users';
715
+
716
+ getUsers(): Observable<User[]> {
717
+ return this.http.get<User[]>(this.apiUrl);
718
+ }
719
+
720
+ getUser(id: string): Observable<User> {
721
+ return this.http.get<User>(\`\${this.apiUrl}/\${id}\`);
722
+ }
723
+
724
+ createUser(user: CreateUserDto): Observable<User> {
725
+ return this.http.post<User>(this.apiUrl, user);
726
+ }
727
+
728
+ updateUser(user: UpdateUserDto): Observable<User> {
729
+ return this.http.put<User>(\`\${this.apiUrl}/\${user.id}\`, user);
730
+ }
731
+
732
+ deleteUser(id: string): Observable<void> {
733
+ return this.http.delete<void>(\`\${this.apiUrl}/\${id}\`);
734
+ }
735
+ }
736
+ `;
737
+ fs.writeFileSync('src/entities/user/api/user.api.ts', userApiTs);
738
+ }
739
+
740
+ // Shared Layer
741
+ async function createSharedLayer() {
742
+ // Button Component
743
+ const buttonComponentTs = `import { Component, input, output } from '@angular/core';
744
+ import { CommonModule } from '@angular/common';
745
+
746
+ @Component({
747
+ selector: 'ui-button',
748
+ imports: [CommonModule],
749
+ template: \`
750
+ <button
751
+ [class]="buttonClasses()"
752
+ [disabled]="disabled()"
753
+ [type]="type()"
754
+ (click)="handleClick($event)"
755
+ >
756
+ <ng-content></ng-content>
757
+ </button>
758
+ \`,
759
+ styleUrl: './button.scss'
760
+ })
761
+ export class UiButton {
762
+ variant = input<'primary' | 'secondary' | 'danger'>('primary');
763
+ size = input<'small' | 'medium' | 'large'>('medium');
764
+ disabled = input<boolean>(false);
765
+ type = input<'button' | 'submit' | 'reset'>('button');
766
+
767
+ click = output<MouseEvent>();
768
+
769
+ buttonClasses() {
770
+ return \`btn btn-\${this.variant()} btn-\${this.size()}\`;
771
+ }
772
+
773
+ handleClick(event: MouseEvent) {
774
+ if (!this.disabled()) {
775
+ this.click.emit(event);
776
+ }
777
+ }
778
+ }
779
+ `;
780
+ fs.writeFileSync('src/shared/ui/button/button.ts', buttonComponentTs);
781
+
782
+ const buttonComponentScss = `.btn {
783
+ padding: 0.5rem 1rem;
784
+ border: none;
785
+ border-radius: 4px;
786
+ cursor: pointer;
787
+ font-weight: 500;
788
+ transition: all 0.2s ease;
789
+
790
+ &:disabled {
791
+ opacity: 0.6;
792
+ cursor: not-allowed;
793
+ }
794
+
795
+ &.btn-small {
796
+ padding: 0.25rem 0.5rem;
797
+ font-size: 0.875rem;
798
+ }
799
+
800
+ &.btn-large {
801
+ padding: 0.75rem 1.5rem;
802
+ font-size: 1.125rem;
803
+ }
804
+
805
+ &.btn-primary {
806
+ background: #1976d2;
807
+ color: white;
808
+
809
+ &:hover:not(:disabled) {
810
+ background: #1565c0;
811
+ }
812
+ }
813
+
814
+ &.btn-secondary {
815
+ background: #6c757d;
816
+ color: white;
817
+
818
+ &:hover:not(:disabled) {
819
+ background: #5a6268;
820
+ }
821
+ }
822
+
823
+ &.btn-danger {
824
+ background: #dc3545;
825
+ color: white;
826
+
827
+ &:hover:not(:disabled) {
828
+ background: #c82333;
829
+ }
830
+ }
831
+ }
832
+ `;
833
+ fs.writeFileSync('src/shared/ui/button/button.scss', buttonComponentScss);
834
+
835
+ // Utils
836
+ const utilsTs = `export function formatDate(date: Date): string {
837
+ return new Intl.DateTimeFormat('en-US', {
838
+ year: 'numeric',
839
+ month: 'long',
840
+ day: 'numeric'
841
+ }).format(date);
842
+ }
843
+
844
+ export function debounce<T extends (...args: any[]) => any>(
845
+ func: T,
846
+ wait: number
847
+ ): T {
848
+ let timeout: number | null = null;
849
+ return ((...args: any[]) => {
850
+ const later = () => {
851
+ timeout = null;
852
+ func(...args);
853
+ };
854
+ if (timeout) clearTimeout(timeout);
855
+ timeout = setTimeout(later, wait);
856
+ }) as T;
857
+ }
858
+
859
+ export function generateId(): string {
860
+ return Math.random().toString(36).substring(2) + Date.now().toString(36);
861
+ }
862
+ `;
863
+ fs.writeFileSync('src/shared/lib/utils/index.ts', utilsTs);
864
+
865
+ // Constants
866
+ const constantsTs = `export const API_BASE_URL = '/api';
867
+
868
+ export const STORAGE_KEYS = {
869
+ USER_PREFERENCES: 'user-preferences',
870
+ AUTH_TOKEN: 'auth-token',
871
+ THEME: 'theme'
872
+ } as const;
873
+
874
+ export const ROUTES = {
875
+ HOME: '/',
876
+ ABOUT: '/about',
877
+ LOGIN: '/login',
878
+ PROFILE: '/profile'
879
+ } as const;
880
+ `;
881
+ fs.writeFileSync('src/shared/lib/constants/index.ts', constantsTs);
882
+
883
+ // Types
884
+ const typesTs = `export type ApiResponse<T> = {
885
+ data: T;
886
+ message?: string;
887
+ success: boolean;
888
+ };
889
+
890
+ export type PaginatedResponse<T> = {
891
+ data: T[];
892
+ total: number;
893
+ page: number;
894
+ limit: number;
895
+ };
896
+
897
+ export type LoadingState = 'idle' | 'loading' | 'success' | 'error';
898
+ `;
899
+ fs.writeFileSync('src/shared/types/index.ts', typesTs);
900
+ }
901
+
902
+ async function createReactFSDSourceFiles(projectName, companyName = null) {
903
+ // Create FSD architecture files for React
904
+
905
+ // 1. App Layer - Core application setup
906
+
907
+ // Create src/index.html
908
+ const indexHtml = `<!DOCTYPE html>
909
+ <html lang="en">
910
+ <head>
911
+ <meta charset="utf-8" />
912
+ <title>${projectName.charAt(0).toUpperCase() + projectName.slice(1)}</title>
913
+ <base href="/" />
914
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
915
+ <link rel="icon" type="image/x-icon" href="favicon.ico" />
916
+ <link rel="manifest" href="manifest.webmanifest" />
917
+ <meta name="theme-color" content="#1976d2" />
918
+ <!-- iOS meta tags -->
919
+ <meta name="apple-mobile-web-app-capable" content="yes" />
920
+ <meta name="apple-mobile-web-app-status-bar-style" content="default" />
921
+ <meta name="apple-mobile-web-app-title" content="${
922
+ projectName.charAt(0).toUpperCase() + projectName.slice(1)
923
+ }" />
924
+ <link rel="apple-touch-icon" href="/shared/assets/icons/icon-192x192.svg" />
925
+ <link rel="stylesheet" href="styles.css" />
926
+ <!-- Windows meta tags -->
927
+ <meta name="msapplication-TileImage" content="/shared/assets/icons/icon-144x144.svg" />
928
+ <meta name="msapplication-TileColor" content="#1976d2" />
929
+ </head>
930
+ <body>
931
+ <div id="root"></div>
932
+ <!-- Load the import map generated by Native Federation -->
933
+ <script type="esms-options">
934
+ {
935
+ "shimMode": true
936
+ }
937
+ </script>
938
+ <script src="https://ga.jspm.io/npm:es-module-shims@1.5.17/dist/es-module-shims.js"></script>
939
+ <script type="module-shim" src="main.js"></script>
940
+ </body>
941
+ </html>
942
+ `;
943
+ fs.writeFileSync('src/index.html', indexHtml);
944
+
945
+ // Create manifest
946
+ const manifest = {
947
+ name: `${projectName.charAt(0).toUpperCase() + projectName.slice(1)} App`,
948
+ short_name: projectName.charAt(0).toUpperCase() + projectName.slice(1),
949
+ theme_color: '#1976d2',
950
+ background_color: '#fafafa',
951
+ display: 'standalone',
952
+ scope: './',
953
+ start_url: './',
954
+ icons: [
955
+ {
956
+ src: '/shared/assets/icons/icon-192x192.svg',
957
+ sizes: '192x192',
958
+ type: 'image/svg+xml',
959
+ purpose: 'maskable any',
960
+ },
961
+ {
962
+ src: '/shared/assets/icons/icon-512x512.svg',
963
+ sizes: '512x512',
964
+ type: 'image/svg+xml',
965
+ purpose: 'maskable any',
966
+ },
967
+ ],
968
+ };
969
+ fs.writeFileSync(
970
+ 'src/manifest.webmanifest',
971
+ JSON.stringify(manifest, null, 2)
972
+ );
973
+
974
+ // Create src/main.tsx - App entry point
975
+ const mainTsx = `import React from 'react';
976
+ import { createRoot } from 'react-dom/client';
977
+ import { App } from './app';
978
+
979
+ const container = document.getElementById('root');
980
+ const root = createRoot(container!);
981
+
982
+ root.render(
983
+ <React.StrictMode>
984
+ <App />
985
+ </React.StrictMode>
986
+ );
987
+ `;
988
+ fs.writeFileSync('src/main.tsx', mainTsx);
989
+
990
+ // Create src/app/index.tsx - App component with providers
991
+ const appIndexTsx = `import React from 'react';
992
+ import { BrowserRouter } from 'react-router-dom';
993
+ import { Provider } from 'react-redux';
994
+ import { store } from './store';
995
+ import { Routing } from './providers/routing';
996
+ import './styles/global.sass';
997
+
998
+ // Determine basename based on deployment context
999
+ const getBasename = () => {
1000
+ // Check if running in webapp context (via URL or environment)
1001
+ const isWebappContext =
1002
+ window.location.pathname.startsWith('/a/') ||
1003
+ process.env.REACT_APP_WEBAPP_MODE === 'true' ||
1004
+ window.location.hostname.includes('webapp');
1005
+
1006
+ return isWebappContext${
1007
+ companyName ? ` ? '/a/${companyName}/${projectName}' : '/'` : " ? '/' : '/'"
1008
+ };
1009
+ };
1010
+
1011
+ export const App: React.FC = () => {
1012
+ return (
1013
+ <Provider store={store}>
1014
+ <BrowserRouter
1015
+ basename={getBasename()}
1016
+ future={{
1017
+ v7_startTransition: true,
1018
+ v7_relativeSplatPath: true,
1019
+ }}
1020
+ >
1021
+ <Routing />
1022
+ </BrowserRouter>
1023
+ </Provider>
1024
+ );
1025
+ };
1026
+ `;
1027
+ fs.writeFileSync('src/app/index.tsx', appIndexTsx);
1028
+
1029
+ // Create src/app/store/index.ts - Redux store
1030
+ const storeTs = `import { configureStore } from '@reduxjs/toolkit';
1031
+ import { userModel } from '../../entities/user';
1032
+ import { sessionModel } from '../../entities/session';
1033
+
1034
+ export const store = configureStore({
1035
+ reducer: {
1036
+ user: userModel.reducer,
1037
+ session: sessionModel.reducer,
1038
+ },
1039
+ });
1040
+
1041
+ export type RootState = ReturnType<typeof store.getState>;
1042
+ export type AppDispatch = typeof store.dispatch;
1043
+ `;
1044
+ fs.writeFileSync('src/app/store/index.ts', storeTs);
1045
+
1046
+ // Create src/app/providers/routing.tsx - App routing
1047
+ const routingTsx = `import React from 'react';
1048
+ import { Routes, Route } from 'react-router-dom';
1049
+ import { HomePage } from '../../pages/home';
1050
+ import { AboutPage } from '../../pages/about';
1051
+ import { ContactPage } from '../../pages/contact';
1052
+
1053
+ export const Routing: React.FC = () => {
1054
+ return (
1055
+ <Routes>
1056
+ <Route path="/" element={<HomePage />} />
1057
+ <Route path="/about" element={<AboutPage />} />
1058
+ <Route path="/contact" element={<ContactPage />} />
1059
+ </Routes>
1060
+ );
1061
+ };
1062
+ `;
1063
+ fs.writeFileSync('src/app/providers/routing.tsx', routingTsx);
1064
+
1065
+ // Create src/app/styles/_variables.sass - Shared variables and mixins
1066
+ const variablesSass = `/* Sass Mixins for responsive design */
1067
+ @mixin mobile
1068
+ @media (max-width: 767px)
1069
+ @content
1070
+
1071
+ @mixin tablet
1072
+ @media (min-width: 768px) and (max-width: 1023px)
1073
+ @content
1074
+
1075
+ @mixin desktop
1076
+ @media (min-width: 1024px)
1077
+ @content
1078
+
1079
+ // Base color values for CSS custom properties
1080
+ $base-primary-color: #1976d2 !default
1081
+ $base-primary-dark: #1565c0 !default
1082
+ $base-secondary-color: #f5f5f5 !default
1083
+ $base-text-primary: #333 !default
1084
+ $base-text-secondary: #666 !default
1085
+ $base-border-color: #e0e0e0 !default
1086
+ $base-background-color: #ffffff !default
1087
+ $base-surface-color: #ffffff !default
1088
+
1089
+ // Theme-aware variables using CSS custom properties
1090
+ $primary-color: var(--primary-color) !default
1091
+ $primary-dark: var(--primary-dark) !default
1092
+ $secondary-color: var(--secondary-color) !default
1093
+ $text-primary: var(--text-primary) !default
1094
+ $text-secondary: var(--text-secondary) !default
1095
+ $border-color: var(--border-color) !default
1096
+ $background-color: var(--background-color) !default
1097
+ $surface-color: var(--surface-color) !default
1098
+ $shadow: var(--shadow) !default
1099
+ `;
1100
+ fs.writeFileSync('src/app/styles/_variables.sass', variablesSass);
1101
+
1102
+ // Create src/app/styles/global.sass - Global styles with theme support
1103
+ const globalSass = `@use './variables' as *
1104
+
1105
+ /* CSS Custom Properties for theming */
1106
+ :root
1107
+ // Light theme (default)
1108
+ --primary-color: #{$base-primary-color}
1109
+ --primary-dark: #{$base-primary-dark}
1110
+ --secondary-color: #{$base-secondary-color}
1111
+ --text-primary: #{$base-text-primary}
1112
+ --text-secondary: #{$base-text-secondary}
1113
+ --border-color: #{$base-border-color}
1114
+ --background-color: #{$base-background-color}
1115
+ --surface-color: #{$base-surface-color}
1116
+ --shadow: 0 2px 8px rgba(0, 0, 0, 0.1)
1117
+
1118
+ // Dark theme
1119
+ :root[data-theme="dark"]
1120
+ --primary-color: #42a5f5
1121
+ --primary-dark: #1e88e5
1122
+ --secondary-color: #1e1e1e
1123
+ --text-primary: #ffffff
1124
+ --text-secondary: #b0b0b0
1125
+ --border-color: #333333
1126
+ --background-color: #121212
1127
+ --surface-color: #1e1e1e
1128
+ --shadow: 0 2px 8px rgba(0, 0, 0, 0.3)
1129
+
1130
+ /* Reset and base styles */
1131
+ *
1132
+ margin: 0
1133
+ padding: 0
1134
+ box-sizing: border-box
1135
+
1136
+ body
1137
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif
1138
+ -webkit-font-smoothing: antialiased
1139
+ -moz-osx-font-smoothing: grayscale
1140
+ background-color: var(--background-color)
1141
+ color: var(--text-primary)
1142
+ transition: background-color 0.3s ease, color 0.3s ease
1143
+
1144
+ +mobile
1145
+ font-size: 14px
1146
+
1147
+ +tablet
1148
+ font-size: 16px
1149
+
1150
+ +desktop
1151
+ font-size: 16px
1152
+
1153
+ #root
1154
+ min-height: 100vh
1155
+ background-color: var(--background-color)
1156
+
1157
+ /* Theme-aware utility classes */
1158
+ .surface
1159
+ background-color: var(--surface-color)
1160
+ border: 1px solid var(--border-color)
1161
+
1162
+ .text-primary
1163
+ color: var(--text-primary)
1164
+
1165
+ .text-secondary
1166
+ color: var(--text-secondary)
1167
+
1168
+ /* Smooth transitions for theme changes */
1169
+ *
1170
+ transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease
1171
+ `;
1172
+ fs.writeFileSync('src/app/styles/global.sass', globalSass);
1173
+
1174
+ // Create .env files for different deployment modes
1175
+ const envDevelopment = `# Development environment variables
1176
+ # Set to 'true' when deploying to webapp context
1177
+ REACT_APP_WEBAPP_MODE=false
1178
+
1179
+ # Build environment
1180
+ NODE_ENV=development
1181
+ `;
1182
+
1183
+ const envProduction = `# Production environment variables
1184
+ # Set to 'true' when deploying to webapp context
1185
+ REACT_APP_WEBAPP_MODE=false
1186
+
1187
+ # Build environment
1188
+ NODE_ENV=production
1189
+ `;
1190
+
1191
+ const envWebapp = `# Webapp deployment environment variables
1192
+ # Set to 'true' when deploying to webapp context
1193
+ REACT_APP_WEBAPP_MODE=true
1194
+
1195
+ # Build environment
1196
+ NODE_ENV=production
1197
+ `;
1198
+
1199
+ fs.writeFileSync('.env', envDevelopment);
1200
+ fs.writeFileSync('.env.production', envProduction);
1201
+ fs.writeFileSync('.env.webapp', envWebapp);
1202
+
1203
+ // Create README section about basename configuration
1204
+ const basenameDocs = `
1205
+ ## Dynamic Basename Configuration
1206
+
1207
+ This project automatically determines the basename for React Router based on the deployment context:
1208
+
1209
+ ### Automatic Detection
1210
+ The app detects webapp context using:
1211
+ - URL path starting with \`/a/\`
1212
+ - Environment variable \`REACT_APP_WEBAPP_MODE=true\`
1213
+ - Hostname containing 'webapp'
1214
+
1215
+ ### Build Modes
1216
+ - **Standalone**: \`npm run build:standalone\` - Routes use \`/\` as basename
1217
+ - **Webapp**: \`npm run build:webapp\` - Routes use \`/a/${
1218
+ companyName || 'company'
1219
+ }/${projectName}\` as basename
1220
+ - **Default**: \`npm run build\` - Uses environment detection
1221
+
1222
+ ### Environment Files
1223
+ - \`.env\` - Development (standalone mode)
1224
+ - \`.env.production\` - Production (standalone mode)
1225
+ - \`.env.webapp\` - Webapp deployment mode
1226
+
1227
+ ### Manual Override
1228
+ Set \`REACT_APP_WEBAPP_MODE=true\` to force webapp mode or \`false\` for standalone mode.
1229
+ `;
1230
+
1231
+ // Append to existing README if it exists, or create new section
1232
+ try {
1233
+ const existingReadme = fs.readFileSync('README.md', 'utf8');
1234
+ fs.writeFileSync('README.md', existingReadme + basenameDocs);
1235
+ } catch {
1236
+ // If README doesn't exist, it will be created by other parts of the init script
1237
+ // Store the docs to add later
1238
+ global.basenameDocs = basenameDocs;
1239
+ }
1240
+
1241
+ // 2. Pages Layer - HomePage
1242
+
1243
+ // Create src/pages/home/index.ts - Public API
1244
+ const homeIndexTs = `export { HomePage } from './ui/HomePage';
1245
+ `;
1246
+ fs.writeFileSync('src/pages/home/index.ts', homeIndexTs);
1247
+
1248
+ // Create src/pages/home/ui/HomePage.tsx
1249
+ const homePageTsx = `import React from 'react';
1250
+ import { Header } from '../../../widgets/header';
1251
+ import { Footer } from '../../../widgets/footer';
1252
+ import { AuthFeature } from '../../../features/auth';
1253
+ import { ThemeToggle } from '../../../features/theme-toggle';
1254
+ import styles from './HomePage.module.sass';
1255
+
1256
+ export const HomePage: React.FC = () => {
1257
+ return (
1258
+ <div className={styles.homePage}>
1259
+ <Header />
1260
+
1261
+ <main className={styles.homeContent}>
1262
+ <div className={styles.container}>
1263
+ <h1>Welcome to ${
1264
+ projectName.charAt(0).toUpperCase() + projectName.slice(1)
1265
+ }</h1>
1266
+
1267
+ <div className={styles.featuresGrid}>
1268
+ <div className={styles.featureCard}>
1269
+ <h3>🏗️ FSD Architecture</h3>
1270
+ <p>Built with Feature-Sliced Design for scalability and maintainability</p>
1271
+ </div>
1272
+
1273
+ <div className={styles.featureCard}>
1274
+ <h3>⚡ React + TypeScript</h3>
1275
+ <p>Modern development stack with type safety</p>
1276
+ </div>
1277
+
1278
+ <div className={styles.featureCard}>
1279
+ <h3>🎨 Themeable</h3>
1280
+ <p>Built-in theme system with CSS custom properties</p>
1281
+ </div>
1282
+
1283
+ <div className={styles.featureCard}>
1284
+ <h3>📱 PWA Ready</h3>
1285
+ <p>Progressive Web App capabilities built-in</p>
1286
+ </div>
1287
+ </div>
1288
+
1289
+ <div className={styles.actions}>
1290
+ <ThemeToggle />
1291
+ <AuthFeature />
1292
+ </div>
1293
+ </div>
1294
+ </main>
1295
+
1296
+ <Footer />
1297
+ </div>
1298
+ );
1299
+ };
1300
+ `;
1301
+ fs.writeFileSync('src/pages/home/ui/HomePage.tsx', homePageTsx);
1302
+
1303
+ // Create src/pages/home/ui/HomePage.module.sass
1304
+ const homePageSass = `@use '../../../app/styles/variables' as *
1305
+
1306
+ .homePage
1307
+ min-height: 100vh
1308
+ display: flex
1309
+ flex-direction: column
1310
+
1311
+ .homeContent
1312
+ flex: 1
1313
+ padding: 2rem 0
1314
+
1315
+ +mobile
1316
+ padding: 1rem 0
1317
+
1318
+ h1
1319
+ text-align: center
1320
+ color: var(--primary-color)
1321
+ margin-bottom: 3rem
1322
+ font-size: 2.5rem
1323
+
1324
+ +mobile
1325
+ font-size: 2rem
1326
+ margin-bottom: 2rem
1327
+
1328
+ .container
1329
+ max-width: 1200px
1330
+ margin: 0 auto
1331
+ padding: 0 1rem
1332
+
1333
+ .featuresGrid
1334
+ display: grid
1335
+ grid-template-columns: repeat(auto-fit, minmax(280px, 1fr))
1336
+ gap: 2rem
1337
+ margin-bottom: 3rem
1338
+
1339
+ +mobile
1340
+ grid-template-columns: 1fr
1341
+ gap: 1rem
1342
+
1343
+ .featureCard
1344
+ background: var(--surface-color)
1345
+ padding: 2rem
1346
+ border-radius: 8px
1347
+ box-shadow: var(--shadow)
1348
+ border: 1px solid var(--border-color)
1349
+ transition: transform 0.2s ease
1350
+
1351
+ +mobile
1352
+ padding: 1.5rem
1353
+
1354
+ &:hover
1355
+ transform: translateY(-2px)
1356
+
1357
+ h3
1358
+ margin-bottom: 1rem
1359
+ color: var(--text-primary)
1360
+
1361
+ p
1362
+ color: var(--text-secondary)
1363
+ line-height: 1.6
1364
+
1365
+ .actions
1366
+ display: flex
1367
+ gap: 1rem
1368
+ justify-content: center
1369
+ flex-wrap: wrap
1370
+
1371
+ +mobile
1372
+ flex-direction: column
1373
+ align-items: center
1374
+ `;
1375
+ fs.writeFileSync('src/pages/home/ui/HomePage.module.sass', homePageSass);
1376
+
1377
+ // Create About Page
1378
+ fs.mkdirSync('src/pages/about', { recursive: true });
1379
+ fs.mkdirSync('src/pages/about/ui', { recursive: true });
1380
+
1381
+ const aboutPageTsx = `import React from 'react';
1382
+ import { Header } from '../../../widgets/header';
1383
+ import { Footer } from '../../../widgets/footer';
1384
+ import styles from './AboutPage.module.sass';
1385
+
1386
+ export const AboutPage: React.FC = () => {
1387
+ return (
1388
+ <div className={styles.aboutPage}>
1389
+ <Header />
1390
+ <main className={styles.aboutContent}>
1391
+ <div className={styles.container}>
1392
+ <h1>About Us</h1>
1393
+ <div className={styles.content}>
1394
+ <section className={styles.section}>
1395
+ <h2>Our Mission</h2>
1396
+ <p>
1397
+ We are dedicated to building modern, scalable web applications using
1398
+ the latest technologies and best practices in software architecture.
1399
+ </p>
1400
+ </section>
1401
+
1402
+ <section className={styles.section}>
1403
+ <h2>Our Technology Stack</h2>
1404
+ <ul className={styles.techList}>
1405
+ <li>React 18 with TypeScript</li>
1406
+ <li>Feature-Sliced Design Architecture</li>
1407
+ <li>Native Federation for Micro-frontends</li>
1408
+ <li>Progressive Web App capabilities</li>
1409
+ <li>Modern CSS with Sass</li>
1410
+ </ul>
1411
+ </section>
1412
+
1413
+ <section className={styles.section}>
1414
+ <h2>Why Choose Us</h2>
1415
+ <p>
1416
+ Our approach focuses on maintainability, scalability, and developer experience.
1417
+ We believe in clean code, proper architecture, and future-proof solutions.
1418
+ </p>
1419
+ </section>
1420
+ </div>
1421
+ </div>
1422
+ </main>
1423
+ <Footer />
1424
+ </div>
1425
+ );
1426
+ };
1427
+ `;
1428
+
1429
+ const aboutPageSass = `@use '../../../app/styles/variables' as *
1430
+
1431
+ .aboutPage
1432
+ min-height: 100vh
1433
+ display: flex
1434
+ flex-direction: column
1435
+
1436
+ .aboutContent
1437
+ flex: 1
1438
+ padding: 2rem 0
1439
+
1440
+ +mobile
1441
+ padding: 1rem 0
1442
+
1443
+ h1
1444
+ text-align: center
1445
+ color: var(--primary-color)
1446
+ margin-bottom: 3rem
1447
+ font-size: 2.5rem
1448
+
1449
+ +mobile
1450
+ font-size: 2rem
1451
+ margin-bottom: 2rem
1452
+
1453
+ .container
1454
+ max-width: 1200px
1455
+ margin: 0 auto
1456
+ padding: 0 1rem
1457
+
1458
+ .content
1459
+ max-width: 800px
1460
+ margin: 0 auto
1461
+
1462
+ .section
1463
+ margin-bottom: 3rem
1464
+
1465
+ +mobile
1466
+ margin-bottom: 2rem
1467
+
1468
+ h2
1469
+ color: var(--primary-color)
1470
+ margin-bottom: 1rem
1471
+ font-size: 1.5rem
1472
+
1473
+ p
1474
+ color: var(--text-secondary)
1475
+ line-height: 1.6
1476
+ margin-bottom: 1rem
1477
+
1478
+ .techList
1479
+ list-style: none
1480
+ padding: 0
1481
+
1482
+ li
1483
+ background: var(--surface-color)
1484
+ padding: 0.75rem 1rem
1485
+ margin-bottom: 0.5rem
1486
+ border-radius: 4px
1487
+ border-left: 4px solid var(--primary-color)
1488
+ box-shadow: var(--shadow)
1489
+
1490
+ +mobile
1491
+ padding: 0.5rem 0.75rem
1492
+ `;
1493
+
1494
+ const aboutIndexTs = `export { AboutPage } from './ui/AboutPage';
1495
+ `;
1496
+
1497
+ fs.writeFileSync('src/pages/about/ui/AboutPage.tsx', aboutPageTsx);
1498
+ fs.writeFileSync('src/pages/about/ui/AboutPage.module.sass', aboutPageSass);
1499
+ fs.writeFileSync('src/pages/about/index.ts', aboutIndexTs);
1500
+
1501
+ // Create Contact Page
1502
+ fs.mkdirSync('src/pages/contact', { recursive: true });
1503
+ fs.mkdirSync('src/pages/contact/ui', { recursive: true });
1504
+
1505
+ const contactPageTsx = `import React, { useState } from 'react';
1506
+ import { Header } from '../../../widgets/header';
1507
+ import { Footer } from '../../../widgets/footer';
1508
+ import { Button } from '../../../shared/ui/button';
1509
+ import styles from './ContactPage.module.sass';
1510
+
1511
+ export const ContactPage: React.FC = () => {
1512
+ const [formData, setFormData] = useState({
1513
+ name: '',
1514
+ email: '',
1515
+ message: ''
1516
+ });
1517
+
1518
+ const handleSubmit = (e: React.FormEvent) => {
1519
+ e.preventDefault();
1520
+ alert('Thank you for your message! We will get back to you soon.');
1521
+ setFormData({ name: '', email: '', message: '' });
1522
+ };
1523
+
1524
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
1525
+ setFormData(prev => ({
1526
+ ...prev,
1527
+ [e.target.name]: e.target.value
1528
+ }));
1529
+ };
1530
+
1531
+ return (
1532
+ <div className={styles.contactPage}>
1533
+ <Header />
1534
+ <main className={styles.contactContent}>
1535
+ <div className={styles.container}>
1536
+ <h1>Contact Us</h1>
1537
+
1538
+ <div className={styles.contactGrid}>
1539
+ <div className={styles.contactInfo}>
1540
+ <h2>Get in Touch</h2>
1541
+ <p>
1542
+ We'd love to hear from you. Send us a message and we'll respond as soon as possible.
1543
+ </p>
1544
+
1545
+ <div className={styles.infoItem}>
1546
+ <h3>📧 Email</h3>
1547
+ <p>contact@example.com</p>
1548
+ </div>
1549
+
1550
+ <div className={styles.infoItem}>
1551
+ <h3>📱 Phone</h3>
1552
+ <p>+1 (555) 123-4567</p>
1553
+ </div>
1554
+
1555
+ <div className={styles.infoItem}>
1556
+ <h3>📍 Address</h3>
1557
+ <p>123 Tech Street<br />Innovation City, IC 12345</p>
1558
+ </div>
1559
+ </div>
1560
+
1561
+ <form className={styles.contactForm} onSubmit={handleSubmit}>
1562
+ <h2>Send us a Message</h2>
1563
+
1564
+ <div className={styles.formGroup}>
1565
+ <label htmlFor="name">Name *</label>
1566
+ <input
1567
+ type="text"
1568
+ id="name"
1569
+ name="name"
1570
+ value={formData.name}
1571
+ onChange={handleChange}
1572
+ required
1573
+ />
1574
+ </div>
1575
+
1576
+ <div className={styles.formGroup}>
1577
+ <label htmlFor="email">Email *</label>
1578
+ <input
1579
+ type="email"
1580
+ id="email"
1581
+ name="email"
1582
+ value={formData.email}
1583
+ onChange={handleChange}
1584
+ required
1585
+ />
1586
+ </div>
1587
+
1588
+ <div className={styles.formGroup}>
1589
+ <label htmlFor="message">Message *</label>
1590
+ <textarea
1591
+ id="message"
1592
+ name="message"
1593
+ value={formData.message}
1594
+ onChange={handleChange}
1595
+ rows={5}
1596
+ required
1597
+ />
1598
+ </div>
1599
+
1600
+ <Button type="submit" variant="primary" size="large">
1601
+ Send Message
1602
+ </Button>
1603
+ </form>
1604
+ </div>
1605
+ </div>
1606
+ </main>
1607
+ <Footer />
1608
+ </div>
1609
+ );
1610
+ };
1611
+ `;
1612
+
1613
+ const contactPageSass = `@use '../../../app/styles/variables' as *
1614
+
1615
+ .contactPage
1616
+ min-height: 100vh
1617
+ display: flex
1618
+ flex-direction: column
1619
+
1620
+ .contactContent
1621
+ flex: 1
1622
+ padding: 2rem 0
1623
+
1624
+ +mobile
1625
+ padding: 1rem 0
1626
+
1627
+ h1
1628
+ text-align: center
1629
+ color: var(--primary-color)
1630
+ margin-bottom: 3rem
1631
+ font-size: 2.5rem
1632
+
1633
+ +mobile
1634
+ font-size: 2rem
1635
+ margin-bottom: 2rem
1636
+
1637
+ .container
1638
+ max-width: 1200px
1639
+ margin: 0 auto
1640
+ padding: 0 1rem
1641
+
1642
+ .contactGrid
1643
+ display: grid
1644
+ grid-template-columns: 1fr 1fr
1645
+ gap: 4rem
1646
+
1647
+ +mobile
1648
+ grid-template-columns: 1fr
1649
+ gap: 2rem
1650
+
1651
+ .contactInfo
1652
+ h2
1653
+ color: var(--primary-color)
1654
+ margin-bottom: 1rem
1655
+
1656
+ p
1657
+ color: var(--text-secondary)
1658
+ line-height: 1.6
1659
+ margin-bottom: 2rem
1660
+
1661
+ .infoItem
1662
+ margin-bottom: 2rem
1663
+
1664
+ h3
1665
+ color: var(--text-primary)
1666
+ margin-bottom: 0.5rem
1667
+ font-size: 1.1rem
1668
+
1669
+ p
1670
+ color: var(--text-secondary)
1671
+ margin: 0
1672
+
1673
+ .contactForm
1674
+ background: var(--surface-color)
1675
+ padding: 2rem
1676
+ border-radius: 8px
1677
+ box-shadow: var(--shadow)
1678
+
1679
+ +mobile
1680
+ padding: 1.5rem
1681
+
1682
+ h2
1683
+ color: var(--primary-color)
1684
+ margin-bottom: 1.5rem
1685
+
1686
+ .formGroup
1687
+ margin-bottom: 1.5rem
1688
+
1689
+ label
1690
+ display: block
1691
+ margin-bottom: 0.5rem
1692
+ color: var(--text-primary)
1693
+ font-weight: 500
1694
+
1695
+ input, textarea
1696
+ width: 100%
1697
+ padding: 0.75rem
1698
+ border: 1px solid var(--border-color)
1699
+ border-radius: 4px
1700
+ font-size: 1rem
1701
+ transition: border-color 0.2s ease
1702
+
1703
+ &:focus
1704
+ outline: none
1705
+ border-color: var(--primary-color)
1706
+
1707
+ +mobile
1708
+ padding: 0.6rem
1709
+ font-size: 0.9rem
1710
+
1711
+ textarea
1712
+ resize: vertical
1713
+ min-height: 120px
1714
+ `;
1715
+
1716
+ const contactIndexTs = `export { ContactPage } from './ui/ContactPage';
1717
+ `;
1718
+
1719
+ fs.writeFileSync('src/pages/contact/ui/ContactPage.tsx', contactPageTsx);
1720
+ fs.writeFileSync(
1721
+ 'src/pages/contact/ui/ContactPage.module.sass',
1722
+ contactPageSass
1723
+ );
1724
+ fs.writeFileSync('src/pages/contact/index.ts', contactIndexTs);
1725
+
1726
+ // 3. Widgets Layer
1727
+
1728
+ // Create Header widget
1729
+ const headerIndexTs = `export { Header } from './ui/Header';
1730
+ `;
1731
+ fs.writeFileSync('src/widgets/header/index.ts', headerIndexTs);
1732
+
1733
+ const headerTsx = `import React from 'react';
1734
+ import { Navigation } from '../../navigation';
1735
+ import styles from './Header.module.sass';
1736
+
1737
+ export const Header: React.FC = () => {
1738
+ return (
1739
+ <header className={styles.header}>
1740
+ <div className={styles.container}>
1741
+ <div className={styles.headerContent}>
1742
+ <div className={styles.logo}>
1743
+ <h2>${
1744
+ projectName.charAt(0).toUpperCase() + projectName.slice(1)
1745
+ }</h2>
1746
+ </div>
1747
+ <Navigation />
1748
+ </div>
1749
+ </div>
1750
+ </header>
1751
+ );
1752
+ };
1753
+ `;
1754
+ fs.writeFileSync('src/widgets/header/ui/Header.tsx', headerTsx);
1755
+
1756
+ const headerSass = `@use '../../../app/styles/variables' as *
1757
+
1758
+ .header
1759
+ background: var(--surface-color)
1760
+ border-bottom: 1px solid var(--border-color)
1761
+ box-shadow: var(--shadow)
1762
+ position: sticky
1763
+ top: 0
1764
+ z-index: 100
1765
+
1766
+ .container
1767
+ max-width: 1200px
1768
+ margin: 0 auto
1769
+ padding: 0 1rem
1770
+
1771
+ .headerContent
1772
+ display: flex
1773
+ justify-content: space-between
1774
+ align-items: center
1775
+ padding: 1rem 0
1776
+
1777
+ +mobile
1778
+ flex-direction: column
1779
+ gap: 1rem
1780
+ text-align: center
1781
+
1782
+ .logo
1783
+ h2
1784
+ color: var(--primary-color)
1785
+ font-size: 1.5rem
1786
+
1787
+ +mobile
1788
+ font-size: 1.3rem
1789
+ `;
1790
+ fs.writeFileSync('src/widgets/header/ui/Header.module.sass', headerSass);
1791
+
1792
+ // Create Navigation widget
1793
+ const navIndexTs = `export { Navigation } from './ui/Navigation';
1794
+ `;
1795
+ fs.writeFileSync('src/widgets/navigation/index.ts', navIndexTs);
1796
+
1797
+ const navTsx = `import React from 'react';
1798
+ import { Link, useLocation } from 'react-router-dom';
1799
+ import styles from './Navigation.module.sass';
1800
+
1801
+ interface NavItem {
1802
+ path: string;
1803
+ label: string;
1804
+ ariaLabel?: string;
1805
+ }
1806
+
1807
+ const navItems: NavItem[] = [
1808
+ { path: '/', label: 'Home', ariaLabel: 'Go to home page' },
1809
+ { path: '/about', label: 'About', ariaLabel: 'Learn about us' },
1810
+ { path: '/contact', label: 'Contact', ariaLabel: 'Contact us' },
1811
+ ];
1812
+
1813
+ export const Navigation: React.FC = () => {
1814
+ const location = useLocation();
1815
+
1816
+ const isActive = (path: string) => {
1817
+ if (path === '/') {
1818
+ return location.pathname === '/';
1819
+ }
1820
+ return location.pathname.startsWith(path);
1821
+ };
1822
+
1823
+ return (
1824
+ <nav className={styles.navigation} role="navigation" aria-label="Main navigation">
1825
+ <ul className={styles.navList}>
1826
+ {navItems.map(({ path, label, ariaLabel }) => (
1827
+ <li key={path} className={styles.navItem}>
1828
+ <Link
1829
+ to={path}
1830
+ className={\`\${styles.navLink} \${isActive(path) ? styles.active : ''}\`}
1831
+ aria-label={ariaLabel || label}
1832
+ aria-current={isActive(path) ? 'page' : undefined}
1833
+ >
1834
+ {label}
1835
+ </Link>
1836
+ </li>
1837
+ ))}
1838
+ </ul>
1839
+ </nav>
1840
+ );
1841
+ };
1842
+ `;
1843
+ fs.writeFileSync('src/widgets/navigation/ui/Navigation.tsx', navTsx);
1844
+
1845
+ // Create src/widgets/navigation/ui/Navigation.module.sass
1846
+ const navigationSass = `@use '../../../app/styles/variables' as *
1847
+
1848
+ .navigation
1849
+ position: relative
1850
+
1851
+ .navList
1852
+ display: flex
1853
+ list-style: none
1854
+ gap: 2rem
1855
+ margin: 0
1856
+ padding: 0
1857
+ align-items: center
1858
+
1859
+ +mobile
1860
+ flex-direction: column
1861
+ gap: 0
1862
+ background: var(--surface-color)
1863
+ border-radius: 8px
1864
+ box-shadow: var(--shadow)
1865
+ padding: 1rem 0
1866
+
1867
+ +tablet
1868
+ gap: 1.5rem
1869
+
1870
+ .navItem
1871
+ position: relative
1872
+
1873
+ +mobile
1874
+ width: 100%
1875
+
1876
+ .navLink
1877
+ text-decoration: none
1878
+ color: var(--text-primary)
1879
+ font-weight: 500
1880
+ font-size: 1rem
1881
+ padding: 0.75rem 1rem
1882
+ border-radius: 6px
1883
+ position: relative
1884
+ display: flex
1885
+ align-items: center
1886
+ transition: all 0.3s ease
1887
+ border: 2px solid transparent
1888
+
1889
+ // Focus styles for accessibility
1890
+ &:focus
1891
+ outline: none
1892
+ border-color: var(--primary-color)
1893
+ box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.2)
1894
+
1895
+ // Hover and active states
1896
+ &:hover
1897
+ color: var(--primary-color)
1898
+ background: var(--secondary-color)
1899
+ transform: translateY(-1px)
1900
+
1901
+ &:active
1902
+ transform: translateY(0)
1903
+
1904
+ // Active/current page indicator
1905
+ &.active
1906
+ color: var(--primary-color)
1907
+ background: var(--secondary-color)
1908
+ font-weight: 600
1909
+
1910
+ &::after
1911
+ content: ''
1912
+ position: absolute
1913
+ bottom: -2px
1914
+ left: 50%
1915
+ transform: translateX(-50%)
1916
+ width: 80%
1917
+ height: 2px
1918
+ background: var(--primary-color)
1919
+ border-radius: 1px
1920
+
1921
+ +mobile
1922
+ bottom: auto
1923
+ right: 1rem
1924
+ left: auto
1925
+ transform: none
1926
+ width: 4px
1927
+ height: 20px
1928
+
1929
+ +mobile
1930
+ display: block
1931
+ padding: 1rem 1.5rem
1932
+ width: 100%
1933
+ text-align: left
1934
+ border-radius: 0
1935
+
1936
+ &:hover
1937
+ background: var(--secondary-color)
1938
+ transform: none
1939
+ padding-left: 2rem
1940
+
1941
+ &:not(:last-child)
1942
+ border-bottom: 1px solid var(--border-color)
1943
+
1944
+ +tablet
1945
+ padding: 0.6rem 0.8rem
1946
+ font-size: 0.95rem
1947
+
1948
+ // Mobile menu toggle (if needed for future hamburger menu)
1949
+ .mobileToggle
1950
+ display: none
1951
+
1952
+ +mobile
1953
+ display: block
1954
+ background: none
1955
+ border: none
1956
+ color: var(--text-primary)
1957
+ font-size: 1.5rem
1958
+ cursor: pointer
1959
+ padding: 0.5rem
1960
+
1961
+ // Animation for smooth mobile menu appearance
1962
+ @keyframes slideDown
1963
+ from
1964
+ opacity: 0
1965
+ transform: translateY(-10px)
1966
+ to
1967
+ opacity: 1
1968
+ transform: translateY(0)
1969
+
1970
+ .navigation .navList
1971
+ +mobile
1972
+ animation: slideDown 0.3s ease-out
1973
+ `;
1974
+ fs.writeFileSync(
1975
+ 'src/widgets/navigation/ui/Navigation.module.sass',
1976
+ navigationSass
1977
+ );
1978
+
1979
+ // Create Footer widget
1980
+ const footerIndexTs = `export { Footer } from './ui/Footer';
1981
+ `;
1982
+ fs.writeFileSync('src/widgets/footer/index.ts', footerIndexTs);
1983
+
1984
+ const footerTsx = `import React from 'react';
1985
+ import styles from './Footer.module.sass';
1986
+
1987
+ export const Footer: React.FC = () => {
1988
+ return (
1989
+ <footer className={styles.footer}>
1990
+ <div className={styles.container}>
1991
+ <p>&copy; 2024 ${
1992
+ projectName.charAt(0).toUpperCase() + projectName.slice(1)
1993
+ }. Built with FSD Architecture.</p>
1994
+ </div>
1995
+ </footer>
1996
+ );
1997
+ };
1998
+ `;
1999
+ fs.writeFileSync('src/widgets/footer/ui/Footer.tsx', footerTsx);
2000
+
2001
+ const footerSass = `@use '../../../app/styles/variables' as *
2002
+
2003
+ .footer
2004
+ background: var(--secondary-color)
2005
+ border-top: 1px solid var(--border-color)
2006
+ padding: 2rem 0
2007
+ text-align: center
2008
+
2009
+ +mobile
2010
+ padding: 1.5rem 0
2011
+
2012
+ .container
2013
+ max-width: 1200px
2014
+ margin: 0 auto
2015
+ padding: 0 1rem
2016
+
2017
+ p
2018
+ color: var(--text-secondary)
2019
+ margin: 0
2020
+
2021
+ +mobile
2022
+ font-size: 0.9rem
2023
+ `;
2024
+ fs.writeFileSync('src/widgets/footer/ui/Footer.module.sass', footerSass);
2025
+
2026
+ // 4. Features Layer
2027
+
2028
+ // Create Auth feature
2029
+ const authIndexTs = `export { AuthFeature } from './ui/AuthFeature';
2030
+ `;
2031
+ fs.writeFileSync('src/features/auth/index.ts', authIndexTs);
2032
+
2033
+ const authFeatureTsx = `import React from 'react';
2034
+ import { useUser } from '../../../entities/user';
2035
+ import { Button } from '../../../shared/ui/button';
2036
+ import styles from './AuthFeature.module.sass';
2037
+
2038
+ export const AuthFeature: React.FC = () => {
2039
+ const { user, login, logout } = useUser();
2040
+
2041
+ return (
2042
+ <div className={styles.authFeature}>
2043
+ {user ? (
2044
+ <div className={styles.authUser}>
2045
+ <span>Welcome, {user.name}!</span>
2046
+ <Button onClick={logout} variant="secondary">
2047
+ Logout
2048
+ </Button>
2049
+ </div>
2050
+ ) : (
2051
+ <Button onClick={() => login({ name: 'Demo User', email: 'demo@example.com' })}>
2052
+ Login
2053
+ </Button>
2054
+ )}
2055
+ </div>
2056
+ );
2057
+ };
2058
+ `;
2059
+ fs.writeFileSync('src/features/auth/ui/AuthFeature.tsx', authFeatureTsx);
2060
+
2061
+ const authFeatureSass = `@use '../../../app/styles/variables' as *
2062
+
2063
+ .authFeature
2064
+ display: flex
2065
+ align-items: center
2066
+ gap: 1rem
2067
+
2068
+ +mobile
2069
+ flex-direction: column
2070
+ align-items: stretch
2071
+
2072
+ .authUser
2073
+ display: flex
2074
+ align-items: center
2075
+ gap: 1rem
2076
+
2077
+ +mobile
2078
+ flex-direction: column
2079
+ text-align: center
2080
+ `;
2081
+ fs.writeFileSync(
2082
+ 'src/features/auth/ui/AuthFeature.module.sass',
2083
+ authFeatureSass
2084
+ );
2085
+
2086
+ // Create Theme Toggle feature
2087
+ const themeToggleIndexTs = `export { ThemeToggle } from './ui/ThemeToggle';
2088
+ `;
2089
+ fs.writeFileSync('src/features/theme-toggle/index.ts', themeToggleIndexTs);
2090
+
2091
+ const themeToggleTsx = `import React, { useState, useEffect } from 'react';
2092
+ import { Button } from '../../../shared/ui/button';
2093
+
2094
+ export const ThemeToggle: React.FC = () => {
2095
+ const [isDark, setIsDark] = useState(() => {
2096
+ // Check if user has a stored preference
2097
+ const stored = localStorage.getItem('theme');
2098
+ if (stored) return stored === 'dark';
2099
+
2100
+ // Check system preference
2101
+ return window.matchMedia('(prefers-color-scheme: dark)').matches;
2102
+ });
2103
+
2104
+ useEffect(() => {
2105
+ // Apply theme on mount and when isDark changes
2106
+ document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
2107
+ localStorage.setItem('theme', isDark ? 'dark' : 'light');
2108
+ }, [isDark]);
2109
+
2110
+ const toggleTheme = () => {
2111
+ setIsDark(!isDark);
2112
+ };
2113
+
2114
+ return (
2115
+ <Button onClick={toggleTheme} variant="secondary">
2116
+ {isDark ? '☀️' : '🌙'} Toggle Theme
2117
+ </Button>
2118
+ );
2119
+ };
2120
+ `;
2121
+ fs.writeFileSync(
2122
+ 'src/features/theme-toggle/ui/ThemeToggle.tsx',
2123
+ themeToggleTsx
2124
+ );
2125
+
2126
+ // 5. Entities Layer
2127
+
2128
+ // Create User entity
2129
+ const userEntityIndexTs = `export { useUser } from './model/useUser';
2130
+ export { userModel } from './model/userSlice';
2131
+ export type { User } from './model/types';
2132
+ `;
2133
+ fs.writeFileSync('src/entities/user/index.ts', userEntityIndexTs);
2134
+
2135
+ const userTypesTs = `export interface User {
2136
+ id?: string;
2137
+ name: string;
2138
+ email: string;
2139
+ }
2140
+ `;
2141
+ fs.writeFileSync('src/entities/user/model/types.ts', userTypesTs);
2142
+
2143
+ const userSliceTs = `import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2144
+ import { User } from './types';
2145
+
2146
+ interface UserState {
2147
+ user: User | null;
2148
+ isLoading: boolean;
2149
+ }
2150
+
2151
+ const initialState: UserState = {
2152
+ user: null,
2153
+ isLoading: false,
2154
+ };
2155
+
2156
+ export const userSlice = createSlice({
2157
+ name: 'user',
2158
+ initialState,
2159
+ reducers: {
2160
+ setUser: (state, action: PayloadAction<User>) => {
2161
+ state.user = action.payload;
2162
+ state.isLoading = false;
2163
+ },
2164
+ clearUser: (state) => {
2165
+ state.user = null;
2166
+ state.isLoading = false;
2167
+ },
2168
+ setLoading: (state, action: PayloadAction<boolean>) => {
2169
+ state.isLoading = action.payload;
2170
+ },
2171
+ },
2172
+ });
2173
+
2174
+ export const { setUser, clearUser, setLoading } = userSlice.actions;
2175
+ export const userModel = {
2176
+ reducer: userSlice.reducer,
2177
+ actions: userSlice.actions,
2178
+ };
2179
+ `;
2180
+ fs.writeFileSync('src/entities/user/model/userSlice.ts', userSliceTs);
2181
+
2182
+ const useUserTs = `import { useDispatch, useSelector } from 'react-redux';
2183
+ import { RootState } from '../../../app/store';
2184
+ import { setUser, clearUser } from './userSlice';
2185
+ import { User } from './types';
2186
+
2187
+ export const useUser = () => {
2188
+ const dispatch = useDispatch();
2189
+ const { user, isLoading } = useSelector((state: RootState) => state.user);
2190
+
2191
+ const login = (userData: User) => {
2192
+ dispatch(setUser(userData));
2193
+ };
2194
+
2195
+ const logout = () => {
2196
+ dispatch(clearUser());
2197
+ };
2198
+
2199
+ return {
2200
+ user,
2201
+ isLoading,
2202
+ login,
2203
+ logout,
2204
+ };
2205
+ };
2206
+ `;
2207
+ fs.writeFileSync('src/entities/user/model/useUser.ts', useUserTs);
2208
+
2209
+ // Create Session entity
2210
+ const sessionEntityIndexTs = `export { sessionModel } from './model/sessionSlice';
2211
+ `;
2212
+ fs.writeFileSync('src/entities/session/index.ts', sessionEntityIndexTs);
2213
+
2214
+ const sessionSliceTs = `import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2215
+
2216
+ interface SessionState {
2217
+ isAuthenticated: boolean;
2218
+ token: string | null;
2219
+ }
2220
+
2221
+ const initialState: SessionState = {
2222
+ isAuthenticated: false,
2223
+ token: null,
2224
+ };
2225
+
2226
+ export const sessionSlice = createSlice({
2227
+ name: 'session',
2228
+ initialState,
2229
+ reducers: {
2230
+ setSession: (state, action: PayloadAction<{ token: string }>) => {
2231
+ state.token = action.payload.token;
2232
+ state.isAuthenticated = true;
2233
+ },
2234
+ clearSession: (state) => {
2235
+ state.token = null;
2236
+ state.isAuthenticated = false;
2237
+ },
2238
+ },
2239
+ });
2240
+
2241
+ export const { setSession, clearSession } = sessionSlice.actions;
2242
+ export const sessionModel = {
2243
+ reducer: sessionSlice.reducer,
2244
+ actions: sessionSlice.actions,
2245
+ };
2246
+ `;
2247
+ fs.writeFileSync(
2248
+ 'src/entities/session/model/sessionSlice.ts',
2249
+ sessionSliceTs
2250
+ );
2251
+
2252
+ // 6. Shared Layer
2253
+
2254
+ // Create Button component
2255
+ const buttonIndexTs = `export { Button } from './Button';
2256
+ export type { ButtonProps } from './Button';
2257
+ `;
2258
+ fs.writeFileSync('src/shared/ui/button/index.ts', buttonIndexTs);
2259
+
2260
+ const buttonTsx = `import React from 'react';
2261
+ import styles from './Button.module.sass';
2262
+
2263
+ export interface ButtonProps {
2264
+ children: React.ReactNode;
2265
+ onClick?: () => void;
2266
+ variant?: 'primary' | 'secondary' | 'outline';
2267
+ size?: 'small' | 'medium' | 'large';
2268
+ disabled?: boolean;
2269
+ type?: 'button' | 'submit' | 'reset';
2270
+ }
2271
+
2272
+ export const Button: React.FC<ButtonProps> = ({
2273
+ children,
2274
+ onClick,
2275
+ variant = 'primary',
2276
+ size = 'medium',
2277
+ disabled = false,
2278
+ type = 'button',
2279
+ }) => {
2280
+ const className = [
2281
+ styles.button,
2282
+ styles[\`button\${variant.charAt(0).toUpperCase() + variant.slice(1)}\`],
2283
+ styles[\`button\${size.charAt(0).toUpperCase() + size.slice(1)}\`]
2284
+ ].join(' ');
2285
+
2286
+ return (
2287
+ <button
2288
+ type={type}
2289
+ className={className}
2290
+ onClick={onClick}
2291
+ disabled={disabled}
2292
+ >
2293
+ {children}
2294
+ </button>
2295
+ );
2296
+ };
2297
+ `;
2298
+ fs.writeFileSync('src/shared/ui/button/Button.tsx', buttonTsx);
2299
+
2300
+ const buttonSass = `@use '../../../app/styles/variables' as *
2301
+
2302
+ .button
2303
+ display: inline-flex
2304
+ align-items: center
2305
+ justify-content: center
2306
+ border: none
2307
+ border-radius: 4px
2308
+ cursor: pointer
2309
+ font-weight: 500
2310
+ text-decoration: none
2311
+ transition: all 0.2s ease
2312
+ font-family: inherit
2313
+
2314
+ &:disabled
2315
+ opacity: 0.6
2316
+ cursor: not-allowed
2317
+
2318
+ // Variants
2319
+ .buttonPrimary
2320
+ @extend .button
2321
+ background: var(--primary-color)
2322
+ color: white
2323
+
2324
+ &:hover:not(:disabled)
2325
+ background: var(--primary-dark)
2326
+
2327
+ .buttonSecondary
2328
+ @extend .button
2329
+ background: var(--surface-color)
2330
+ color: var(--text-primary)
2331
+ border: 1px solid var(--border-color)
2332
+
2333
+ &:hover:not(:disabled)
2334
+ background: var(--secondary-color)
2335
+
2336
+ .buttonOutline
2337
+ @extend .button
2338
+ background: transparent
2339
+ color: var(--primary-color)
2340
+ border: 1px solid var(--primary-color)
2341
+
2342
+ &:hover:not(:disabled)
2343
+ background: var(--primary-color)
2344
+ color: white
2345
+
2346
+ // Sizes
2347
+ .buttonSmall
2348
+ padding: 0.5rem 1rem
2349
+ font-size: 0.875rem
2350
+
2351
+ +mobile
2352
+ padding: 0.4rem 0.8rem
2353
+ font-size: 0.8rem
2354
+
2355
+ .buttonMedium
2356
+ padding: 0.75rem 1.5rem
2357
+ font-size: 1rem
2358
+
2359
+ +mobile
2360
+ padding: 0.6rem 1.2rem
2361
+ font-size: 0.9rem
2362
+
2363
+ .buttonLarge
2364
+ padding: 1rem 2rem
2365
+ font-size: 1.125rem
2366
+
2367
+ +mobile
2368
+ padding: 0.8rem 1.6rem
2369
+ font-size: 1rem
2370
+ `;
2371
+ fs.writeFileSync('src/shared/ui/button/Button.module.sass', buttonSass);
2372
+
2373
+ // Create shared utilities
2374
+ const utilsIndexTs = `export { cn } from './cn';
2375
+ export { formatDate } from './formatDate';
2376
+ `;
2377
+ fs.writeFileSync('src/shared/lib/utils/index.ts', utilsIndexTs);
2378
+
2379
+ const cnTs = `/**
2380
+ * Utility function for conditional classNames
2381
+ */
2382
+ export function cn(...classes: (string | undefined | null | false)[]): string {
2383
+ return classes.filter(Boolean).join(' ');
2384
+ }
2385
+ `;
2386
+ fs.writeFileSync('src/shared/lib/utils/cn.ts', cnTs);
2387
+
2388
+ const formatDateTs = `/**
2389
+ * Simple date formatting utility
2390
+ */
2391
+ export function formatDate(date: Date | string): string {
2392
+ const d = new Date(date);
2393
+ return d.toLocaleDateString('en-US', {
2394
+ year: 'numeric',
2395
+ month: 'long',
2396
+ day: 'numeric',
2397
+ });
2398
+ }
2399
+ `;
2400
+ fs.writeFileSync('src/shared/lib/utils/formatDate.ts', formatDateTs);
2401
+
2402
+ // Create shared types
2403
+ const typesIndexTs = `export type { ApiResponse } from './api';
2404
+ export type { Theme } from './theme';
2405
+ `;
2406
+ fs.writeFileSync('src/shared/types/index.ts', typesIndexTs);
2407
+
2408
+ const apiTypesTs = `export interface ApiResponse<T = any> {
2409
+ data: T;
2410
+ message?: string;
2411
+ success: boolean;
2412
+ error?: string;
2413
+ }
2414
+ `;
2415
+ fs.writeFileSync('src/shared/types/api.ts', apiTypesTs);
2416
+
2417
+ const themeTypesTs = `export type Theme = 'light' | 'dark';
2418
+ `;
2419
+ fs.writeFileSync('src/shared/types/theme.ts', themeTypesTs);
2420
+
2421
+ // Create shared constants
2422
+ const constantsIndexTs = `export { API_ENDPOINTS } from './api';
2423
+ export { APP_CONFIG } from './app';
2424
+ `;
2425
+ fs.writeFileSync('src/shared/lib/constants/index.ts', constantsIndexTs);
2426
+
2427
+ const apiConstantsTs = `export const API_ENDPOINTS = {
2428
+ BASE_URL: process.env.NODE_ENV === 'production' ? '/api' : 'http://localhost:3001/api',
2429
+ AUTH: {
2430
+ LOGIN: '/auth/login',
2431
+ LOGOUT: '/auth/logout',
2432
+ PROFILE: '/auth/profile',
2433
+ },
2434
+ USERS: '/users',
2435
+ } as const;
2436
+ `;
2437
+ fs.writeFileSync('src/shared/lib/constants/api.ts', apiConstantsTs);
2438
+
2439
+ const appConstantsTs = `export const APP_CONFIG = {
2440
+ NAME: '${projectName}',
2441
+ VERSION: '1.0.0',
2442
+ COMPANY: ${companyName ? `'${companyName}'` : 'null'},
2443
+ } as const;
2444
+ `;
2445
+ fs.writeFileSync('src/shared/lib/constants/app.ts', appConstantsTs);
2446
+
2447
+ // Create README for FSD structure
2448
+ const readmeContent = `# ${
2449
+ projectName.charAt(0).toUpperCase() + projectName.slice(1)
2450
+ } - FSD Architecture
2451
+
2452
+ This project follows **Feature-Sliced Design (FSD)** architecture methodology.
2453
+
2454
+ ## 📁 Project Structure
2455
+
2456
+ \`\`\`
2457
+ src/
2458
+ ├── app/ # App layer - Application initialization
2459
+ │ ├── providers/ # App providers (routing, store, etc.)
2460
+ │ ├── store/ # Global store configuration
2461
+ │ └── styles/ # Global styles
2462
+ │
2463
+ ├── pages/ # Pages layer - Application routes
2464
+ │ └── home/ # Home page
2465
+ │ ├── ui/ # Page components
2466
+ │ ├── model/ # Page-specific state
2467
+ │ └── api/ # Page-specific API calls
2468
+ │
2469
+ ├── widgets/ # Widgets layer - Standalone UI blocks
2470
+ │ ├── header/ # Header widget
2471
+ │ ├── footer/ # Footer widget
2472
+ │ └── navigation/ # Navigation widget
2473
+ │
2474
+ ├── features/ # Features layer - User interactions
2475
+ │ ├── auth/ # Authentication feature
2476
+ │ └── theme-toggle/ # Theme switching feature
2477
+ │
2478
+ ├── entities/ # Entities layer - Business entities
2479
+ │ ├── user/ # User entity
2480
+ │ └── session/ # Session entity
2481
+ │
2482
+ └── shared/ # Shared layer - Reusable code
2483
+ ├── ui/ # UI components (Button, Input, etc.)
2484
+ ├── lib/ # Utilities and helpers
2485
+ ├── api/ # API configuration
2486
+ ├── config/ # App configuration
2487
+ ├── types/ # TypeScript types
2488
+ └── assets/ # Static assets
2489
+ \`\`\`
2490
+
2491
+ ## 🏗️ FSD Layers
2492
+
2493
+ 1. **App** - Application initialization, providers, global styles
2494
+ 2. **Pages** - Application routes and page-specific logic
2495
+ 3. **Widgets** - Large, standalone UI blocks
2496
+ 4. **Features** - User interactions with business value
2497
+ 5. **Entities** - Business entities and domain logic
2498
+ 6. **Shared** - Reusable code without business logic
2499
+
2500
+ ## 📋 FSD Rules
2501
+
2502
+ - **Layers can only import from layers below them**
2503
+ - **Each slice has a public API (index.ts)**
2504
+ - **Segments organize code by technical purpose (ui, model, api, lib)**
2505
+ - **Features are isolated and reusable**
2506
+
2507
+ ## 🚀 Getting Started
2508
+
2509
+ 1. Install dependencies: \`npm install\`
2510
+ 2. Start development: \`npm run dev\`
2511
+ 3. Build for production: \`npm run build\`
2512
+
2513
+ ## 📚 Learn More
2514
+
2515
+ - [Feature-Sliced Design Documentation](https://feature-sliced.design/)
2516
+ - [FSD Examples](https://github.com/feature-sliced/examples)
2517
+ `;
2518
+ fs.writeFileSync('README.md', readmeContent);
2519
+
2520
+ // 7. Create Web Component files for Module Federation
2521
+
2522
+ // Create src/shared/magmonium directory
2523
+ fs.mkdirSync('src/shared/magmonium', { recursive: true });
2524
+
2525
+ // Create main.component.tsx
2526
+ const mainComponentTsx = `import React from 'react';
2527
+ import { App } from '../../app';
2528
+
2529
+ export const MainComponent: React.FC = () => {
2530
+ return <App />;
2531
+ };
2532
+
2533
+ export default MainComponent;
2534
+ `;
2535
+ fs.writeFileSync('src/shared/magmonium/main.component.tsx', mainComponentTsx);
2536
+
2537
+ // Create main.web-component.tsx
2538
+ const camelCaseProjectName = projectName
2539
+ .split('-')
2540
+ .map((word, index) =>
2541
+ index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)
2542
+ )
2543
+ .join('');
2544
+
2545
+ const mainWebComponentTsx = `import React, { lazy, Suspense } from "react";
2546
+ import { createRoot, Root } from "react-dom/client";
2547
+ import { MainComponent } from "./main.component";
2548
+
2549
+ const LazyMainComponent = lazy(() =>
2550
+ import("./main.component").then((module) => ({
2551
+ default: module.MainComponent,
2552
+ }))
2553
+ );
2554
+
2555
+ class ${camelCaseProjectName}WebComponent extends HTMLElement {
2556
+ private root: Root | null = null;
2557
+
2558
+ connectedCallback() {
2559
+ const mountPoint = document.createElement("div");
2560
+ this.appendChild(mountPoint);
2561
+
2562
+ this.root = createRoot(mountPoint);
2563
+ this.root.render(
2564
+ React.createElement(
2565
+ Suspense,
2566
+ { fallback: React.createElement("div", null, "Loading...") },
2567
+ React.createElement(LazyMainComponent)
2568
+ )
2569
+ );
2570
+ }
2571
+
2572
+ disconnectedCallback() {
2573
+ if (this.root) {
2574
+ this.root.unmount();
2575
+ this.root = null;
2576
+ }
2577
+ }
2578
+ }
2579
+
2580
+ if (!customElements.get("mag-${
2581
+ companyName || 'app'
2582
+ }-${projectName}-main-app")) {
2583
+ customElements.define("mag-${
2584
+ companyName || 'app'
2585
+ }-${projectName}-main-app", ${camelCaseProjectName}WebComponent);
2586
+ }
2587
+
2588
+ export default ${camelCaseProjectName}WebComponent;
2589
+ `;
2590
+ fs.writeFileSync(
2591
+ 'src/shared/magmonium/main.web-component.tsx',
2592
+ mainWebComponentTsx
2593
+ );
2594
+ }
2595
+
2596
+ module.exports = createSourceFiles;