create-fleetbo-project 1.2.8 → 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.
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- {/*const { execSync } = require('child_process');
3
+ 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'); // Pas strictement nécessaire ici
7
8
 
8
9
  // --- Configuration ---
9
10
  const repoOwner = 'FleetFleetbo';
10
11
  const repoName = 'dev.fleetbo.io';
11
- const branchName = 'master'; // Assurez-vous que c'est la bonne branche
12
+ const branchName = 'master';
12
13
 
13
- const repoGitUrl = `https://github.com/${repoOwner}/${repoName}.git`;
14
+ // URL de téléchargement direct de l'archive
15
+ const archiveUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.tar.gz`;
14
16
  const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
15
17
 
16
18
  // --- Analyse des Arguments ---
@@ -19,20 +21,21 @@ const projectNameArg = args.find(arg => !arg.startsWith('--'));
19
21
  const tokenArg = args.find(arg => arg.startsWith('--token='));
20
22
 
21
23
  if (!projectNameArg) {
22
- console.error('\n Error : Please specify a name for your project.');
23
- console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
24
+ console.error('\n Error : Please specify a name for your project.');
25
+ console.log(' Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
24
26
  process.exit(1);
25
27
  }
26
28
 
27
29
  const bootstrapToken = tokenArg ? tokenArg.split('=')[1] : null;
28
30
 
29
31
  if (!bootstrapToken) {
30
- console.error('\n Error : "The bootstrap token is missing.');
31
- console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
32
+ console.error('\n Error : The bootstrap token is missing.');
33
+ console.log(' Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
32
34
  process.exit(1);
33
35
  }
34
36
 
35
37
  const projectName = projectNameArg;
38
+ const projectDir = path.join(process.cwd(), projectName);
36
39
 
37
40
  // --- Fonctions Utilitaires ---
38
41
 
@@ -51,7 +54,8 @@ function fetchProjectKeys(token) {
51
54
  reject(new Error('Invalid response from the key server.'));
52
55
  }
53
56
  } else {
54
- 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){}
55
59
  reject(new Error(errorMsg));
56
60
  }
57
61
  });
@@ -62,67 +66,133 @@ function fetchProjectKeys(token) {
62
66
  });
63
67
  }
64
68
 
69
+ // --- CORRECTION ICI : Gestion des redirections (301/302) ---
70
+ function downloadEngine(url, dest) {
71
+ return new Promise((resolve, reject) => {
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)
88
+ if (response.statusCode !== 200) {
89
+ reject(new Error(`Failed to download engine (Status: ${response.statusCode})`));
90
+ return;
91
+ }
92
+
93
+ // 3. Écriture du fichier
94
+ const file = fs.createWriteStream(dest);
95
+ response.pipe(file);
96
+
97
+ file.on('finish', () => {
98
+ file.close(resolve);
99
+ });
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, () => {});
109
+ reject(err);
110
+ });
111
+ });
112
+ }
113
+
65
114
  // --- Fonction Principale ---
66
115
 
67
116
  async function setupProject() {
68
- console.log(`\nCreating your Fleetbo project "${projectName}"...`);
69
- const projectDir = path.join(process.cwd(), projectName);
70
-
117
+ console.log(`\n⚡ Initializing Fleetbo Framework for "${projectName}"...`);
118
+
71
119
  try {
72
- // Étape 1 : Télécharger la structure de base du projet
73
- console.log(' [1/5] Initializing project structure...');
74
- // On redirige la sortie d'erreur (stderr) vers null pour masquer les messages de progression de Git
75
- execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}" 2> /dev/null`);
120
+ if (fs.existsSync(projectDir)) {
121
+ throw new Error(`Directory "${projectName}" already exists.`);
122
+ }
123
+ fs.mkdirSync(projectDir);
76
124
 
77
- // Étape 2 : Se déplacer dans le dossier du projet et nettoyer
78
- console.log(' [2/5] Project structure initialized. Configuring...');
79
- process.chdir(projectDir);
125
+ // Étape 1 : Téléchargement
126
+ console.log(' [1/6] 📥 Downloading Fleetbo Core Engine...');
127
+ const archivePath = path.join(projectDir, 'engine.tar.gz');
128
+
129
+ // Cette fonction gère maintenant la redirection GitHub
130
+ await downloadEngine(archiveUrl, archivePath);
131
+
132
+ // Étape 2 : Extraction
133
+ console.log(' [2/6] 📦 Scaffolding project structure...');
134
+ try {
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);
138
+ } catch (e) {
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.");
141
+ }
80
142
 
81
- // Supprimer l'historique Git pour commencer avec un projet propre
82
- fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
143
+ process.chdir(projectDir);
83
144
 
84
- // Étape 3 : Récupération des clés de projet
85
- console.log(' [3/5] Fetching project keys...');
145
+ // Étape 3 : Authentification
146
+ console.log(' [3/6] 🔑 Authenticating with Fleetbo Cloud...');
86
147
  const keys = await fetchProjectKeys(bootstrapToken);
87
148
  if (!keys.enterpriseId || !keys.fleetboDBKey) {
88
149
  throw new Error("Received keys from the server are invalid.");
89
150
  }
90
151
 
91
- // Étape 4 : Configuration du fichier .env
92
- console.log(' [4/5] .env file configured successfully.');
93
- //const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`; //99b426483d543b042209671dd53fb18
94
- const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=99b426483d543b042209671dd53fb18\nREACT_KEY_APP=${projectName}\n`;
152
+ // Étape 4 : Environnement
153
+ console.log(' [4/6] ⚙️ Configuring environment...');
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`;
95
155
  fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
96
156
 
97
- // Étape 5 : Installation des dépendances
98
- console.log(' [5/5] Installing dependencies...');
99
- execSync('npm install', { stdio: 'inherit' });
157
+ // Étape 5 : Dépendances
158
+ console.log(' [5/6] 📚 Installing dependencies...');
159
+ // On installe les deps du projet + ngrok en dev
160
+ execSync('npm install', { stdio: 'inherit' });
161
+ execSync('npm install ngrok dotenv --save-dev', { stdio: 'ignore' });
100
162
 
101
- // Personnalisation du package.json
163
+ // Étape 6 : Finalisation
164
+ console.log(' [6/6] ✨ Finalizing setup...');
102
165
  const packageJsonPath = path.join(projectDir, 'package.json');
103
166
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
104
167
  packageJson.name = projectName;
168
+
169
+ packageJson.scripts = {
170
+ ...packageJson.scripts,
171
+ "fleetbo": "node cli.js",
172
+ "dev": "node cli.js"
173
+ };
105
174
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
106
175
 
107
- console.log('\n🚀 Your Fleetbo project is ready !');
108
- console.log(`\nTo get started, run the following commands :`);
176
+ console.log('\n Project successfully created!');
177
+ console.log(`\n👉 Get started with:`);
109
178
  console.log(` cd ${projectName}`);
110
- console.log(` npx fleetbo start`);
179
+ console.log(` npm run fleetbo`);
111
180
 
112
181
  } catch (error) {
113
- console.error('\n An error occurred while creating the project :', error.message);
114
- // Nettoyage en cas d'erreur
182
+ console.error('\n Setup failed:', error.message);
115
183
  if (fs.existsSync(projectDir)) {
116
- fs.rmSync(projectDir, { recursive: true, force: true });
184
+ try { fs.rmSync(projectDir, { recursive: true, force: true }); } catch(e){}
117
185
  }
186
+ process.exit(1);
118
187
  }
119
188
  }
120
189
 
121
190
  setupProject();
122
- */}
123
191
 
124
192
 
125
193
 
194
+ {/*
195
+
126
196
  const { execSync } = require('child_process');
127
197
  const fs = require('fs');
128
198
  const path = require('path');
@@ -143,7 +213,7 @@ const tokenArg = args.find(arg => arg.startsWith('--token='));
143
213
 
144
214
  if (!projectNameArg) {
145
215
  console.error('\n Error : Please specify a name for your project.');
146
- console.log(' Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
216
+ console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
147
217
  process.exit(1);
148
218
  }
149
219
 
@@ -151,7 +221,7 @@ const bootstrapToken = tokenArg ? tokenArg.split('=')[1] : null;
151
221
 
152
222
  if (!bootstrapToken) {
153
223
  console.error('\n Error : "The bootstrap token is missing.');
154
- console.log(' Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
224
+ console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
155
225
  process.exit(1);
156
226
  }
157
227
 
@@ -193,39 +263,35 @@ async function setupProject() {
193
263
 
194
264
  try {
195
265
  // Étape 1 : Télécharger la structure de base du projet
196
- console.log(' [1/6] Initializing project structure...');
266
+ console.log(' [1/5] Initializing project structure...');
197
267
  // On redirige la sortie d'erreur (stderr) vers null pour masquer les messages de progression de Git
198
268
  execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}" 2> /dev/null`);
199
269
 
200
270
  // Étape 2 : Se déplacer dans le dossier du projet et nettoyer
201
- console.log(' [2/6] Project structure initialized. Configuring...');
271
+ console.log(' [2/5] Project structure initialized. Configuring...');
202
272
  process.chdir(projectDir);
203
273
 
204
274
  // Supprimer l'historique Git pour commencer avec un projet propre
205
275
  fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
206
276
 
207
277
  // Étape 3 : Récupération des clés de projet
208
- console.log(' [3/6] Fetching project keys...');
278
+ console.log(' [3/5] Fetching project keys...');
209
279
  const keys = await fetchProjectKeys(bootstrapToken);
210
280
  if (!keys.enterpriseId || !keys.fleetboDBKey) {
211
281
  throw new Error("Received keys from the server are invalid.");
212
282
  }
213
283
 
214
284
  // Étape 4 : Configuration du fichier .env
215
- console.log(' [4/6] .env file configured successfully.');
216
- // Les variables d'environnement sont mises à jour pour le projet
285
+ console.log(' [4/5] .env file configured successfully.');
286
+ //const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`; //99b426483d543b042209671dd53fb18
217
287
  const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=99b426483d543b042209671dd53fb18\nREACT_KEY_APP=${projectName}\n`;
218
288
  fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
219
289
 
220
- // Étape 5 : Installation des dépendances (principales)
221
- console.log(' [5/6] Installing core dependencies...');
222
- execSync('npm install', { stdio: 'inherit' }); // Installe toutes les dépendances listées dans package.json
290
+ // Étape 5 : Installation des dépendances
291
+ console.log(' [5/5] Installing dependencies...');
292
+ execSync('npm install', { stdio: 'inherit' });
223
293
 
224
- // Étape 6 : Installation de ngrok (nécessaire pour le Hot Reloading sur le simulateur en ligne)
225
- console.log(' [6/6] Installing ngrok for secure tunneling...');
226
- execSync('npm install ngrok', { stdio: 'inherit' });
227
-
228
- // Personnalisation du package.json (Nom du projet)
294
+ // Personnalisation du package.json
229
295
  const packageJsonPath = path.join(projectDir, 'package.json');
230
296
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
231
297
  packageJson.name = projectName;
@@ -245,4 +311,8 @@ async function setupProject() {
245
311
  }
246
312
  }
247
313
 
248
- setupProject();
314
+ setupProject();
315
+ */}
316
+
317
+
318
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {
@@ -9,6 +9,8 @@
9
9
  "dependencies": {
10
10
  "axios": "^1.12.2",
11
11
  "chalk": "^4.1.2",
12
+ "dotenv": "^16.6.1",
13
+ "ngrok": "^5.0.0-beta.2",
12
14
  "ora": "^5.4.1",
13
15
  "unzipper": "^0.10.14",
14
16
  "yargs-parser": "^21.1.1"