create-fleetbo-project 1.0.16 → 1.0.18
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 +79 -12
- 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 avec téléchargement complet)
|
|
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,10 +23,59 @@ if (!projectName || !bootstrapToken) {
|
|
|
24
23
|
process.exit(1);
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
// --- Fonction pour télécharger le fichier ---
|
|
27
|
+
function downloadFile(url, dest) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const file = fs.createWriteStream(dest);
|
|
30
|
+
https.get(url, (response) => {
|
|
31
|
+
// Gérer les redirections
|
|
32
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
33
|
+
file.close();
|
|
34
|
+
fs.unlinkSync(dest);
|
|
35
|
+
return downloadFile(response.headers.location, dest).then(resolve).catch(reject);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (response.statusCode !== 200) {
|
|
39
|
+
file.close();
|
|
40
|
+
fs.unlinkSync(dest);
|
|
41
|
+
return reject(new Error(`Échec du téléchargement: ${response.statusCode}`));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
response.pipe(file);
|
|
45
|
+
|
|
46
|
+
file.on('finish', () => {
|
|
47
|
+
file.close(() => resolve());
|
|
48
|
+
});
|
|
49
|
+
}).on('error', (err) => {
|
|
50
|
+
fs.unlinkSync(dest);
|
|
51
|
+
reject(err);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
file.on('error', (err) => {
|
|
55
|
+
fs.unlinkSync(dest);
|
|
56
|
+
reject(err);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// --- Fonction pour décompresser ---
|
|
62
|
+
function extractZip(zipPath, extractTo) {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
fs.createReadStream(zipPath)
|
|
65
|
+
.pipe(unzipper.Extract({ path: extractTo }))
|
|
66
|
+
.on('close', () => {
|
|
67
|
+
// Attendre un peu pour s'assurer que tous les fichiers sont écrits
|
|
68
|
+
setTimeout(resolve, 500);
|
|
69
|
+
})
|
|
70
|
+
.on('error', reject);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
27
74
|
// --- Fonction Principale ---
|
|
28
75
|
async function setupProject() {
|
|
29
76
|
console.log(chalk.blue(`Création de votre projet Fleetbo "${projectName}"...`));
|
|
30
77
|
const spinner = ora();
|
|
78
|
+
const tempZip = path.join(process.cwd(), 'temp-fleetbo.zip');
|
|
31
79
|
|
|
32
80
|
try {
|
|
33
81
|
spinner.start('Récupération de la configuration sécurisée...');
|
|
@@ -36,15 +84,28 @@ async function setupProject() {
|
|
|
36
84
|
spinner.succeed(chalk.green('Configuration récupérée !'));
|
|
37
85
|
|
|
38
86
|
spinner.start('Téléchargement du template...');
|
|
39
|
-
|
|
87
|
+
await downloadFile(repoUrl, tempZip);
|
|
40
88
|
spinner.succeed(chalk.green('Template téléchargé.'));
|
|
41
89
|
|
|
42
90
|
spinner.start('Décompression des fichiers...');
|
|
43
|
-
await
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
91
|
+
await extractZip(tempZip, '.');
|
|
92
|
+
|
|
93
|
+
// Supprimer le fichier ZIP temporaire
|
|
94
|
+
fs.unlinkSync(tempZip);
|
|
95
|
+
|
|
96
|
+
const extractedDir = 'dev.fleetbo.io-main';
|
|
97
|
+
|
|
98
|
+
// Vérifier que le dossier existe
|
|
99
|
+
if (!fs.existsSync(extractedDir)) {
|
|
100
|
+
throw new Error(`Le dossier ${extractedDir} n'a pas été créé après la décompression`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Vérifier que le dossier cible n'existe pas déjà
|
|
104
|
+
if (fs.existsSync(projectName)) {
|
|
105
|
+
throw new Error(`Le dossier ${projectName} existe déjà`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fs.renameSync(extractedDir, projectName);
|
|
48
109
|
spinner.succeed(chalk.green('Fichiers décompressés.'));
|
|
49
110
|
|
|
50
111
|
process.chdir(projectName);
|
|
@@ -52,7 +113,7 @@ async function setupProject() {
|
|
|
52
113
|
spinner.start('Configuration du projet...');
|
|
53
114
|
const envContent = `REACT_APP_FLEETBO_DB_KEY="${projectSecrets.fleetboDB}"\nREACT_APP_ENTERPRISE_ID=${projectSecrets.appId}\n`;
|
|
54
115
|
fs.writeFileSync('.env', envContent, 'utf8');
|
|
55
|
-
|
|
116
|
+
|
|
56
117
|
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
57
118
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
58
119
|
packageJson.name = projectName;
|
|
@@ -65,11 +126,17 @@ async function setupProject() {
|
|
|
65
126
|
|
|
66
127
|
console.log(chalk.green.bold('\n🚀 Votre projet Fleetbo est prêt !'));
|
|
67
128
|
console.log(`\nPour commencer :`);
|
|
68
|
-
console.log(chalk.cyan(`
|
|
69
|
-
console.log(chalk.cyan(`
|
|
129
|
+
console.log(chalk.cyan(` cd ${projectName}`));
|
|
130
|
+
console.log(chalk.cyan(` npm start`));
|
|
70
131
|
|
|
71
132
|
} catch (error) {
|
|
72
133
|
if (spinner.isSpinning) spinner.fail();
|
|
134
|
+
|
|
135
|
+
// Nettoyer le fichier temporaire en cas d'erreur
|
|
136
|
+
if (fs.existsSync(tempZip)) {
|
|
137
|
+
fs.unlinkSync(tempZip);
|
|
138
|
+
}
|
|
139
|
+
|
|
73
140
|
console.error(chalk.red('\n❌ Une erreur est survenue :'), error.response ? error.response.data : error.message);
|
|
74
141
|
process.exit(1);
|
|
75
142
|
}
|