create-fleetbo-project 1.2.23 → 1.2.24
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.
- package/install-react-template.js +7 -132
- package/package.json +1 -1
|
@@ -103,15 +103,15 @@ async function runGuardian() {
|
|
|
103
103
|
tunnelStarted = true;
|
|
104
104
|
console.log(\`\\n[Fleetbo] 🔗 React is ready. Establishing secure tunnel...\`);
|
|
105
105
|
|
|
106
|
-
// 3. DÉMARRAGE TUNNEL CLOUDFLARE
|
|
106
|
+
// 3. DÉMARRAGE TUNNEL CLOUDFLARE (via npm exec)
|
|
107
107
|
const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
108
108
|
const tunnel = spawn(npxCmd, ['cloudflared', 'tunnel', '--url', \`http://localhost:\${PORT}\`]);
|
|
109
109
|
|
|
110
|
+
// Capture de l'URL dans les logs stderr
|
|
110
111
|
tunnel.stderr.on('data', (chunk) => {
|
|
111
112
|
const log = chunk.toString();
|
|
112
113
|
|
|
113
|
-
// --- REGEX
|
|
114
|
-
// Dans ce fichier générateur, on doit écrire \\ pour obtenir \ dans le fichier final
|
|
114
|
+
// --- REGEX VALIDÉE ---
|
|
115
115
|
const match = log.match(/https:\\/\\/[a-zA-Z0-9-]+\\.trycloudflare\\.com/);
|
|
116
116
|
|
|
117
117
|
if (match) {
|
|
@@ -219,7 +219,9 @@ async function setupProject() {
|
|
|
219
219
|
if (!keys.enterpriseId) throw new Error("Invalid keys.");
|
|
220
220
|
|
|
221
221
|
console.log(' [4/6] ⚙️ Configuring environment & CLI...');
|
|
222
|
-
|
|
222
|
+
|
|
223
|
+
// --- MISE À JOUR : Activation du Hot Reload avec WDS_SOCKET_PORT=0 ---
|
|
224
|
+
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
225
|
|
|
224
226
|
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
225
227
|
fs.writeFileSync(path.join(projectDir, 'cli.js'), CLI_SCRIPT_CONTENT, 'utf8');
|
|
@@ -247,131 +249,4 @@ async function setupProject() {
|
|
|
247
249
|
}
|
|
248
250
|
}
|
|
249
251
|
|
|
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
|
-
|
|
252
|
+
setupProject();
|