create-fleetbo-project 1.0.36 → 1.0.38

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.
@@ -4,14 +4,13 @@ const { execSync } = require('child_process');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
  const https = require('https');
7
- const unzipper = require('unzipper');
8
7
 
9
8
  // --- Configuration ---
10
9
  const repoOwner = 'FleetFleetbo';
11
10
  const repoName = 'dev.fleetbo.io';
12
11
  const branchName = 'master'; // Assurez-vous que c'est la bonne branche
13
12
 
14
- const repoUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.zip`;
13
+ const repoGitUrl = `https://github.com/${repoOwner}/${repoName}.git`;
15
14
  const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
16
15
 
17
16
  // --- Analyse des Arguments ---
@@ -67,54 +66,34 @@ function fetchProjectKeys(token) {
67
66
 
68
67
  async function setupProject() {
69
68
  console.log(`\nCréation de votre projet Fleetbo "${projectName}"...`);
70
-
71
- // Le nom du dossier que GitHub crée dans le .zip
72
- const unzippedDirName = `${repoName}-${branchName}`;
73
- const sourceDir = path.join(process.cwd(), unzippedDirName);
74
69
  const projectDir = path.join(process.cwd(), projectName);
75
70
 
76
71
  try {
77
- // Étape 1 : Téléchargement et décompression (votre modèle)
78
- console.log(' [1/5] 📥 Téléchargement et décompression du template...');
79
- await new Promise((resolve, reject) => {
80
- https.get(repoUrl, (response) => {
81
- if (response.statusCode === 301 || response.statusCode === 302) {
82
- return https.get(response.headers.location, (redirectResponse) => {
83
- redirectResponse.pipe(unzipper.Extract({ path: process.cwd() }))
84
- .on('finish', resolve)
85
- .on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
86
- }).on('error', (err) => reject(new Error(`Erreur réseau après redirection: ${err.message}`)));
87
- } else if (response.statusCode !== 200) {
88
- return reject(new Error(`Échec du téléchargement. Statut: ${response.statusCode}`));
89
- } else {
90
- response.pipe(unzipper.Extract({ path: process.cwd() }))
91
- .on('finish', resolve)
92
- .on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
93
- }
94
- }).on('error', (err) => reject(new Error(`Erreur réseau: ${err.message}`)));
95
- });
96
-
97
- // Étape 2 : Renommer le dossier décompressé
98
- console.log(' [2/5] ✅ Template décompressé. Renommage du dossier...');
99
- if (fs.existsSync(sourceDir)) {
100
- fs.renameSync(sourceDir, projectDir);
101
- } else {
102
- throw new Error(`Le dossier attendu "${unzippedDirName}" n'a pas été trouvé après la décompression.`);
103
- }
72
+ // Étape 1 : Télécharger la structure de base du projet
73
+ console.log(' [1/5] 📥 Initialisation de la structure du projet...');
74
+ // On retire "stdio: 'inherit'" pour masquer les logs de git
75
+ execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}"`);
104
76
 
105
- // Étape 3 : Se déplacer dans le dossier du projet et continuer
77
+ // Étape 2 : Se déplacer dans le dossier du projet et nettoyer
78
+ console.log(' [2/5] ✅ Structure du projet initialisée. Configuration en cours...');
106
79
  process.chdir(projectDir);
107
80
 
81
+ // Supprimer l'historique Git pour commencer avec un projet propre
82
+ fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
83
+
84
+ // Étape 3 : Récupération des clés de projet
108
85
  console.log(' [3/5] 🔑 Récupération des clés de projet...');
109
86
  const keys = await fetchProjectKeys(bootstrapToken);
110
87
  if (!keys.enterpriseId || !keys.fleetboDBKey) {
111
88
  throw new Error("Les clés reçues du serveur sont invalides.");
112
89
  }
113
90
 
91
+ // Étape 4 : Configuration du fichier .env
114
92
  console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
115
93
  const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`;
116
94
  fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
117
95
 
96
+ // Étape 5 : Installation des dépendances
118
97
  console.log(' [5/5] 📦 Installation des dépendances...');
119
98
  execSync('npm install', { stdio: 'inherit' });
120
99
 
@@ -132,9 +111,6 @@ async function setupProject() {
132
111
  } catch (error) {
133
112
  console.error('\n❌ Une erreur est survenue lors de la création du projet :', error.message);
134
113
  // Nettoyage en cas d'erreur
135
- if (fs.existsSync(sourceDir)) {
136
- fs.rmSync(sourceDir, { recursive: true, force: true });
137
- }
138
114
  if (fs.existsSync(projectDir)) {
139
115
  fs.rmSync(projectDir, { recursive: true, force: true });
140
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {