create-fleetbo-project 1.0.36 → 1.0.37
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 +12 -37
- package/package.json +1 -1
|
@@ -4,14 +4,13 @@ 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 unzipper = require('unzipper');
|
|
8
7
|
|
|
9
8
|
// --- Configuration ---
|
|
10
9
|
const repoOwner = 'FleetFleetbo';
|
|
11
10
|
const repoName = 'dev.fleetbo.io';
|
|
12
11
|
const branchName = 'master'; // Assurez-vous que c'est la bonne branche
|
|
13
12
|
|
|
14
|
-
const
|
|
13
|
+
const repoGitUrl = `https://github.com/${repoOwner}/${repoName}.git`;
|
|
15
14
|
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
16
15
|
|
|
17
16
|
// --- Analyse des Arguments ---
|
|
@@ -67,54 +66,33 @@ function fetchProjectKeys(token) {
|
|
|
67
66
|
|
|
68
67
|
async function setupProject() {
|
|
69
68
|
console.log(`\nCréation de votre projet Fleetbo "${projectName}"...`);
|
|
70
|
-
|
|
71
|
-
// Le nom du dossier que GitHub crée dans le .zip
|
|
72
|
-
const unzippedDirName = `${repoName}-${branchName}`;
|
|
73
|
-
const sourceDir = path.join(process.cwd(), unzippedDirName);
|
|
74
69
|
const projectDir = path.join(process.cwd(), projectName);
|
|
75
70
|
|
|
76
71
|
try {
|
|
77
|
-
// Étape 1 :
|
|
78
|
-
console.log(' [1/5] 📥
|
|
79
|
-
|
|
80
|
-
https.get(repoUrl, (response) => {
|
|
81
|
-
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
82
|
-
return https.get(response.headers.location, (redirectResponse) => {
|
|
83
|
-
redirectResponse.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
84
|
-
.on('finish', resolve)
|
|
85
|
-
.on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
|
|
86
|
-
}).on('error', (err) => reject(new Error(`Erreur réseau après redirection: ${err.message}`)));
|
|
87
|
-
} else if (response.statusCode !== 200) {
|
|
88
|
-
return reject(new Error(`Échec du téléchargement. Statut: ${response.statusCode}`));
|
|
89
|
-
} else {
|
|
90
|
-
response.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
91
|
-
.on('finish', resolve)
|
|
92
|
-
.on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
|
|
93
|
-
}
|
|
94
|
-
}).on('error', (err) => reject(new Error(`Erreur réseau: ${err.message}`)));
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Étape 2 : Renommer le dossier décompressé
|
|
98
|
-
console.log(' [2/5] ✅ Template décompressé. Renommage du dossier...');
|
|
99
|
-
if (fs.existsSync(sourceDir)) {
|
|
100
|
-
fs.renameSync(sourceDir, projectDir);
|
|
101
|
-
} else {
|
|
102
|
-
throw new Error(`Le dossier attendu "${unzippedDirName}" n'a pas été trouvé après la décompression.`);
|
|
103
|
-
}
|
|
72
|
+
// Étape 1 : Cloner le dépôt avec Git (plus robuste que le zip)
|
|
73
|
+
console.log(' [1/5] 📥 Clonage du template via Git...');
|
|
74
|
+
execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}"`, { stdio: 'inherit' });
|
|
104
75
|
|
|
105
|
-
// Étape
|
|
76
|
+
// Étape 2 : Se déplacer dans le dossier du projet et nettoyer
|
|
77
|
+
console.log(' [2/5] ✅ Template cloné. Configuration du projet...');
|
|
106
78
|
process.chdir(projectDir);
|
|
107
79
|
|
|
80
|
+
// Supprimer le dossier .git pour commencer avec un projet propre
|
|
81
|
+
fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
|
|
82
|
+
|
|
83
|
+
// Étape 3 : Récupération des clés de projet
|
|
108
84
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
109
85
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
110
86
|
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
111
87
|
throw new Error("Les clés reçues du serveur sont invalides.");
|
|
112
88
|
}
|
|
113
89
|
|
|
90
|
+
// Étape 4 : Configuration du fichier .env
|
|
114
91
|
console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
|
|
115
92
|
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`;
|
|
116
93
|
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
117
94
|
|
|
95
|
+
// Étape 5 : Installation des dépendances
|
|
118
96
|
console.log(' [5/5] 📦 Installation des dépendances...');
|
|
119
97
|
execSync('npm install', { stdio: 'inherit' });
|
|
120
98
|
|
|
@@ -132,9 +110,6 @@ async function setupProject() {
|
|
|
132
110
|
} catch (error) {
|
|
133
111
|
console.error('\n❌ Une erreur est survenue lors de la création du projet :', error.message);
|
|
134
112
|
// Nettoyage en cas d'erreur
|
|
135
|
-
if (fs.existsSync(sourceDir)) {
|
|
136
|
-
fs.rmSync(sourceDir, { recursive: true, force: true });
|
|
137
|
-
}
|
|
138
113
|
if (fs.existsSync(projectDir)) {
|
|
139
114
|
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
140
115
|
}
|