@arc-js/initiator 0.0.81 → 0.0.82

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.
package/README.md CHANGED
@@ -2,13 +2,430 @@
2
2
 
3
3
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4
4
  ![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-007ACC)
5
- ![Browser](https://img.shields.io/badge/browser-compatible-green)
6
- ![Node.js](https://img.shields.io/badge/Node.js-18+-339933)
5
+ ![React](https://img.shields.io/badge/React-18+-61DAFB)
6
+ ![React Router](https://img.shields.io/badge/React%20Router-6+-CA4245)
7
+
8
+ **@arc-js/initiator** est un plugin d'initialisation intelligent pour les applications React avec TypeScript/Javascript. Il génère automatiquement les fichiers de configuration, de routage et d'internationalisation basés sur la structure de votre projet.
9
+
10
+ ## ✨ Fonctionnalités Principales
11
+
12
+ ### 🗺️ Génération Automatique
13
+ - **Génération automatique des routes** à partir de la structure du système de fichiers
14
+ - **Configuration modulaire** avec détection automatique des modules
15
+ - **Internationalisation automatisée** avec extraction des clés de traduction
16
+ - **Fichiers de configuration** générés dynamiquement
17
+
18
+ ### ⚙️ Initialisation Intelligente
19
+ - **Détection automatique** des fichiers de pages et modules
20
+ - **Génération de fichiers TypeScript** typesafe
21
+ - **Support des layouts hiérarchiques** avec héritage automatique
22
+ - **Configuration minimale** requise
23
+
24
+ ### 📁 Structure de Projet
25
+ - **Organisation modulaire** naturelle
26
+ - **Support des pages spéciales** (layout, error, 404)
27
+ - **Routes dynamiques** avec paramètres
28
+ - **Modules indépendants** avec leur propre configuration
29
+
30
+ ## 📦 Installation
31
+
32
+ ### Installation globale (recommandée)
33
+ ```bash
34
+ npm install -g @arc-js/initiator
35
+ # ou
36
+ yarn global add @arc-js/initiator
37
+ # ou
38
+ pnpm add -g @arc-js/initiator
39
+ ```
40
+
41
+ ### Installation locale
42
+ ```bash
43
+ npm install @arc-js/initiator
44
+ # ou
45
+ yarn add @arc-js/initiator
46
+ # ou
47
+ pnpm add @arc-js/initiator
48
+ ```
49
+
50
+ ## 🚀 Utilisation Rapide
51
+
52
+ ### Commande de base
53
+ ```bash
54
+ # Depuis la racine de votre projet
55
+ arc-init
56
+ # ou
57
+ npx @arc-js/initiator
58
+ ```
59
+
60
+ ### Options disponibles
61
+ ```bash
62
+ # Initialiser avec un répertoire spécifique
63
+ arc-init --dir ./mon-projet
64
+
65
+ # Forcer la régénération des fichiers
66
+ arc-init --force
67
+
68
+ # Mode silencieux (moins de logs)
69
+ arc-init --quiet
70
+
71
+ # Afficher l'aide
72
+ arc-init --help
73
+ ```
74
+
75
+ ### Structure de projet générée
76
+ ```
77
+ src/
78
+ ├── auto-config.ts # Configuration générée
79
+ ├── auto-intl.ts # Internationalisation générée
80
+ ├── auto-routes.tsx # Routes générées
81
+ ├── config.json # Configuration racine
82
+ ├── locales/
83
+ │ ├── en.json # Traductions anglais
84
+ │ └── fr.json # Traductions français
85
+ ├── pages/
86
+ │ ├── _layout.tsx # Layout racine
87
+ │ ├── _error.tsx # Page d'erreur
88
+ │ ├── _404.tsx # Page 404
89
+ │ └── index.tsx # Page d'accueil
90
+ └── modules/
91
+ └── example/
92
+ ├── config.json # Configuration du module
93
+ ├── locales/
94
+ │ ├── en.json # Traductions module
95
+ │ └── fr.json # Traductions module
96
+ └── pages/
97
+ └── index.tsx # Page du module
98
+ ```
99
+
100
+ ## 🔧 Fonctionnalités Détaillées
101
+
102
+ ### 1. Génération de Routes
103
+ Le plugin scanne automatiquement vos dossiers `pages/` et `modules/*/pages/` pour :
104
+ - **Créer des routes React Router** automatiquement
105
+ - **Gérer les layouts hiérarchiques**
106
+ - **Supporter les pages d'erreur spécifiques**
107
+ - **Générer des composants lazy-loaded**
108
+
109
+ ### 2. Internationalisation
110
+ Extraction automatique des clés de traduction :
111
+ - **Scan des fichiers source** pour les appels `t()`
112
+ - **Détection des modules** avec fichiers de traduction
113
+ - **Génération des imports dynamiques**
114
+ - **Support multi-langue**
115
+
116
+ ### 3. Configuration
117
+ Génération centralisée de configuration :
118
+ - **Configuration racine** depuis `config.json`
119
+ - **Configuration des modules** depuis `modules/*/config.json`
120
+ - **Fichier TypeScript** avec imports dynamiques
121
+
122
+ ## 📚 API du Plugin
123
+
124
+ ### Fonction principale
125
+ ```typescript
126
+ import init from '@arc-js/initiator';
127
+
128
+ // Initialisation par défaut (utilise __dirname)
129
+ init();
130
+
131
+ // Avec répertoire personnalisé
132
+ init('/chemin/vers/mon/projet');
133
+ ```
134
+
135
+ ### Classes exportées
136
+ ```typescript
137
+ import {
138
+ TranslationGenerator,
139
+ RouteGenerator,
140
+ ConfigGenerator
141
+ } from '@arc-js/initiator';
142
+
143
+ // Utilisation avancée
144
+ const translationGen = new TranslationGenerator(config);
145
+ const routeGen = new RouteGenerator(config);
146
+ const configGen = new ConfigGenerator(config);
147
+ ```
148
+
149
+ ### Interfaces TypeScript
150
+ ```typescript
151
+ import type {
152
+ TranslationConfig,
153
+ RouteConfig,
154
+ ConfigGeneratorOptions,
155
+ TranslationKey,
156
+ RouteFile
157
+ } from '@arc-js/initiator';
158
+ ```
159
+
160
+ ## 🎯 Exemples d'Utilisation
161
+
162
+ ### Exemple 1 : Script d'initialisation
163
+ ```javascript
164
+ // scripts/init.js
165
+ import init from '@arc-js/initiator';
166
+
167
+ // Initialiser avec le répertoire du projet
168
+ init(process.cwd());
169
+
170
+ console.log('✅ Initialisation terminée !');
171
+ ```
172
+
173
+ ### Exemple 2 : Personnalisation avancée
174
+ ```typescript
175
+ // scripts/custom-init.ts
176
+ import { RouteGenerator } from '@arc-js/initiator';
177
+
178
+ const customConfig = {
179
+ srcDir: './src',
180
+ modulesDir: './src/modules',
181
+ pagesDir: './src/views', // Dossier personnalisé
182
+ outputFile: './src/generated/routes.tsx',
183
+ layoutFileName: 'layout',
184
+ errorFileName: 'error-page',
185
+ notFoundFileName: 'not-found-page'
186
+ };
187
+
188
+ const generator = new RouteGenerator(customConfig);
189
+ await generator.generate();
190
+ ```
191
+
192
+ ### Exemple 3 : Intégration avec un build personnalisé
193
+ ```json
194
+ {
195
+ "scripts": {
196
+ "dev": "vite",
197
+ "build": "npm run generate && vite build",
198
+ "generate": "node scripts/generate-all.js",
199
+ "generate:routes": "node scripts/generate-routes.js",
200
+ "generate:intl": "node scripts/generate-intl.js",
201
+ "generate:config": "node scripts/generate-config.js"
202
+ }
203
+ }
204
+ ```
205
+
206
+ ## 🔧 Configuration Avancée
207
+
208
+ ### Configuration de la traduction
209
+ ```typescript
210
+ const translationConfig = {
211
+ srcDir: './src',
212
+ supportedLocales: ['en', 'fr', 'es'], // Langues supportées
213
+ outputFile: './src/auto-intl.ts',
214
+ modulesDir: './src/modules',
215
+ localesDir: './src/locales'
216
+ };
217
+ ```
218
+
219
+ ### Configuration du routage
220
+ ```typescript
221
+ const routeConfig = {
222
+ srcDir: './src',
223
+ modulesDir: './src/modules',
224
+ pagesDir: './src/pages', // Ou 'views', 'screens', etc.
225
+ outputFile: './src/auto-routes.tsx',
226
+ layoutFileName: '_layout', // Fichier de layout
227
+ errorFileName: '_error', // Fichier d'erreur
228
+ notFoundFileName: '_404' // Fichier 404
229
+ };
230
+ ```
231
+
232
+ ### Fichier config.json racine
233
+ ```json
234
+ {
235
+ "name": "Mon Application",
236
+ "version": "1.0.0",
237
+ "description": "Description de l'application",
238
+ "author": "Votre Nom",
239
+ "defaultLocale": "fr",
240
+ "supportedLocales": ["fr", "en"],
241
+ "apiUrl": "https://api.example.com",
242
+ "features": {
243
+ "auth": true,
244
+ "analytics": false,
245
+ "pwa": true
246
+ }
247
+ }
248
+ ```
249
+
250
+ ### Fichier config.json de module
251
+ ```json
252
+ {
253
+ "name": "Module Admin",
254
+ "description": "Module d'administration",
255
+ "author": "Équipe Admin",
256
+ "version": "1.0.0",
257
+ "routePrefix": "/admin",
258
+ "isEnabled": true,
259
+ "dependencies": ["auth"],
260
+ "permissions": ["admin", "superuser"]
261
+ }
262
+ ```
263
+
264
+ ## 📁 Conventions de Fichiers
265
+
266
+ ### Pages spéciales
267
+ | Fichier | Description | Route générée |
268
+ |---------|-------------|---------------|
269
+ | `_layout.tsx` | Layout du dossier | Non accessible directement |
270
+ | `_error.tsx` | Page d'erreur | Utilisée comme errorElement |
271
+ | `_404.tsx` | Page non trouvée | Route catch-all |
272
+ | `[param].tsx` | Route paramétrée | `/:param` |
273
+ | `[...slug].tsx` | Route catch-all | `/*` |
274
+ | `index.tsx` | Page d'index | `/` ou `/dossier/` |
275
+
276
+ ### Structure de module
277
+ ```
278
+ modules/
279
+ └── nom-du-module/
280
+ ├── config.json # Configuration du module
281
+ ├── locales/ # Traductions du module
282
+ │ ├── en.json
283
+ │ └── fr.json
284
+ ├── pages/ # Pages du module
285
+ │ ├── _layout.tsx # Layout du module
286
+ │ ├── _error.tsx # Erreur du module
287
+ │ ├── _404.tsx # 404 du module
288
+ │ └── index.tsx # Page d'accueil du module
289
+ └── components/ # Composants du module (optionnel)
290
+ ```
291
+
292
+ ## 🔄 Workflow de Développement
293
+
294
+ ### 1. Initialisation du projet
295
+ ```bash
296
+ # Créer un nouveau projet
297
+ npm create vite@latest mon-app -- --template react-ts
298
+ cd mon-app
299
+
300
+ # Installer l'initiator
301
+ npm install @arc-js/initiator
302
+
303
+ # Générer la structure initiale
304
+ npx @arc-js/initiator
305
+ ```
306
+
307
+ ### 2. Ajout d'un nouveau module
308
+ ```bash
309
+ # Créer la structure du module
310
+ mkdir -p src/modules/admin/{locales,pages,components}
311
+
312
+ # Ajouter les fichiers de base
313
+ touch src/modules/admin/config.json
314
+ touch src/modules/admin/pages/index.tsx
315
+ touch src/modules/admin/locales/fr.json
316
+
317
+ # Régénérer les fichiers
318
+ npx @arc-js/initiator
319
+ ```
320
+
321
+ ### 3. Développement avec hot-reload
322
+ ```bash
323
+ # Démarrer le serveur de développement
324
+ npm run dev
325
+
326
+ # Dans un autre terminal, surveiller les changements
327
+ npx @arc-js/initiator --watch
328
+ ```
329
+
330
+ ## 🛠️ Intégration avec d'autres outils
331
+
332
+ ### Avec Vite
333
+ ```javascript
334
+ // vite.config.js
335
+ import { defineConfig } from 'vite';
336
+ import react from '@vitejs/plugin-react';
337
+
338
+ export default defineConfig({
339
+ plugins: [react()],
340
+ build: {
341
+ rollupOptions: {
342
+ external: ['@arc-js/initiator']
343
+ }
344
+ }
345
+ });
346
+ ```
347
+
348
+ ### Avec Next.js (Adaptation)
349
+ ```javascript
350
+ // next.config.js
351
+ const { generateRoutes } = require('@arc-js/initiator/adapters/next');
352
+
353
+ module.exports = {
354
+ async rewrites() {
355
+ const routes = await generateRoutes();
356
+ return routes.map(route => ({
357
+ source: route.path,
358
+ destination: route.filePath
359
+ }));
360
+ }
361
+ };
362
+ ```
363
+
364
+ ### Avec Webpack
365
+ ```javascript
366
+ // webpack.config.js
367
+ const { GenerateRoutesPlugin } = require('@arc-js/initiator/webpack');
368
+
369
+ module.exports = {
370
+ plugins: [
371
+ new GenerateRoutesPlugin({
372
+ watch: process.env.NODE_ENV === 'development'
373
+ })
374
+ ]
375
+ };
376
+ ```
377
+
378
+ ## 🐛 Dépannage
379
+
380
+ ### Problèmes courants
381
+
382
+ 1. **"Cannot find module"**
383
+ ```bash
384
+ # Réinstaller le plugin
385
+ npm install @arc-js/initiator
386
+ ```
387
+
388
+ 2. **Fichiers non générés**
389
+ ```bash
390
+ # Forcer la régénération
391
+ npx @arc-js/initiator --force
392
+
393
+ # Vérifier les permissions
394
+ chmod +x node_modules/.bin/arc-init
395
+ ```
396
+
397
+ 3. **Erreurs TypeScript**
398
+ ```bash
399
+ # Vérifier les types
400
+ npm run type-check
401
+
402
+ # Régénérer les fichiers
403
+ npx @arc-js/initiator
404
+ ```
405
+
406
+ ### Logs de débogage
407
+ ```bash
408
+ # Activer les logs détaillés
409
+ DEBUG=arc-js:* npx @arc-js/initiator
410
+
411
+ # Sauvegarder les logs dans un fichier
412
+ npx @arc-js/initiator 2>&1 | tee init.log
413
+ ```
7
414
 
8
415
  ## 📄 Licence
9
416
 
10
417
  MIT License - Voir le fichier [LICENSE](LICENSE) pour plus de détails.
11
418
 
419
+ ## 🤝 Contribution
420
+
421
+ Les contributions sont les bienvenues ! Pour contribuer :
422
+
423
+ 1. Fork le projet
424
+ 2. Créer une branche (`git checkout -b feature/amazing-feature`)
425
+ 3. Commit vos changements (`git commit -m 'Add amazing feature'`)
426
+ 4. Push vers la branche (`git push origin feature/amazing-feature`)
427
+ 5. Ouvrir une Pull Request
428
+
12
429
  ## 🐛 Signaler un Bug
13
430
 
14
431
  Envoyez nous un mail à l'adresse `contact.inicode@gmail.com` pour :
@@ -18,4 +435,6 @@ Envoyez nous un mail à l'adresse `contact.inicode@gmail.com` pour :
18
435
 
19
436
  ---
20
437
 
438
+ **@arc-js/initiator** - Le plugin d'initialisation intelligent pour React et TypeScript.
439
+
21
440
  *Développé par l'équipe INICODE*
package/index.js CHANGED
@@ -194801,7 +194801,7 @@ class RouteGenerator {
194801
194801
  srcDir: config.srcDir || pajoExports.Pajo.join(dirname, 'src') || '',
194802
194802
  modulesDir: config.modulesDir || pajoExports.Pajo.join(dirname, 'src\\modules') || '',
194803
194803
  pagesDir: config.pagesDir || pajoExports.Pajo.join(dirname, 'src\\pages') || '',
194804
- outputFile: config.outputFile || pajoExports.Pajo.join(dirname, 'src\\auto-routes.ts') || '',
194804
+ outputFile: config.outputFile || pajoExports.Pajo.join(dirname, 'src\\auto-routes.tsx') || '',
194805
194805
  layoutFileName: config.layoutFileName || '_layout',
194806
194806
  errorFileName: config.errorFileName || '_error',
194807
194807
  notFoundFileName: config.notFoundFileName || '_404'
package/index.min.js CHANGED
@@ -385,5 +385,5 @@ ${0<i.length?i:" // No modules with config.json found"}
385
385
  }
386
386
  };
387
387
 
388
- export default configs;`}}function ConfigInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$2){new ConfigGenerator({},e).generate().then(()=>{}).catch(e=>{})})}let __filename$1=url.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&"SCRIPT"===_documentCurrentScript.tagName.toUpperCase()&&_documentCurrentScript.src||new URL("index.js",document.baseURI).href),__dirname$1=path.dirname(__filename$1);class RouteGenerator{constructor(e={},t=__dirname$1){this.routeFiles=[],this.modules=new Set,this.config={srcDir:e.srcDir||pajoExports.Pajo.join(t,"src")||"",modulesDir:e.modulesDir||pajoExports.Pajo.join(t,"src\\modules")||"",pagesDir:e.pagesDir||pajoExports.Pajo.join(t,"src\\pages")||"",outputFile:e.outputFile||pajoExports.Pajo.join(t,"src\\auto-routes.ts")||"",layoutFileName:e.layoutFileName||"_layout",errorFileName:e.errorFileName||"_error",notFoundFileName:e.notFoundFileName||"_404"}}generate(){return __awaiter(this,void 0,void 0,function*(){yield this.findRouteFiles(),yield this.generateAutoRoutesFile()})}findRouteFiles(){return __awaiter(this,void 0,void 0,function*(){var e;if(this.routeFiles=[],yield this.scanDirectoryForRoutes(this.config.pagesDir),fs.existsSync(this.config.modulesDir))for(e of fs.readdirSync(this.config.modulesDir,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)){var t=path.join(this.config.modulesDir,e,"pages");fs.existsSync(t)&&(this.modules.add(e),yield this.scanDirectoryForRoutes(t,e))}})}scanDirectoryForRoutes(i,a){return __awaiter(this,void 0,void 0,function*(){try{var e;for(e of fs.readdirSync(i,{withFileTypes:!0})){var t,r,n=path.join(i,e.name);"node_modules"===e.name||"dist"===e.name||"build"===e.name||e.name.startsWith(".")||(e.isDirectory()?yield this.scanDirectoryForRoutes(n,a):e.isFile()&&(t=path.extname(e.name).toLowerCase(),[".tsx",".jsx"].includes(t))&&(r=path.basename(e.name,t))!==this.config.layoutFileName&&r!==this.config.errorFileName&&r!==this.config.notFoundFileName&&(yield this.processRouteFile(n,a)))}}catch(e){}})}processRouteFile(o,s){return __awaiter(this,void 0,void 0,function*(){try{var e=this.convertFilePathToRoutePath(o,s),t=this.extractComponentName(o,s),r=this.findLayoutComponent(o,s),n=this.findErrorComponent(o,s),i=this.findNotFoundComponent(o,s),a={filePath:o,relativePath:path.relative(this.config.srcDir,o),routePath:e,componentName:t,layoutComponent:r,errorComponent:n,notFoundComponent:i,moduleName:s};this.routeFiles.push(a)}catch(e){}})}convertFilePathToRoutePath(e,t){let r=e;return r=r.replace(this.config.srcDir,""),t?(e=`modules${path.sep}${t}${path.sep}pages`,r.includes(e)&&(r="/"+t+(r=r.substring(r.indexOf(e)+e.length)))):r.includes("pages")&&(r=r.substring(r.indexOf("pages")+"pages".length)),"/"===(r=(r=(r=(r=(r=r.replace(/\.(tsx|jsx)$/,"")).replace(/\\/g,"/")).endsWith("/index")?r.replace(/\/index$/,""):r).replace(/\[([^\]]+)\]/g,"{$1}")).startsWith("/")?r:"/"+r)||"//"===r?"/":r}extractComponentName(e,t){var r=path.basename(e,path.extname(e)),e=path.dirname(e).split(path.sep);let i=0;if(t){let n=path.sep+"modules"+path.sep+t+path.sep+"pages";i=e.findIndex((e,t,r)=>r.slice(0,t+1).join(path.sep).endsWith(n))+1}else{let n=path.sep+"pages";i=e.findIndex((e,t,r)=>r.slice(0,t+1).join(path.sep).endsWith(n))+1}i<0&&(i=0);e=e.slice(i);let n=t?this.toPascalCase(t):"",a=(e.forEach(e=>{e&&"pages"!==e&&(n+=this.toPascalCase(e))}),r);(a=r.startsWith("{")&&r.endsWith("}")?(t=r.substring(1,r.length-1),this.toPascalCase(t)+"Params"):this.toPascalCase(r)).endsWith("Page")||(a+="Page");return["Layout","ErrorBoundary","NotFound"].includes(a)&&(a+="Component"),n+a}toPascalCase(e){return e?e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(""):""}findLayoutComponent(e,t){let r=path.dirname(e);for(;r!==this.config.srcDir&&r!==path.dirname(this.config.srcDir);){var n=path.join(r,this.config.layoutFileName+".tsx");if(fs.existsSync(n))return this.generateComponentName(n,t,"Layout");if(t){n=path.join(this.config.modulesDir,t);if(r===n)break}r=path.dirname(r)}e=path.join(this.config.pagesDir,this.config.layoutFileName+".tsx");if(fs.existsSync(e))return"Layout"}findErrorComponent(e,t){let r=path.dirname(e);for(;r!==this.config.srcDir&&r!==path.dirname(this.config.srcDir);){var n=path.join(r,this.config.errorFileName+".tsx");if(fs.existsSync(n))return this.generateComponentName(n,t,"ErrorBoundary");if(t){n=path.join(this.config.modulesDir,t);if(r===n)break}r=path.dirname(r)}e=path.join(this.config.pagesDir,this.config.errorFileName+".tsx");if(fs.existsSync(e))return"ErrorBoundary"}findNotFoundComponent(e,t){var r;if(t)return r=path.join(this.config.modulesDir,t,"pages"),r=path.join(r,this.config.notFoundFileName+".tsx"),fs.existsSync(r)?this.generateComponentName(r,t,"NotFound"):void 0}generateComponentName(e,t,r){if(!t)return r;var n=path.basename(e,path.extname(e)),e=path.dirname(e),i=path.join(this.config.modulesDir,t,"pages"),i=path.relative(i,e);let a=this.toPascalCase(t);return i&&"."!==i&&i.split(path.sep).filter(e=>e&&"."!==e).forEach(e=>{a+=this.toPascalCase(e)}),n!==this.config.layoutFileName&&n!==this.config.errorFileName&&n!==this.config.notFoundFileName&&(a+=this.toPascalCase(n)),a+r}generateAutoRoutesFile(){return __awaiter(this,void 0,void 0,function*(){var e=path.dirname(this.config.outputFile),e=(fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),this.generateFileContent());fs.writeFileSync(this.config.outputFile,e,"utf-8")})}getRelativeImportPath(e){var t=path.dirname(this.config.outputFile);let r=path.relative(t,e).replace(/\\/g,"/");return r=(r=r.startsWith(".")||r.startsWith("/")?r:"./"+r).replace(/\.(tsx|jsx)$/,"")}generateFileContent(){let c=new Set,r=["import { lazy } from 'react';","import type { RouteObject } from 'react-router-dom';",""];var e=path.join(this.config.pagesDir,this.config.layoutFileName+".tsx"),t=path.join(this.config.pagesDir,this.config.errorFileName+".tsx"),n=path.join(this.config.pagesDir,this.config.notFoundFileName+".tsx");fs.existsSync(e)&&(e=this.getRelativeImportPath(e),r.push(`const Layout = lazy(() => import('${e}'));`),c.add("Layout")),fs.existsSync(t)&&(e=this.getRelativeImportPath(t),r.push(`const ErrorBoundary = lazy(() => import('${e}'));`),c.add("ErrorBoundary")),fs.existsSync(n)&&(t=this.getRelativeImportPath(n),r.push(`const NotFound = lazy(() => import('${t}'));`),c.add("NotFound")),r.push("");let l=new Map,i=(e,t=0,s)=>{if(fs.existsSync(e)){let o=e=>{try{var t;for(t of fs.readdirSync(e,{withFileTypes:!0})){var r,n,i,a=path.join(e,t.name);t.isDirectory()?o(a):t.isFile()&&(r=path.extname(t.name).toLowerCase(),![".tsx",".jsx"].includes(r)||(n=path.basename(t.name,r))!==this.config.layoutFileName&&n!==this.config.errorFileName&&n!==this.config.notFoundFileName||(i=this.generateComponentName(a,s,n===this.config.layoutFileName?"Layout":n===this.config.errorFileName?"ErrorBoundary":"NotFound"),c.has(i))||(l.set(a,i),c.add(i)))}}catch(e){}};o(e)}},o=(i(this.config.pagesDir,!1),this.modules.forEach(e=>{var t=path.join(this.config.modulesDir,e,"pages");fs.existsSync(t)&&i(t,!0,e)}),l.forEach((e,t)=>{t=this.getRelativeImportPath(t);r.push(`const ${e} = lazy(() => import('${t}'));`)}),0<l.size&&r.push(""),this.routeFiles.forEach(e=>{var t=this.getRelativeImportPath(e.filePath);r.push(`const ${e.componentName} = lazy(() => import('${t}'));`),c.add(e.componentName)}),r.push(""),["export const routes: RouteObject[] = ["]),s=this.routeFiles.sort((e,t)=>"/"===e.routePath?-1:"/"===t.routePath?1:!e.moduleName&&t.moduleName?-1:e.moduleName&&!t.moduleName?1:e.moduleName===t.moduleName?e.routePath.localeCompare(t.routePath):0),_=void 0,a=(s.forEach((e,t)=>{e.moduleName!==_&&(void 0!==_&&o.push(""),e.moduleName&&o.push(` // ${e.moduleName} module routes`),_=e.moduleName);var r,n=[" {"];n.push(` path: '${e.routePath}',`);let i=e.layoutComponent,a=((i=!i&&e.moduleName&&(r=path.join(this.config.modulesDir,e.moduleName,"pages",this.config.layoutFileName+".tsx"),fs.existsSync(r))?this.generateComponentName(r,e.moduleName,"Layout"):i)?n.push(` element: <${i}><${e.componentName} /></${i}>,`):n.push(` element: <${e.componentName} />,`),e.errorComponent);(a=!a&&e.moduleName&&(r=path.join(this.config.modulesDir,e.moduleName,"pages",this.config.errorFileName+".tsx"),fs.existsSync(r))?this.generateComponentName(r,e.moduleName,"ErrorBoundary"):a)&&n.push(` errorElement: <${a} />`),n[n.length-1].endsWith(",")&&(n[n.length-1]=n[n.length-1].slice(0,-1)),n.push(" }"),t<s.length-1&&(n[n.length-1]+=","),o.push(n.join("\n"))}),new Set);return l.forEach((e,t)=>{var r;path.basename(t,path.extname(t))===this.config.notFoundFileName&&-1!==(r=(t=t.split(path.sep)).indexOf("modules"))&&r+1<t.length&&(t=t[r+1],a.has(t)||(a.add(t),o[o.length-1].endsWith(",")&&(o[o.length-1]=o[o.length-1].slice(0,-1)),o.push(","),o.push(" {"),o.push(` path: '/${t}/*',`),o.push(` element: <${e} />`),o.push(" }")))}),c.has("NotFound")&&(o[o.length-1].endsWith(",")&&(o[o.length-1]=o[o.length-1].slice(0,-1)),o.push(","),o.push(" {"),o.push(" path: '*',"),o.push(" element: <NotFound />"),o.push(" }")),o.push("];"),o.push(""),o.push("export default routes;"),[...r,"",...o].join("\n")}}function RouteInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$1){e=new RouteGenerator({},e);try{yield e.generate()}catch(e){}})}function index(e=__dirname){TranslationInitiator(e),ConfigInitiator(e),RouteInitiator(e)}module.exports=index;
388
+ export default configs;`}}function ConfigInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$2){new ConfigGenerator({},e).generate().then(()=>{}).catch(e=>{})})}let __filename$1=url.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&"SCRIPT"===_documentCurrentScript.tagName.toUpperCase()&&_documentCurrentScript.src||new URL("index.js",document.baseURI).href),__dirname$1=path.dirname(__filename$1);class RouteGenerator{constructor(e={},t=__dirname$1){this.routeFiles=[],this.modules=new Set,this.config={srcDir:e.srcDir||pajoExports.Pajo.join(t,"src")||"",modulesDir:e.modulesDir||pajoExports.Pajo.join(t,"src\\modules")||"",pagesDir:e.pagesDir||pajoExports.Pajo.join(t,"src\\pages")||"",outputFile:e.outputFile||pajoExports.Pajo.join(t,"src\\auto-routes.tsx")||"",layoutFileName:e.layoutFileName||"_layout",errorFileName:e.errorFileName||"_error",notFoundFileName:e.notFoundFileName||"_404"}}generate(){return __awaiter(this,void 0,void 0,function*(){yield this.findRouteFiles(),yield this.generateAutoRoutesFile()})}findRouteFiles(){return __awaiter(this,void 0,void 0,function*(){var e;if(this.routeFiles=[],yield this.scanDirectoryForRoutes(this.config.pagesDir),fs.existsSync(this.config.modulesDir))for(e of fs.readdirSync(this.config.modulesDir,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)){var t=path.join(this.config.modulesDir,e,"pages");fs.existsSync(t)&&(this.modules.add(e),yield this.scanDirectoryForRoutes(t,e))}})}scanDirectoryForRoutes(i,a){return __awaiter(this,void 0,void 0,function*(){try{var e;for(e of fs.readdirSync(i,{withFileTypes:!0})){var t,r,n=path.join(i,e.name);"node_modules"===e.name||"dist"===e.name||"build"===e.name||e.name.startsWith(".")||(e.isDirectory()?yield this.scanDirectoryForRoutes(n,a):e.isFile()&&(t=path.extname(e.name).toLowerCase(),[".tsx",".jsx"].includes(t))&&(r=path.basename(e.name,t))!==this.config.layoutFileName&&r!==this.config.errorFileName&&r!==this.config.notFoundFileName&&(yield this.processRouteFile(n,a)))}}catch(e){}})}processRouteFile(o,s){return __awaiter(this,void 0,void 0,function*(){try{var e=this.convertFilePathToRoutePath(o,s),t=this.extractComponentName(o,s),r=this.findLayoutComponent(o,s),n=this.findErrorComponent(o,s),i=this.findNotFoundComponent(o,s),a={filePath:o,relativePath:path.relative(this.config.srcDir,o),routePath:e,componentName:t,layoutComponent:r,errorComponent:n,notFoundComponent:i,moduleName:s};this.routeFiles.push(a)}catch(e){}})}convertFilePathToRoutePath(e,t){let r=e;return r=r.replace(this.config.srcDir,""),t?(e=`modules${path.sep}${t}${path.sep}pages`,r.includes(e)&&(r="/"+t+(r=r.substring(r.indexOf(e)+e.length)))):r.includes("pages")&&(r=r.substring(r.indexOf("pages")+"pages".length)),"/"===(r=(r=(r=(r=(r=r.replace(/\.(tsx|jsx)$/,"")).replace(/\\/g,"/")).endsWith("/index")?r.replace(/\/index$/,""):r).replace(/\[([^\]]+)\]/g,"{$1}")).startsWith("/")?r:"/"+r)||"//"===r?"/":r}extractComponentName(e,t){var r=path.basename(e,path.extname(e)),e=path.dirname(e).split(path.sep);let i=0;if(t){let n=path.sep+"modules"+path.sep+t+path.sep+"pages";i=e.findIndex((e,t,r)=>r.slice(0,t+1).join(path.sep).endsWith(n))+1}else{let n=path.sep+"pages";i=e.findIndex((e,t,r)=>r.slice(0,t+1).join(path.sep).endsWith(n))+1}i<0&&(i=0);e=e.slice(i);let n=t?this.toPascalCase(t):"",a=(e.forEach(e=>{e&&"pages"!==e&&(n+=this.toPascalCase(e))}),r);(a=r.startsWith("{")&&r.endsWith("}")?(t=r.substring(1,r.length-1),this.toPascalCase(t)+"Params"):this.toPascalCase(r)).endsWith("Page")||(a+="Page");return["Layout","ErrorBoundary","NotFound"].includes(a)&&(a+="Component"),n+a}toPascalCase(e){return e?e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(""):""}findLayoutComponent(e,t){let r=path.dirname(e);for(;r!==this.config.srcDir&&r!==path.dirname(this.config.srcDir);){var n=path.join(r,this.config.layoutFileName+".tsx");if(fs.existsSync(n))return this.generateComponentName(n,t,"Layout");if(t){n=path.join(this.config.modulesDir,t);if(r===n)break}r=path.dirname(r)}e=path.join(this.config.pagesDir,this.config.layoutFileName+".tsx");if(fs.existsSync(e))return"Layout"}findErrorComponent(e,t){let r=path.dirname(e);for(;r!==this.config.srcDir&&r!==path.dirname(this.config.srcDir);){var n=path.join(r,this.config.errorFileName+".tsx");if(fs.existsSync(n))return this.generateComponentName(n,t,"ErrorBoundary");if(t){n=path.join(this.config.modulesDir,t);if(r===n)break}r=path.dirname(r)}e=path.join(this.config.pagesDir,this.config.errorFileName+".tsx");if(fs.existsSync(e))return"ErrorBoundary"}findNotFoundComponent(e,t){var r;if(t)return r=path.join(this.config.modulesDir,t,"pages"),r=path.join(r,this.config.notFoundFileName+".tsx"),fs.existsSync(r)?this.generateComponentName(r,t,"NotFound"):void 0}generateComponentName(e,t,r){if(!t)return r;var n=path.basename(e,path.extname(e)),e=path.dirname(e),i=path.join(this.config.modulesDir,t,"pages"),i=path.relative(i,e);let a=this.toPascalCase(t);return i&&"."!==i&&i.split(path.sep).filter(e=>e&&"."!==e).forEach(e=>{a+=this.toPascalCase(e)}),n!==this.config.layoutFileName&&n!==this.config.errorFileName&&n!==this.config.notFoundFileName&&(a+=this.toPascalCase(n)),a+r}generateAutoRoutesFile(){return __awaiter(this,void 0,void 0,function*(){var e=path.dirname(this.config.outputFile),e=(fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),this.generateFileContent());fs.writeFileSync(this.config.outputFile,e,"utf-8")})}getRelativeImportPath(e){var t=path.dirname(this.config.outputFile);let r=path.relative(t,e).replace(/\\/g,"/");return r=(r=r.startsWith(".")||r.startsWith("/")?r:"./"+r).replace(/\.(tsx|jsx)$/,"")}generateFileContent(){let c=new Set,r=["import { lazy } from 'react';","import type { RouteObject } from 'react-router-dom';",""];var e=path.join(this.config.pagesDir,this.config.layoutFileName+".tsx"),t=path.join(this.config.pagesDir,this.config.errorFileName+".tsx"),n=path.join(this.config.pagesDir,this.config.notFoundFileName+".tsx");fs.existsSync(e)&&(e=this.getRelativeImportPath(e),r.push(`const Layout = lazy(() => import('${e}'));`),c.add("Layout")),fs.existsSync(t)&&(e=this.getRelativeImportPath(t),r.push(`const ErrorBoundary = lazy(() => import('${e}'));`),c.add("ErrorBoundary")),fs.existsSync(n)&&(t=this.getRelativeImportPath(n),r.push(`const NotFound = lazy(() => import('${t}'));`),c.add("NotFound")),r.push("");let l=new Map,i=(e,t=0,s)=>{if(fs.existsSync(e)){let o=e=>{try{var t;for(t of fs.readdirSync(e,{withFileTypes:!0})){var r,n,i,a=path.join(e,t.name);t.isDirectory()?o(a):t.isFile()&&(r=path.extname(t.name).toLowerCase(),![".tsx",".jsx"].includes(r)||(n=path.basename(t.name,r))!==this.config.layoutFileName&&n!==this.config.errorFileName&&n!==this.config.notFoundFileName||(i=this.generateComponentName(a,s,n===this.config.layoutFileName?"Layout":n===this.config.errorFileName?"ErrorBoundary":"NotFound"),c.has(i))||(l.set(a,i),c.add(i)))}}catch(e){}};o(e)}},o=(i(this.config.pagesDir,!1),this.modules.forEach(e=>{var t=path.join(this.config.modulesDir,e,"pages");fs.existsSync(t)&&i(t,!0,e)}),l.forEach((e,t)=>{t=this.getRelativeImportPath(t);r.push(`const ${e} = lazy(() => import('${t}'));`)}),0<l.size&&r.push(""),this.routeFiles.forEach(e=>{var t=this.getRelativeImportPath(e.filePath);r.push(`const ${e.componentName} = lazy(() => import('${t}'));`),c.add(e.componentName)}),r.push(""),["export const routes: RouteObject[] = ["]),s=this.routeFiles.sort((e,t)=>"/"===e.routePath?-1:"/"===t.routePath?1:!e.moduleName&&t.moduleName?-1:e.moduleName&&!t.moduleName?1:e.moduleName===t.moduleName?e.routePath.localeCompare(t.routePath):0),_=void 0,a=(s.forEach((e,t)=>{e.moduleName!==_&&(void 0!==_&&o.push(""),e.moduleName&&o.push(` // ${e.moduleName} module routes`),_=e.moduleName);var r,n=[" {"];n.push(` path: '${e.routePath}',`);let i=e.layoutComponent,a=((i=!i&&e.moduleName&&(r=path.join(this.config.modulesDir,e.moduleName,"pages",this.config.layoutFileName+".tsx"),fs.existsSync(r))?this.generateComponentName(r,e.moduleName,"Layout"):i)?n.push(` element: <${i}><${e.componentName} /></${i}>,`):n.push(` element: <${e.componentName} />,`),e.errorComponent);(a=!a&&e.moduleName&&(r=path.join(this.config.modulesDir,e.moduleName,"pages",this.config.errorFileName+".tsx"),fs.existsSync(r))?this.generateComponentName(r,e.moduleName,"ErrorBoundary"):a)&&n.push(` errorElement: <${a} />`),n[n.length-1].endsWith(",")&&(n[n.length-1]=n[n.length-1].slice(0,-1)),n.push(" }"),t<s.length-1&&(n[n.length-1]+=","),o.push(n.join("\n"))}),new Set);return l.forEach((e,t)=>{var r;path.basename(t,path.extname(t))===this.config.notFoundFileName&&-1!==(r=(t=t.split(path.sep)).indexOf("modules"))&&r+1<t.length&&(t=t[r+1],a.has(t)||(a.add(t),o[o.length-1].endsWith(",")&&(o[o.length-1]=o[o.length-1].slice(0,-1)),o.push(","),o.push(" {"),o.push(` path: '/${t}/*',`),o.push(` element: <${e} />`),o.push(" }")))}),c.has("NotFound")&&(o[o.length-1].endsWith(",")&&(o[o.length-1]=o[o.length-1].slice(0,-1)),o.push(","),o.push(" {"),o.push(" path: '*',"),o.push(" element: <NotFound />"),o.push(" }")),o.push("];"),o.push(""),o.push("export default routes;"),[...r,"",...o].join("\n")}}function RouteInitiator(){return __awaiter(this,arguments,void 0,function*(e=__dirname$1){e=new RouteGenerator({},e);try{yield e.generate()}catch(e){}})}function index(e=__dirname){TranslationInitiator(e),ConfigInitiator(e),RouteInitiator(e)}module.exports=index;
389
389
  //# sourceMappingURL=index.min.js.map
package/package.json CHANGED
@@ -3,8 +3,8 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.81",
7
- "description": "INITIATOR est un système de gestion de configuration modulaire pour les applications React avec TypeScript/JavaScript. Il fournit une gestion centralisée des configurations, un chargement dynamique des modules, et une intégration transparente avec les variables d'environnement.",
6
+ "version": "0.0.82",
7
+ "description": "INITIATOR est un plugin d'initialisation intelligent pour les applications React avec TypeScript/Javascript. Il génère automatiquement les fichiers de configuration, de routage et d'internationalisation basés sur la structure de votre projet.",
8
8
  "main": "index.js",
9
9
  "keywords": [],
10
10
  "author": "INICODE <contact.inicode@gmail.com>",