create-fleetbo-project 1.0.16 → 1.0.17
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 +48 -11
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// install-react-template.js (Version
|
|
2
|
+
// Fichier : install-react-template.js (Version corrigée)
|
|
3
3
|
const { execSync } = require('child_process');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
@@ -14,8 +14,7 @@ const projectName = process.argv[2];
|
|
|
14
14
|
const tokenArgIndex = process.argv.indexOf('--token');
|
|
15
15
|
const bootstrapToken = tokenArgIndex !== -1 ? process.argv[tokenArgIndex + 1] : null;
|
|
16
16
|
const repoUrl = 'https://github.com/FleetFleetbo/dev.fleetbo.io/archive/refs/heads/main.zip';
|
|
17
|
-
|
|
18
|
-
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
17
|
+
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
19
18
|
|
|
20
19
|
// --- Validation ---
|
|
21
20
|
if (!projectName || !bootstrapToken) {
|
|
@@ -24,6 +23,23 @@ if (!projectName || !bootstrapToken) {
|
|
|
24
23
|
process.exit(1);
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
// --- Fonction pour attendre que le dossier existe ---
|
|
27
|
+
function waitForDirectory(dirPath, timeout = 10000) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const startTime = Date.now();
|
|
30
|
+
const interval = setInterval(() => {
|
|
31
|
+
if (fs.existsSync(dirPath)) {
|
|
32
|
+
clearInterval(interval);
|
|
33
|
+
// Attendre un peu plus pour s'assurer que tous les fichiers sont écrits
|
|
34
|
+
setTimeout(() => resolve(), 500);
|
|
35
|
+
} else if (Date.now() - startTime > timeout) {
|
|
36
|
+
clearInterval(interval);
|
|
37
|
+
reject(new Error(`Le dossier ${dirPath} n'a pas été créé dans le délai imparti`));
|
|
38
|
+
}
|
|
39
|
+
}, 100);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
27
43
|
// --- Fonction Principale ---
|
|
28
44
|
async function setupProject() {
|
|
29
45
|
console.log(chalk.blue(`Création de votre projet Fleetbo "${projectName}"...`));
|
|
@@ -36,23 +52,44 @@ async function setupProject() {
|
|
|
36
52
|
spinner.succeed(chalk.green('Configuration récupérée !'));
|
|
37
53
|
|
|
38
54
|
spinner.start('Téléchargement du template...');
|
|
39
|
-
const responseStream = await new Promise((resolve, reject) =>
|
|
55
|
+
const responseStream = await new Promise((resolve, reject) => {
|
|
56
|
+
https.get(repoUrl, res => resolve(res)).on('error', err => reject(err));
|
|
57
|
+
});
|
|
40
58
|
spinner.succeed(chalk.green('Template téléchargé.'));
|
|
41
59
|
|
|
42
60
|
spinner.start('Décompression des fichiers...');
|
|
61
|
+
|
|
62
|
+
// Décompression avec gestion d'erreur améliorée
|
|
43
63
|
await new Promise((resolve, reject) => {
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
responseStream
|
|
65
|
+
.pipe(unzipper.Extract({ path: '.' }))
|
|
66
|
+
.on('close', resolve) // 'close' est plus fiable que 'finish'
|
|
67
|
+
.on('error', reject);
|
|
46
68
|
});
|
|
47
|
-
|
|
69
|
+
|
|
70
|
+
// Attendre que le dossier soit bien créé
|
|
71
|
+
const extractedDir = 'dev.fleetbo.io-main';
|
|
72
|
+
await waitForDirectory(extractedDir);
|
|
73
|
+
|
|
74
|
+
// Vérifier que le dossier existe avant de renommer
|
|
75
|
+
if (!fs.existsSync(extractedDir)) {
|
|
76
|
+
throw new Error(`Le dossier ${extractedDir} n'a pas été créé après la décompression`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Vérifier que le dossier cible n'existe pas déjà
|
|
80
|
+
if (fs.existsSync(projectName)) {
|
|
81
|
+
throw new Error(`Le dossier ${projectName} existe déjà`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fs.renameSync(extractedDir, projectName);
|
|
48
85
|
spinner.succeed(chalk.green('Fichiers décompressés.'));
|
|
49
86
|
|
|
50
87
|
process.chdir(projectName);
|
|
51
88
|
|
|
52
89
|
spinner.start('Configuration du projet...');
|
|
53
|
-
const envContent = `REACT_APP_FLEETBO_DB_KEY
|
|
90
|
+
const envContent = `REACT_APP_FLEETBO_DB_KEY=${projectSecrets.fleetboDB}\nREACT_APP_ENTERPRISE_ID=${projectSecrets.appId}\n`;
|
|
54
91
|
fs.writeFileSync('.env', envContent, 'utf8');
|
|
55
|
-
|
|
92
|
+
|
|
56
93
|
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
57
94
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
58
95
|
packageJson.name = projectName;
|
|
@@ -65,8 +102,8 @@ async function setupProject() {
|
|
|
65
102
|
|
|
66
103
|
console.log(chalk.green.bold('\n🚀 Votre projet Fleetbo est prêt !'));
|
|
67
104
|
console.log(`\nPour commencer :`);
|
|
68
|
-
console.log(chalk.cyan(`
|
|
69
|
-
console.log(chalk.cyan(`
|
|
105
|
+
console.log(chalk.cyan(` cd ${projectName}`));
|
|
106
|
+
console.log(chalk.cyan(` npm start`));
|
|
70
107
|
|
|
71
108
|
} catch (error) {
|
|
72
109
|
if (spinner.isSpinning) spinner.fail();
|