@arc-js/initiator 0.0.8 → 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 +421 -2
- package/index.js +142 -85
- package/index.min.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,13 +2,430 @@
|
|
|
2
2
|
|
|
3
3
|
[](LICENSE)
|
|
4
4
|

|
|
5
|
-

|
|
6
|
+

|
|
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.
|
|
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'
|
|
@@ -194927,27 +194927,51 @@ class RouteGenerator {
|
|
|
194927
194927
|
extractComponentName(filePath, moduleName) {
|
|
194928
194928
|
const fileName = path.basename(filePath, path.extname(filePath));
|
|
194929
194929
|
const dirName = path.dirname(filePath);
|
|
194930
|
-
const
|
|
194930
|
+
const parts = dirName.split(path.sep);
|
|
194931
|
+
let startIndex = 0;
|
|
194932
|
+
if (moduleName) {
|
|
194933
|
+
const modulePagesPath = path.sep + 'modules' + path.sep + moduleName + path.sep + 'pages';
|
|
194934
|
+
startIndex = parts.findIndex((part, index, arr) => {
|
|
194935
|
+
const pathSoFar = arr.slice(0, index + 1).join(path.sep);
|
|
194936
|
+
return pathSoFar.endsWith(modulePagesPath);
|
|
194937
|
+
}) + 1;
|
|
194938
|
+
}
|
|
194939
|
+
else {
|
|
194940
|
+
const pagesPath = path.sep + 'pages';
|
|
194941
|
+
startIndex = parts.findIndex((part, index, arr) => {
|
|
194942
|
+
const pathSoFar = arr.slice(0, index + 1).join(path.sep);
|
|
194943
|
+
return pathSoFar.endsWith(pagesPath);
|
|
194944
|
+
}) + 1;
|
|
194945
|
+
}
|
|
194946
|
+
if (startIndex < 0)
|
|
194947
|
+
startIndex = 0;
|
|
194948
|
+
const relevantParts = parts.slice(startIndex);
|
|
194931
194949
|
let componentName = moduleName ? this.toPascalCase(moduleName) : '';
|
|
194932
|
-
|
|
194933
|
-
if (
|
|
194934
|
-
componentName += this.toPascalCase(
|
|
194950
|
+
relevantParts.forEach(part => {
|
|
194951
|
+
if (part && part !== 'pages') {
|
|
194952
|
+
componentName += this.toPascalCase(part);
|
|
194935
194953
|
}
|
|
194936
194954
|
});
|
|
194937
|
-
let
|
|
194955
|
+
let fileNamePart = fileName;
|
|
194938
194956
|
if (fileName.startsWith('{') && fileName.endsWith('}')) {
|
|
194939
194957
|
const paramName = fileName.substring(1, fileName.length - 1);
|
|
194940
|
-
|
|
194958
|
+
fileNamePart = this.toPascalCase(paramName) + 'Params';
|
|
194941
194959
|
}
|
|
194942
194960
|
else {
|
|
194943
|
-
|
|
194961
|
+
fileNamePart = this.toPascalCase(fileName);
|
|
194944
194962
|
}
|
|
194945
|
-
if (!
|
|
194946
|
-
|
|
194963
|
+
if (!fileNamePart.endsWith('Page')) {
|
|
194964
|
+
fileNamePart += 'Page';
|
|
194947
194965
|
}
|
|
194948
|
-
|
|
194966
|
+
const reservedNames = ['Layout', 'ErrorBoundary', 'NotFound'];
|
|
194967
|
+
if (reservedNames.includes(fileNamePart)) {
|
|
194968
|
+
fileNamePart += 'Component';
|
|
194969
|
+
}
|
|
194970
|
+
return componentName + fileNamePart;
|
|
194949
194971
|
}
|
|
194950
194972
|
toPascalCase(str) {
|
|
194973
|
+
if (!str)
|
|
194974
|
+
return '';
|
|
194951
194975
|
return str
|
|
194952
194976
|
.split(/[-_]/)
|
|
194953
194977
|
.map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
@@ -195011,14 +195035,22 @@ class RouteGenerator {
|
|
|
195011
195035
|
if (!moduleName) {
|
|
195012
195036
|
return suffix;
|
|
195013
195037
|
}
|
|
195014
|
-
const
|
|
195038
|
+
const fileName = path.basename(filePath, path.extname(filePath));
|
|
195039
|
+
const dirName = path.dirname(filePath);
|
|
195040
|
+
const modulePagesPath = path.join(this.config.modulesDir, moduleName, 'pages');
|
|
195041
|
+
const relativePath = path.relative(modulePagesPath, dirName);
|
|
195015
195042
|
let componentName = this.toPascalCase(moduleName);
|
|
195016
195043
|
if (relativePath && relativePath !== '.') {
|
|
195017
|
-
const
|
|
195018
|
-
|
|
195019
|
-
componentName += this.toPascalCase(
|
|
195044
|
+
const dirParts = relativePath.split(path.sep).filter(part => part && part !== '.');
|
|
195045
|
+
dirParts.forEach(part => {
|
|
195046
|
+
componentName += this.toPascalCase(part);
|
|
195020
195047
|
});
|
|
195021
195048
|
}
|
|
195049
|
+
if (fileName !== this.config.layoutFileName &&
|
|
195050
|
+
fileName !== this.config.errorFileName &&
|
|
195051
|
+
fileName !== this.config.notFoundFileName) {
|
|
195052
|
+
componentName += this.toPascalCase(fileName);
|
|
195053
|
+
}
|
|
195022
195054
|
return componentName + suffix;
|
|
195023
195055
|
}
|
|
195024
195056
|
generateAutoRoutesFile() {
|
|
@@ -195067,41 +195099,60 @@ class RouteGenerator {
|
|
|
195067
195099
|
components.add('NotFound');
|
|
195068
195100
|
}
|
|
195069
195101
|
imports.push(``);
|
|
195070
|
-
const
|
|
195071
|
-
|
|
195072
|
-
if (
|
|
195073
|
-
|
|
195074
|
-
|
|
195075
|
-
|
|
195076
|
-
const
|
|
195077
|
-
|
|
195078
|
-
|
|
195079
|
-
|
|
195080
|
-
|
|
195081
|
-
|
|
195082
|
-
|
|
195083
|
-
|
|
195084
|
-
|
|
195085
|
-
|
|
195102
|
+
const specialComponents = new Map();
|
|
195103
|
+
const findSpecialFiles = (baseDir, isModule = false, moduleName) => {
|
|
195104
|
+
if (!fs.existsSync(baseDir))
|
|
195105
|
+
return;
|
|
195106
|
+
const walkDir = (dir) => {
|
|
195107
|
+
try {
|
|
195108
|
+
const items = fs.readdirSync(dir, { withFileTypes: true });
|
|
195109
|
+
for (const item of items) {
|
|
195110
|
+
const fullPath = path.join(dir, item.name);
|
|
195111
|
+
if (item.isDirectory()) {
|
|
195112
|
+
walkDir(fullPath);
|
|
195113
|
+
}
|
|
195114
|
+
else if (item.isFile()) {
|
|
195115
|
+
const ext = path.extname(item.name).toLowerCase();
|
|
195116
|
+
if (['.tsx', '.jsx'].includes(ext)) {
|
|
195117
|
+
const fileName = path.basename(item.name, ext);
|
|
195118
|
+
if (fileName === this.config.layoutFileName ||
|
|
195119
|
+
fileName === this.config.errorFileName ||
|
|
195120
|
+
fileName === this.config.notFoundFileName) {
|
|
195121
|
+
const componentName = this.generateComponentName(fullPath, moduleName, fileName === this.config.layoutFileName ? 'Layout' :
|
|
195122
|
+
fileName === this.config.errorFileName ? 'ErrorBoundary' : 'NotFound');
|
|
195123
|
+
if (!components.has(componentName)) {
|
|
195124
|
+
specialComponents.set(fullPath, componentName);
|
|
195125
|
+
components.add(componentName);
|
|
195126
|
+
}
|
|
195127
|
+
}
|
|
195128
|
+
}
|
|
195129
|
+
}
|
|
195130
|
+
}
|
|
195086
195131
|
}
|
|
195087
|
-
|
|
195088
|
-
|
|
195089
|
-
components.add(route.notFoundComponent);
|
|
195090
|
-
const notFoundFile = this.findComponentFile(route.filePath, this.config.notFoundFileName, route.moduleName);
|
|
195091
|
-
if (notFoundFile) {
|
|
195092
|
-
const importPath = this.getRelativeImportPath(notFoundFile);
|
|
195093
|
-
imports.push(`const ${route.notFoundComponent} = lazy(() => import('${importPath}'));`);
|
|
195132
|
+
catch (error) {
|
|
195133
|
+
console.error(`Error walking directory ${dir}:`, error);
|
|
195094
195134
|
}
|
|
195135
|
+
};
|
|
195136
|
+
walkDir(baseDir);
|
|
195137
|
+
};
|
|
195138
|
+
findSpecialFiles(this.config.pagesDir, false);
|
|
195139
|
+
this.modules.forEach(moduleName => {
|
|
195140
|
+
const modulePagesDir = path.join(this.config.modulesDir, moduleName, 'pages');
|
|
195141
|
+
if (fs.existsSync(modulePagesDir)) {
|
|
195142
|
+
findSpecialFiles(modulePagesDir, true, moduleName);
|
|
195095
195143
|
}
|
|
195144
|
+
});
|
|
195145
|
+
specialComponents.forEach((componentName, filePath) => {
|
|
195146
|
+
const importPath = this.getRelativeImportPath(filePath);
|
|
195147
|
+
imports.push(`const ${componentName} = lazy(() => import('${importPath}'));`);
|
|
195148
|
+
});
|
|
195149
|
+
if (specialComponents.size > 0) {
|
|
195150
|
+
imports.push(``);
|
|
195151
|
+
}
|
|
195152
|
+
this.routeFiles.forEach(route => {
|
|
195096
195153
|
const importPath = this.getRelativeImportPath(route.filePath);
|
|
195097
195154
|
imports.push(`const ${route.componentName} = lazy(() => import('${importPath}'));`);
|
|
195098
195155
|
components.add(route.componentName);
|
|
195099
|
-
if (route.moduleName) {
|
|
195100
|
-
if (!moduleComponents.has(route.moduleName)) {
|
|
195101
|
-
moduleComponents.set(route.moduleName, new Set());
|
|
195102
|
-
}
|
|
195103
|
-
moduleComponents.get(route.moduleName).add(route.componentName);
|
|
195104
|
-
}
|
|
195105
195156
|
});
|
|
195106
195157
|
imports.push(``);
|
|
195107
195158
|
const routes = ['export const routes: RouteObject[] = ['];
|
|
@@ -195119,18 +195170,41 @@ class RouteGenerator {
|
|
|
195119
195170
|
}
|
|
195120
195171
|
return 0;
|
|
195121
195172
|
});
|
|
195173
|
+
let lastModuleName = undefined;
|
|
195122
195174
|
sortedRoutes.forEach((route, index) => {
|
|
195123
|
-
|
|
195175
|
+
if (route.moduleName !== lastModuleName) {
|
|
195176
|
+
if (lastModuleName !== undefined) {
|
|
195177
|
+
routes.push(``);
|
|
195178
|
+
}
|
|
195179
|
+
if (route.moduleName) {
|
|
195180
|
+
routes.push(` // ${route.moduleName} module routes`);
|
|
195181
|
+
}
|
|
195182
|
+
lastModuleName = route.moduleName;
|
|
195183
|
+
}
|
|
195124
195184
|
const routeLines = [' {'];
|
|
195125
195185
|
routeLines.push(` path: '${route.routePath}',`);
|
|
195126
|
-
|
|
195127
|
-
|
|
195186
|
+
let layoutComponent = route.layoutComponent;
|
|
195187
|
+
if (!layoutComponent && route.moduleName) {
|
|
195188
|
+
const moduleLayoutPath = path.join(this.config.modulesDir, route.moduleName, 'pages', `${this.config.layoutFileName}.tsx`);
|
|
195189
|
+
if (fs.existsSync(moduleLayoutPath)) {
|
|
195190
|
+
layoutComponent = this.generateComponentName(moduleLayoutPath, route.moduleName, 'Layout');
|
|
195191
|
+
}
|
|
195192
|
+
}
|
|
195193
|
+
if (layoutComponent) {
|
|
195194
|
+
routeLines.push(` element: <${layoutComponent}><${route.componentName} /></${layoutComponent}>,`);
|
|
195128
195195
|
}
|
|
195129
195196
|
else {
|
|
195130
195197
|
routeLines.push(` element: <${route.componentName} />,`);
|
|
195131
195198
|
}
|
|
195132
|
-
|
|
195133
|
-
|
|
195199
|
+
let errorComponent = route.errorComponent;
|
|
195200
|
+
if (!errorComponent && route.moduleName) {
|
|
195201
|
+
const moduleErrorPath = path.join(this.config.modulesDir, route.moduleName, 'pages', `${this.config.errorFileName}.tsx`);
|
|
195202
|
+
if (fs.existsSync(moduleErrorPath)) {
|
|
195203
|
+
errorComponent = this.generateComponentName(moduleErrorPath, route.moduleName, 'ErrorBoundary');
|
|
195204
|
+
}
|
|
195205
|
+
}
|
|
195206
|
+
if (errorComponent) {
|
|
195207
|
+
routeLines.push(` errorElement: <${errorComponent} />`);
|
|
195134
195208
|
}
|
|
195135
195209
|
if (routeLines[routeLines.length - 1].endsWith(',')) {
|
|
195136
195210
|
routeLines[routeLines.length - 1] = routeLines[routeLines.length - 1].slice(0, -1);
|
|
@@ -195139,21 +195213,28 @@ class RouteGenerator {
|
|
|
195139
195213
|
if (index < sortedRoutes.length - 1) {
|
|
195140
195214
|
routeLines[routeLines.length - 1] += ',';
|
|
195141
195215
|
}
|
|
195142
|
-
if (route.moduleName && (index === 0 ||
|
|
195143
|
-
((_a = sortedRoutes[index - 1]) === null || _a === void 0 ? void 0 : _a.moduleName) !== route.moduleName)) {
|
|
195144
|
-
routes.push(` // ${route.moduleName} module routes`);
|
|
195145
|
-
}
|
|
195146
195216
|
routes.push(routeLines.join('\n'));
|
|
195147
195217
|
});
|
|
195148
195218
|
const modulesWith404 = new Set();
|
|
195149
|
-
|
|
195150
|
-
|
|
195151
|
-
|
|
195152
|
-
|
|
195153
|
-
|
|
195154
|
-
|
|
195155
|
-
|
|
195156
|
-
|
|
195219
|
+
specialComponents.forEach((componentName, filePath) => {
|
|
195220
|
+
const fileName = path.basename(filePath, path.extname(filePath));
|
|
195221
|
+
if (fileName === this.config.notFoundFileName) {
|
|
195222
|
+
const pathParts = filePath.split(path.sep);
|
|
195223
|
+
const modulesIndex = pathParts.indexOf('modules');
|
|
195224
|
+
if (modulesIndex !== -1 && modulesIndex + 1 < pathParts.length) {
|
|
195225
|
+
const moduleName = pathParts[modulesIndex + 1];
|
|
195226
|
+
if (!modulesWith404.has(moduleName)) {
|
|
195227
|
+
modulesWith404.add(moduleName);
|
|
195228
|
+
if (routes[routes.length - 1].endsWith(',')) {
|
|
195229
|
+
routes[routes.length - 1] = routes[routes.length - 1].slice(0, -1);
|
|
195230
|
+
}
|
|
195231
|
+
routes.push(`,`);
|
|
195232
|
+
routes.push(` {`);
|
|
195233
|
+
routes.push(` path: '/${moduleName}/*',`);
|
|
195234
|
+
routes.push(` element: <${componentName} />`);
|
|
195235
|
+
routes.push(` }`);
|
|
195236
|
+
}
|
|
195237
|
+
}
|
|
195157
195238
|
}
|
|
195158
195239
|
});
|
|
195159
195240
|
if (components.has('NotFound')) {
|
|
@@ -195175,30 +195256,6 @@ class RouteGenerator {
|
|
|
195175
195256
|
...routes
|
|
195176
195257
|
].join('\n');
|
|
195177
195258
|
}
|
|
195178
|
-
findComponentFile(startPath, fileName, moduleName) {
|
|
195179
|
-
const dir = path.dirname(startPath);
|
|
195180
|
-
let currentDir = dir;
|
|
195181
|
-
while (currentDir !== this.config.srcDir && currentDir !== path.dirname(this.config.srcDir)) {
|
|
195182
|
-
const componentPath = path.join(currentDir, `${fileName}.tsx`);
|
|
195183
|
-
if (fs.existsSync(componentPath)) {
|
|
195184
|
-
return componentPath;
|
|
195185
|
-
}
|
|
195186
|
-
if (moduleName) {
|
|
195187
|
-
const modulePath = path.join(this.config.modulesDir, moduleName);
|
|
195188
|
-
if (currentDir === modulePath) {
|
|
195189
|
-
break;
|
|
195190
|
-
}
|
|
195191
|
-
}
|
|
195192
|
-
currentDir = path.dirname(currentDir);
|
|
195193
|
-
}
|
|
195194
|
-
if (!moduleName) {
|
|
195195
|
-
const globalPath = path.join(this.config.pagesDir, `${fileName}.tsx`);
|
|
195196
|
-
if (fs.existsSync(globalPath)) {
|
|
195197
|
-
return globalPath;
|
|
195198
|
-
}
|
|
195199
|
-
}
|
|
195200
|
-
return undefined;
|
|
195201
|
-
}
|
|
195202
195259
|
}
|
|
195203
195260
|
function RouteInitiator() {
|
|
195204
195261
|
return __awaiter(this, arguments, void 0, function* (dirname = __dirname$1) {
|
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.
|
|
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.
|
|
7
|
-
"description": "INITIATOR est un
|
|
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>",
|