create-fleetbo-project 1.0.15 → 1.0.17

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.
@@ -1,89 +1,115 @@
1
- #!/usr/bin/env node
2
- // install-react-template.js (Version améliorée)
3
- const { execSync } = require('child_process');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const https = require('https');
7
- const unzipper = require('unzipper');
8
- const axios = require('axios');
9
- const ora = require('ora');
10
- const chalk = require('chalk');
11
-
12
- // --- Configuration ---
13
- const projectName = process.argv[2];
14
- const tokenArgIndex = process.argv.indexOf('--token');
15
- const bootstrapToken = tokenArgIndex !== -1 ? process.argv[tokenArgIndex + 1] : null;
16
- const repoUrl = 'https://github.com/FleetFleetbo/dev.fleetbo.io/archive/refs/heads/main.zip';
17
- // ⚠️ REMPLACEZ PAR L'URL DE VOTRE FONCTION bootstrapProject
18
- const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
19
-
20
- // --- Validation ---
21
- if (!projectName || !bootstrapToken) {
22
- console.error(chalk.red('Erreur : Nom du projet ou token manquant.'));
23
- console.log('Usage: npx create-fleetbo-project <nom-du-projet> --token <votre-token>');
24
- process.exit(1);
25
- }
26
-
27
- // --- Fonction Principale ---
28
- async function setupProject() {
29
- console.log(chalk.blue(`Création de votre projet Fleetbo "${projectName}"...`));
30
- const spinner = ora();
31
-
32
- try {
33
- spinner.start('Récupération de la configuration sécurisée...');
34
- const response = await axios.post(bootstrapUrl, { token: bootstrapToken });
35
- const projectSecrets = response.data;
36
- spinner.succeed(chalk.green('Configuration récupérée !'));
37
-
38
- spinner.start('Téléchargement du template...');
39
- const responseStream = await new Promise((resolve, reject) => https.get(repoUrl, res => resolve(res)).on('error', err => reject(err)));
40
- spinner.succeed(chalk.green('Template téléchargé.'));
41
-
42
- spinner.start('Décompression des fichiers...');
43
- await new Promise((resolve, reject) => {
44
- responseStream.pipe(unzipper.Extract({ path: '.' }))
45
- .on('finish', resolve).on('error', reject);
46
- });
47
-
48
- // --- AJOUTEZ LE BLOC DE DÉBOGAGE ICI ---
49
- console.log(chalk.yellow('\n[DEBUG] Décompression terminée. Contenu du dossier actuel :'));
50
- const files = fs.readdirSync('.');
51
- console.log(files);
52
- // --- FIN DU BLOC DE DÉBOGAGE ---
53
-
54
- const extractedDirName = files.find(file => fs.statSync(file).isDirectory());
55
- if (!extractedDirName) {
56
- throw new Error("Could not find the extracted template directory after unzipping.");
57
- }
58
- fs.renameSync(extractedDirName, projectName);
59
- spinner.succeed(chalk.green('Fichiers décompressés.'));
60
-
61
- process.chdir(projectName);
62
-
63
- spinner.start('Configuration du projet...');
64
- const envContent = `REACT_APP_FLEETBO_DB_KEY=${projectSecrets.fleetboDB}\nREACT_APP_ENTERPRISE_ID=${projectSecrets.appId}\n`;
65
- fs.writeFileSync('.env', envContent, 'utf8');
66
-
67
- const packageJsonPath = path.join(process.cwd(), 'package.json');
68
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
69
- packageJson.name = projectName;
70
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
71
- spinner.succeed(chalk.green('Projet configuré.'));
72
-
73
- spinner.start('Installation des dépendances (cela peut prendre quelques minutes)...');
74
- execSync('npm install', { stdio: 'inherit' });
75
- spinner.succeed(chalk.green('Dépendances installées.'));
76
-
77
- console.log(chalk.green.bold('\n🚀 Votre projet Fleetbo est prêt !'));
78
- console.log(`\nPour commencer :`);
79
- console.log(chalk.cyan(` cd ${projectName}`));
80
- console.log(chalk.cyan(` npm start`));
81
-
82
- } catch (error) {
83
- if (spinner.isSpinning) spinner.fail();
84
- console.error(chalk.red('\n❌ Une erreur est survenue :'), error.response ? error.response.data : error.message);
85
- process.exit(1);
86
- }
87
- }
88
-
1
+ #!/usr/bin/env node
2
+ // Fichier : install-react-template.js (Version corrigée)
3
+ const { execSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const https = require('https');
7
+ const unzipper = require('unzipper');
8
+ const axios = require('axios');
9
+ const ora = require('ora');
10
+ const chalk = require('chalk');
11
+
12
+ // --- Configuration ---
13
+ const projectName = process.argv[2];
14
+ const tokenArgIndex = process.argv.indexOf('--token');
15
+ const bootstrapToken = tokenArgIndex !== -1 ? process.argv[tokenArgIndex + 1] : null;
16
+ const repoUrl = 'https://github.com/FleetFleetbo/dev.fleetbo.io/archive/refs/heads/main.zip';
17
+ const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
18
+
19
+ // --- Validation ---
20
+ if (!projectName || !bootstrapToken) {
21
+ console.error(chalk.red('Erreur : Nom du projet ou token manquant.'));
22
+ console.log('Usage: npx create-fleetbo-project <nom-du-projet> --token <votre-token>');
23
+ process.exit(1);
24
+ }
25
+
26
+ // --- Fonction pour attendre que le dossier existe ---
27
+ function waitForDirectory(dirPath, timeout = 10000) {
28
+ return new Promise((resolve, reject) => {
29
+ const startTime = Date.now();
30
+ const interval = setInterval(() => {
31
+ if (fs.existsSync(dirPath)) {
32
+ clearInterval(interval);
33
+ // Attendre un peu plus pour s'assurer que tous les fichiers sont écrits
34
+ setTimeout(() => resolve(), 500);
35
+ } else if (Date.now() - startTime > timeout) {
36
+ clearInterval(interval);
37
+ reject(new Error(`Le dossier ${dirPath} n'a pas été créé dans le délai imparti`));
38
+ }
39
+ }, 100);
40
+ });
41
+ }
42
+
43
+ // --- Fonction Principale ---
44
+ async function setupProject() {
45
+ console.log(chalk.blue(`Création de votre projet Fleetbo "${projectName}"...`));
46
+ const spinner = ora();
47
+
48
+ try {
49
+ spinner.start('Récupération de la configuration sécurisée...');
50
+ const response = await axios.post(bootstrapUrl, { token: bootstrapToken });
51
+ const projectSecrets = response.data;
52
+ spinner.succeed(chalk.green('Configuration récupérée !'));
53
+
54
+ spinner.start('Téléchargement du template...');
55
+ const responseStream = await new Promise((resolve, reject) => {
56
+ https.get(repoUrl, res => resolve(res)).on('error', err => reject(err));
57
+ });
58
+ spinner.succeed(chalk.green('Template téléchargé.'));
59
+
60
+ spinner.start('Décompression des fichiers...');
61
+
62
+ // Décompression avec gestion d'erreur améliorée
63
+ await new Promise((resolve, reject) => {
64
+ responseStream
65
+ .pipe(unzipper.Extract({ path: '.' }))
66
+ .on('close', resolve) // 'close' est plus fiable que 'finish'
67
+ .on('error', reject);
68
+ });
69
+
70
+ // Attendre que le dossier soit bien créé
71
+ const extractedDir = 'dev.fleetbo.io-main';
72
+ await waitForDirectory(extractedDir);
73
+
74
+ // Vérifier que le dossier existe avant de renommer
75
+ if (!fs.existsSync(extractedDir)) {
76
+ throw new Error(`Le dossier ${extractedDir} n'a pas été créé après la décompression`);
77
+ }
78
+
79
+ // Vérifier que le dossier cible n'existe pas déjà
80
+ if (fs.existsSync(projectName)) {
81
+ throw new Error(`Le dossier ${projectName} existe déjà`);
82
+ }
83
+
84
+ fs.renameSync(extractedDir, projectName);
85
+ spinner.succeed(chalk.green('Fichiers décompressés.'));
86
+
87
+ process.chdir(projectName);
88
+
89
+ spinner.start('Configuration du projet...');
90
+ const envContent = `REACT_APP_FLEETBO_DB_KEY=${projectSecrets.fleetboDB}\nREACT_APP_ENTERPRISE_ID=${projectSecrets.appId}\n`;
91
+ fs.writeFileSync('.env', envContent, 'utf8');
92
+
93
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
94
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
95
+ packageJson.name = projectName;
96
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
97
+ spinner.succeed(chalk.green('Projet configuré.'));
98
+
99
+ spinner.start('Installation des dépendances (cela peut prendre quelques minutes)...');
100
+ execSync('npm install', { stdio: 'inherit' });
101
+ spinner.succeed(chalk.green('Dépendances installées.'));
102
+
103
+ console.log(chalk.green.bold('\n🚀 Votre projet Fleetbo est prêt !'));
104
+ console.log(`\nPour commencer :`);
105
+ console.log(chalk.cyan(` cd ${projectName}`));
106
+ console.log(chalk.cyan(` npm start`));
107
+
108
+ } catch (error) {
109
+ if (spinner.isSpinning) spinner.fail();
110
+ console.error(chalk.red('\n❌ Une erreur est survenue :'), error.response ? error.response.data : error.message);
111
+ process.exit(1);
112
+ }
113
+ }
114
+
89
115
  setupProject();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {