create-fleetbo-project 1.2.9 → 1.2.10

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,15 +4,14 @@ 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 os = require('os');
7
+ // const os = require('os'); // Pas strictement nécessaire ici
8
8
 
9
9
  // --- Configuration ---
10
- // On cible l'archive (zip/tar) plutôt que le repo git
11
10
  const repoOwner = 'FleetFleetbo';
12
11
  const repoName = 'dev.fleetbo.io';
13
12
  const branchName = 'master';
14
13
 
15
- // URL de téléchargement direct de l'archive (plus rapide, pas de .git)
14
+ // URL de téléchargement direct de l'archive
16
15
  const archiveUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.tar.gz`;
17
16
  const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
18
17
 
@@ -41,7 +40,6 @@ const projectDir = path.join(process.cwd(), projectName);
41
40
  // --- Fonctions Utilitaires ---
42
41
 
43
42
  function fetchProjectKeys(token) {
44
- // ... (Code inchangé pour la récupération des clés) ...
45
43
  return new Promise((resolve, reject) => {
46
44
  const postData = JSON.stringify({ token });
47
45
  const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } };
@@ -56,7 +54,8 @@ function fetchProjectKeys(token) {
56
54
  reject(new Error('Invalid response from the key server.'));
57
55
  }
58
56
  } else {
59
- const errorMsg = JSON.parse(data).error || `Server error (code: ${res.statusCode})`;
57
+ let errorMsg = `Server error (code: ${res.statusCode})`;
58
+ try { errorMsg = JSON.parse(data).error || errorMsg; } catch(e){}
60
59
  reject(new Error(errorMsg));
61
60
  }
62
61
  });
@@ -67,21 +66,46 @@ function fetchProjectKeys(token) {
67
66
  });
68
67
  }
69
68
 
70
- // Fonction pour télécharger l'archive
69
+ // --- CORRECTION ICI : Gestion des redirections (301/302) ---
71
70
  function downloadEngine(url, dest) {
72
71
  return new Promise((resolve, reject) => {
73
- const file = fs.createWriteStream(dest);
74
- https.get(url, (response) => {
72
+ const request = https.get(url, (response) => {
73
+ // 1. Gérer la redirection (GitHub renvoie souvent 302 Found)
74
+ if (response.statusCode === 301 || response.statusCode === 302) {
75
+ const newUrl = response.headers.location;
76
+ if (!newUrl) {
77
+ reject(new Error("Redirect status found but no location header."));
78
+ return;
79
+ }
80
+ // Appel récursif avec la nouvelle URL
81
+ downloadEngine(newUrl, dest)
82
+ .then(resolve)
83
+ .catch(reject);
84
+ return;
85
+ }
86
+
87
+ // 2. Vérifier le succès (200 OK)
75
88
  if (response.statusCode !== 200) {
76
89
  reject(new Error(`Failed to download engine (Status: ${response.statusCode})`));
77
90
  return;
78
91
  }
92
+
93
+ // 3. Écriture du fichier
94
+ const file = fs.createWriteStream(dest);
79
95
  response.pipe(file);
96
+
80
97
  file.on('finish', () => {
81
98
  file.close(resolve);
82
99
  });
83
- }).on('error', (err) => {
84
- fs.unlink(dest, () => {}); // Supprimer le fichier partiel
100
+
101
+ file.on('error', (err) => {
102
+ fs.unlink(dest, () => {}); // Supprimer fichier incomplet
103
+ reject(err);
104
+ });
105
+ });
106
+
107
+ request.on('error', (err) => {
108
+ fs.unlink(dest, () => {});
85
109
  reject(err);
86
110
  });
87
111
  });
@@ -93,61 +117,55 @@ async function setupProject() {
93
117
  console.log(`\n⚡ Initializing Fleetbo Framework for "${projectName}"...`);
94
118
 
95
119
  try {
96
- // Création du dossier
97
120
  if (fs.existsSync(projectDir)) {
98
121
  throw new Error(`Directory "${projectName}" already exists.`);
99
122
  }
100
123
  fs.mkdirSync(projectDir);
101
124
 
102
- // Étape 1 : Téléchargement du Moteur (Sans Git)
125
+ // Étape 1 : Téléchargement
103
126
  console.log(' [1/6] 📥 Downloading Fleetbo Core Engine...');
104
127
  const archivePath = path.join(projectDir, 'engine.tar.gz');
128
+
129
+ // Cette fonction gère maintenant la redirection GitHub
105
130
  await downloadEngine(archiveUrl, archivePath);
106
131
 
107
- // Étape 2 : Extraction (Scaffolding)
132
+ // Étape 2 : Extraction
108
133
  console.log(' [2/6] 📦 Scaffolding project structure...');
109
- // On utilise 'tar' qui est présent sur Win10+, Mac et Linux.
110
- // --strip-components=1 permet de retirer le dossier racine "dev.fleetbo.io-master" de l'archive
111
134
  try {
112
- execSync(`tar -xf "${archivePath}" -C "${projectDir}" --strip-components=1`);
113
- fs.unlinkSync(archivePath); // Nettoyage de l'archive
135
+ // On ignore les erreurs de tar si c'est juste des warnings, mais on catch les erreurs fatales
136
+ execSync(`tar -xf "${archivePath}" -C "${projectDir}" --strip-components=1`, { stdio: 'ignore' });
137
+ fs.unlinkSync(archivePath);
114
138
  } catch (e) {
115
- throw new Error("Failed to extract the engine. Ensure 'tar' is available on your system.");
139
+ // Fallback pour Windows si 'tar' n'est pas dans le path (rare sur Win10/11 mais possible)
140
+ throw new Error("Failed to extract engine. Make sure 'tar' command is available.");
116
141
  }
117
142
 
118
- // On se déplace dans le dossier (Plus besoin de supprimer .git car il n'y en a pas !)
119
143
  process.chdir(projectDir);
120
144
 
121
- // Étape 3 : Récupération des clés (Authentication)
145
+ // Étape 3 : Authentification
122
146
  console.log(' [3/6] 🔑 Authenticating with Fleetbo Cloud...');
123
147
  const keys = await fetchProjectKeys(bootstrapToken);
124
148
  if (!keys.enterpriseId || !keys.fleetboDBKey) {
125
149
  throw new Error("Received keys from the server are invalid.");
126
150
  }
127
151
 
128
- // Étape 4 : Configuration de l'environnement
152
+ // Étape 4 : Environnement
129
153
  console.log(' [4/6] ⚙️ Configuring environment...');
130
- // Configuration .env optimisée pour le simulateur (DANGEROUSLY_DISABLE_HOST_CHECK)
131
154
  const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\nREACT_KEY_APP=${projectName}\nDANGEROUSLY_DISABLE_HOST_CHECK=true\n`;
132
155
  fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
133
156
 
134
- // Étape 5 : Installation des dépendances
135
- console.log(' [5/6] 📚 Installing dependencies (this may take a moment)...');
136
- // Installation silencieuse pour faire plus "pro" (pipe stdio si erreur)
157
+ // Étape 5 : Dépendances
158
+ console.log(' [5/6] 📚 Installing dependencies...');
159
+ // On installe les deps du projet + ngrok en dev
137
160
  execSync('npm install', { stdio: 'inherit' });
138
-
139
- // Installation des outils de dev (Ngrok est vital pour le flow)
140
- console.log(' Installing development tools...');
141
161
  execSync('npm install ngrok dotenv --save-dev', { stdio: 'ignore' });
142
162
 
143
163
  // Étape 6 : Finalisation
144
164
  console.log(' [6/6] ✨ Finalizing setup...');
145
-
146
165
  const packageJsonPath = path.join(projectDir, 'package.json');
147
166
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
148
167
  packageJson.name = projectName;
149
168
 
150
- // On ajoute la commande 'fleetbo'
151
169
  packageJson.scripts = {
152
170
  ...packageJson.scripts,
153
171
  "fleetbo": "node cli.js",
@@ -162,7 +180,6 @@ async function setupProject() {
162
180
 
163
181
  } catch (error) {
164
182
  console.error('\n❌ Setup failed:', error.message);
165
- // Nettoyage en cas d'erreur
166
183
  if (fs.existsSync(projectDir)) {
167
184
  try { fs.rmSync(projectDir, { recursive: true, force: true }); } catch(e){}
168
185
  }
@@ -174,9 +191,6 @@ setupProject();
174
191
 
175
192
 
176
193
 
177
-
178
-
179
-
180
194
  {/*
181
195
 
182
196
  const { execSync } = require('child_process');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {