create-fleetbo-project 1.2.23 → 1.2.25

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.
@@ -12,7 +12,7 @@ const branchName = 'master';
12
12
  const archiveUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.tar.gz`;
13
13
  const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
14
14
 
15
- // --- LE CONTENU DU GARDIEN (CLI.JS) ---
15
+ // --- LE CONTENU DU CLI (Version "Secure Uplink") ---
16
16
  const CLI_SCRIPT_CONTENT = `#!/usr/bin/env node
17
17
 
18
18
  const { spawn, execSync } = require('child_process');
@@ -25,7 +25,7 @@ const os = require('os');
25
25
  const UPDATE_NETWORK_URL = 'https://us-central1-myapp-259bf.cloudfunctions.net/updateDeveloperNetwork';
26
26
  const PORT = 3000;
27
27
 
28
- // Nettoyage des ports (Mac/Linux)
28
+ // Gestion des processus système (Mac/Linux)
29
29
  function killProcessOnPort(port) {
30
30
  try {
31
31
  if (process.platform !== 'win32') {
@@ -37,8 +37,8 @@ function killProcessOnPort(port) {
37
37
  } catch (e) {}
38
38
  }
39
39
 
40
- // Nettoyage spécifique Cloudflare
41
- function killCloudflared() {
40
+ // Gestion du service réseau
41
+ function killNetworkService() {
42
42
  try {
43
43
  const cmd = process.platform === 'win32' ? 'taskkill /IM cloudflared.exe /F' : 'pkill cloudflared';
44
44
  execSync(cmd + ' 2>/dev/null');
@@ -46,8 +46,8 @@ function killCloudflared() {
46
46
  }
47
47
 
48
48
  async function cleanupAndExit(code = 0) {
49
- console.log('\\n[Fleetbo] 🛑 Stopping services...');
50
- killCloudflared();
49
+ console.log('\\n[Fleetbo] 🛑 Stopping development environment...');
50
+ killNetworkService();
51
51
  killProcessOnPort(PORT);
52
52
  process.exit(code);
53
53
  }
@@ -59,7 +59,7 @@ async function syncFirebase(keyApp, networkUrl) {
59
59
  try {
60
60
  await axios.post(UPDATE_NETWORK_URL, { keyApp, networkUrl });
61
61
  console.log('\\n[Fleetbo] ---------------------------------------------------');
62
- console.log(\`[Fleetbo] ✅ Tunnel Active: \${networkUrl}\`);
62
+ console.log(\`[Fleetbo] ✅ Uplink Status: Online\`);
63
63
  console.log(\`[Fleetbo] 🚀 Simulator: https://fleetbo.io/studio/view/\${keyApp}\`);
64
64
  console.log('[Fleetbo] ---------------------------------------------------\\n');
65
65
  } catch (err) {
@@ -67,23 +67,23 @@ async function syncFirebase(keyApp, networkUrl) {
67
67
  }
68
68
  }
69
69
 
70
- async function runGuardian() {
71
- console.log(\`[Fleetbo] 🛡️ Starting Fleetbo Guardian on \${os.platform()}...\`);
70
+ async function runDevEnvironment() {
71
+ console.log(\`[Fleetbo] 🛡️ Initializing Developer Environment on \${os.platform()}...\`);
72
72
 
73
73
  // 1. NETTOYAGE PRÉVENTIF
74
- killCloudflared();
74
+ killNetworkService();
75
75
  killProcessOnPort(PORT);
76
76
 
77
77
  const envPath = path.join(process.cwd(), '.env');
78
78
  if (!fs.existsSync(envPath)) {
79
- console.error('Error: .env file not found.');
79
+ console.error('Error: Configuration file not found.');
80
80
  process.exit(1);
81
81
  }
82
82
  dotenv.config({ path: envPath });
83
83
  const keyApp = process.env.REACT_KEY_APP;
84
84
 
85
- // 2. DÉMARRAGE REACT
86
- console.log(\`[Fleetbo] 📦 Booting React Server...\`);
85
+ // 2. DÉMARRAGE DU SERVEUR LOCAL
86
+ console.log(\`[Fleetbo] 📦 Starting Local Server...\`);
87
87
  const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
88
88
 
89
89
  const devServer = spawn(npmCmd, ['start'], {
@@ -94,24 +94,23 @@ async function runGuardian() {
94
94
  devServer.stdout.pipe(process.stdout);
95
95
  devServer.stderr.pipe(process.stderr);
96
96
 
97
- let tunnelStarted = false;
97
+ let connectionStarted = false;
98
98
 
99
99
  devServer.stdout.on('data', (data) => {
100
100
  const output = data.toString();
101
101
 
102
- if (!tunnelStarted && (output.includes('Local:') || output.includes('Compiled successfully'))) {
103
- tunnelStarted = true;
104
- console.log(\`\\n[Fleetbo] 🔗 React is ready. Establishing secure tunnel...\`);
102
+ if (!connectionStarted && (output.includes('Local:') || output.includes('Compiled successfully'))) {
103
+ connectionStarted = true;
104
+ console.log(\`\\n[Fleetbo] 🔗 Local Server Ready. Establishing Secure Uplink...\`);
105
105
 
106
- // 3. DÉMARRAGE TUNNEL CLOUDFLARE
106
+ // 3. DÉMARRAGE DE LA LIAISON (UPLINK)
107
107
  const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
108
- const tunnel = spawn(npxCmd, ['cloudflared', 'tunnel', '--url', \`http://localhost:\${PORT}\`]);
108
+ const uplink = spawn(npxCmd, ['cloudflared', 'tunnel', '--url', \`http://localhost:\${PORT}\`]);
109
109
 
110
- tunnel.stderr.on('data', (chunk) => {
110
+ // Capture de l'URL (Silencieux)
111
+ uplink.stderr.on('data', (chunk) => {
111
112
  const log = chunk.toString();
112
113
 
113
- // --- REGEX CORRIGÉE AVEC DOUBLE ÉCHAPPEMENT ---
114
- // Dans ce fichier générateur, on doit écrire \\ pour obtenir \ dans le fichier final
115
114
  const match = log.match(/https:\\/\\/[a-zA-Z0-9-]+\\.trycloudflare\\.com/);
116
115
 
117
116
  if (match) {
@@ -123,14 +122,14 @@ async function runGuardian() {
123
122
  }
124
123
  });
125
124
 
126
- tunnel.on('error', (err) => {
127
- console.error("[Fleetbo] ❌ Tunnel Error. Ensure 'cloudflared' is installed.");
125
+ uplink.on('error', (err) => {
126
+ console.error("[Fleetbo] ❌ Uplink Error. Network component missing.");
128
127
  });
129
128
  }
130
129
  });
131
130
  }
132
131
 
133
- runGuardian();
132
+ runDevEnvironment();
134
133
  `;
135
134
 
136
135
  // --- Analyse des Arguments ---
@@ -219,7 +218,9 @@ async function setupProject() {
219
218
  if (!keys.enterpriseId) throw new Error("Invalid keys.");
220
219
 
221
220
  console.log(' [4/6] ⚙️ Configuring environment & CLI...');
222
- 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`;
221
+
222
+ // Hot Reload activé via WDS_SOCKET_PORT=0
223
+ const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\nREACT_KEY_APP=${projectName}\nDANGEROUSLY_DISABLE_HOST_CHECK=true\nWDS_SOCKET_PORT=0\n`;
223
224
 
224
225
  fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
225
226
  fs.writeFileSync(path.join(projectDir, 'cli.js'), CLI_SCRIPT_CONTENT, 'utf8');
@@ -227,7 +228,7 @@ async function setupProject() {
227
228
  console.log(' [5/6] 📚 Installing dependencies...');
228
229
  execSync('npm install', { stdio: 'inherit' });
229
230
 
230
- // Installation de cloudflared
231
+ // Installation silencieuse
231
232
  execSync('npm install cloudflared dotenv axios --save-dev', { stdio: 'ignore' });
232
233
 
233
234
  console.log(' [6/6] ✨ Finalizing setup...');
@@ -247,131 +248,4 @@ async function setupProject() {
247
248
  }
248
249
  }
249
250
 
250
- setupProject();
251
-
252
-
253
- {/*
254
-
255
- const { execSync } = require('child_process');
256
- const fs = require('fs');
257
- const path = require('path');
258
- const https = require('https');
259
-
260
- // --- Configuration ---
261
- const repoOwner = 'FleetFleetbo';
262
- const repoName = 'dev.fleetbo.io';
263
- const branchName = 'master'; // Assurez-vous que c'est la bonne branche
264
-
265
- const repoGitUrl = `https://github.com/${repoOwner}/${repoName}.git`;
266
- const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
267
-
268
- // --- Analyse des Arguments ---
269
- const args = process.argv.slice(2);
270
- const projectNameArg = args.find(arg => !arg.startsWith('--'));
271
- const tokenArg = args.find(arg => arg.startsWith('--token='));
272
-
273
- if (!projectNameArg) {
274
- console.error('\n Error : Please specify a name for your project.');
275
- console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
276
- process.exit(1);
277
- }
278
-
279
- const bootstrapToken = tokenArg ? tokenArg.split('=')[1] : null;
280
-
281
- if (!bootstrapToken) {
282
- console.error('\n Error : "The bootstrap token is missing.');
283
- console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
284
- process.exit(1);
285
- }
286
-
287
- const projectName = projectNameArg;
288
-
289
- // --- Fonctions Utilitaires ---
290
-
291
- function fetchProjectKeys(token) {
292
- return new Promise((resolve, reject) => {
293
- const postData = JSON.stringify({ token });
294
- const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } };
295
- const req = https.request(bootstrapUrl, options, (res) => {
296
- let data = '';
297
- res.on('data', (chunk) => { data += chunk; });
298
- res.on('end', () => {
299
- if (res.statusCode >= 200 && res.statusCode < 300) {
300
- try {
301
- resolve(JSON.parse(data));
302
- } catch (e) {
303
- reject(new Error('Invalid response from the key server.'));
304
- }
305
- } else {
306
- const errorMsg = JSON.parse(data).error || `Server error (code: ${res.statusCode})`;
307
- reject(new Error(errorMsg));
308
- }
309
- });
310
- });
311
- req.on('error', (e) => reject(e));
312
- req.write(postData);
313
- req.end();
314
- });
315
- }
316
-
317
- // --- Fonction Principale ---
318
-
319
- async function setupProject() {
320
- console.log(`\nCreating your Fleetbo project "${projectName}"...`);
321
- const projectDir = path.join(process.cwd(), projectName);
322
-
323
- try {
324
- // Étape 1 : Télécharger la structure de base du projet
325
- console.log(' [1/5] Initializing project structure...');
326
- // On redirige la sortie d'erreur (stderr) vers null pour masquer les messages de progression de Git
327
- execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}" 2> /dev/null`);
328
-
329
- // Étape 2 : Se déplacer dans le dossier du projet et nettoyer
330
- console.log(' [2/5] Project structure initialized. Configuring...');
331
- process.chdir(projectDir);
332
-
333
- // Supprimer l'historique Git pour commencer avec un projet propre
334
- fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
335
-
336
- // Étape 3 : Récupération des clés de projet
337
- console.log(' [3/5] Fetching project keys...');
338
- const keys = await fetchProjectKeys(bootstrapToken);
339
- if (!keys.enterpriseId || !keys.fleetboDBKey) {
340
- throw new Error("Received keys from the server are invalid.");
341
- }
342
-
343
- // Étape 4 : Configuration du fichier .env
344
- console.log(' [4/5] .env file configured successfully.');
345
- //const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`; //99b426483d543b042209671dd53fb18
346
- const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=99b426483d543b042209671dd53fb18\nREACT_KEY_APP=${projectName}\n`;
347
- fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
348
-
349
- // Étape 5 : Installation des dépendances
350
- console.log(' [5/5] Installing dependencies...');
351
- execSync('npm install', { stdio: 'inherit' });
352
-
353
- // Personnalisation du package.json
354
- const packageJsonPath = path.join(projectDir, 'package.json');
355
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
356
- packageJson.name = projectName;
357
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
358
-
359
- console.log('\n🚀 Your Fleetbo project is ready !');
360
- console.log(`\nTo get started, run the following commands :`);
361
- console.log(` cd ${projectName}`);
362
- console.log(` npx fleetbo start`);
363
-
364
- } catch (error) {
365
- console.error('\n An error occurred while creating the project :', error.message);
366
- // Nettoyage en cas d'erreur
367
- if (fs.existsSync(projectDir)) {
368
- fs.rmSync(projectDir, { recursive: true, force: true });
369
- }
370
- }
371
- }
372
-
373
- setupProject();
374
- */}
375
-
376
-
377
-
251
+ setupProject();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.2.23",
3
+ "version": "1.2.25",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {