create-fleetbo-project 1.0.21 → 1.0.22
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 +28 -33
- package/package.json +1 -1
|
@@ -7,11 +7,13 @@ const https = require('https');
|
|
|
7
7
|
const unzipper = require('unzipper');
|
|
8
8
|
|
|
9
9
|
// --- Configuration ---
|
|
10
|
-
|
|
11
|
-
const
|
|
10
|
+
// !!! VÉRIFIEZ ET CORRIGEZ CES DEUX LIGNES !!!
|
|
11
|
+
const repoOwner = 'FleetFleetbo'; // Assurez-vous que c'est le bon nom d'utilisateur GitHub
|
|
12
|
+
const repoName = 'dev.fleetbo.io'; // Assurez-vous que c'est le bon nom de dépôt
|
|
13
|
+
|
|
12
14
|
const repoUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/main.zip`;
|
|
13
15
|
|
|
14
|
-
// URL de votre Cloud Function.
|
|
16
|
+
// URL de votre Cloud Function.
|
|
15
17
|
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
16
18
|
|
|
17
19
|
// --- Analyse des Arguments ---
|
|
@@ -41,15 +43,7 @@ const projectName = projectNameArg;
|
|
|
41
43
|
function fetchProjectKeys(token) {
|
|
42
44
|
return new Promise((resolve, reject) => {
|
|
43
45
|
const postData = JSON.stringify({ token });
|
|
44
|
-
|
|
45
|
-
const options = {
|
|
46
|
-
method: 'POST',
|
|
47
|
-
headers: {
|
|
48
|
-
'Content-Type': 'application/json',
|
|
49
|
-
'Content-Length': Buffer.byteLength(postData),
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
|
|
46
|
+
const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } };
|
|
53
47
|
const req = https.request(bootstrapUrl, options, (res) => {
|
|
54
48
|
let data = '';
|
|
55
49
|
res.on('data', (chunk) => { data += chunk; });
|
|
@@ -62,34 +56,29 @@ function fetchProjectKeys(token) {
|
|
|
62
56
|
}
|
|
63
57
|
});
|
|
64
58
|
});
|
|
65
|
-
|
|
66
59
|
req.on('error', (e) => reject(e));
|
|
67
60
|
req.write(postData);
|
|
68
61
|
req.end();
|
|
69
62
|
});
|
|
70
63
|
}
|
|
71
64
|
|
|
72
|
-
|
|
73
65
|
/**
|
|
74
|
-
* Fonction Principale Asynchrone
|
|
75
|
-
*/
|
|
76
|
-
/**
|
|
77
|
-
* Fonction Principale Asynchrone (Version corrigée)
|
|
66
|
+
* Fonction Principale Asynchrone (Version avec meilleur débogage)
|
|
78
67
|
*/
|
|
79
68
|
async function setupProject() {
|
|
80
69
|
console.log(`\nCréation de votre projet Fleetbo "${projectName}"...`);
|
|
81
70
|
|
|
82
71
|
try {
|
|
83
|
-
// Étape 1 & 2 : Télécharger et décompresser de manière sécurisée
|
|
84
72
|
console.log(' [1/5] 📥 Téléchargement du template...');
|
|
85
73
|
await new Promise((resolve, reject) => {
|
|
86
74
|
https.get(repoUrl, (response) => {
|
|
87
|
-
// Gérer les redirections (très courant avec GitHub)
|
|
88
75
|
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
const redirectUrl = response.headers.location;
|
|
77
|
+
// Log de l'URL pour faciliter le débogage
|
|
78
|
+
console.log(` -> Redirection détectée, suivi du lien : ${redirectUrl}`);
|
|
79
|
+
https.get(redirectUrl, (redirectResponse) => {
|
|
91
80
|
if (redirectResponse.statusCode !== 200) {
|
|
92
|
-
return reject(new Error(`Échec du téléchargement après redirection.
|
|
81
|
+
return reject(new Error(`Échec du téléchargement après redirection. L'URL n'existe pas (Code: ${redirectResponse.statusCode})`));
|
|
93
82
|
}
|
|
94
83
|
redirectResponse.pipe(unzipper.Extract({ path: '.' }))
|
|
95
84
|
.on('finish', resolve)
|
|
@@ -98,22 +87,27 @@ async function setupProject() {
|
|
|
98
87
|
return;
|
|
99
88
|
}
|
|
100
89
|
|
|
101
|
-
// Gérer les erreurs directes (ex: 404 Dépôt non trouvé)
|
|
102
90
|
if (response.statusCode !== 200) {
|
|
103
|
-
return reject(new Error(`Échec du téléchargement
|
|
91
|
+
return reject(new Error(`Échec du téléchargement. Le dépôt est peut-être privé ou l'URL est incorrecte (Code: ${response.statusCode})`));
|
|
104
92
|
}
|
|
105
93
|
|
|
106
|
-
// Si le code est 200 OK, on décompresse
|
|
107
94
|
response.pipe(unzipper.Extract({ path: '.' }))
|
|
108
95
|
.on('finish', resolve)
|
|
109
96
|
.on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
|
|
110
97
|
|
|
111
98
|
}).on('error', (err) => reject(new Error(`Erreur réseau lors du téléchargement: ${err.message}`)));
|
|
112
99
|
});
|
|
100
|
+
|
|
101
|
+
// La suite du script a été omise pour la brièveté mais reste identique...
|
|
102
|
+
// ...
|
|
103
|
+
// Le renommage et le reste de la logique doit être ici
|
|
104
|
+
// ...
|
|
113
105
|
|
|
114
106
|
console.log(' [2/5] ✅ Template téléchargé et décompressé.');
|
|
107
|
+
|
|
108
|
+
// Le dossier décompressé aura un nom comme "repoName-main", on le renomme
|
|
109
|
+
fs.renameSync(`${repoName}-main`, projectName);
|
|
115
110
|
|
|
116
|
-
// Le reste du script continue ici
|
|
117
111
|
process.chdir(projectName);
|
|
118
112
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
119
113
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
@@ -121,16 +115,13 @@ async function setupProject() {
|
|
|
121
115
|
throw new Error("Les clés reçues du serveur sont invalides.");
|
|
122
116
|
}
|
|
123
117
|
|
|
124
|
-
|
|
118
|
+
console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
|
|
125
119
|
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`;
|
|
126
120
|
fs.writeFileSync(path.join(process.cwd(), '.env'), envContent, 'utf8');
|
|
127
|
-
console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
|
|
128
121
|
|
|
129
|
-
// 5. Installer les dépendances
|
|
130
122
|
console.log(' [5/5] 📦 Installation des dépendances (cela peut prendre quelques minutes)...');
|
|
131
123
|
execSync('npm install', { stdio: 'inherit' });
|
|
132
124
|
|
|
133
|
-
// Mise à jour du package.json
|
|
134
125
|
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
135
126
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
136
127
|
packageJson.name = projectName;
|
|
@@ -143,14 +134,18 @@ async function setupProject() {
|
|
|
143
134
|
|
|
144
135
|
} catch (error) {
|
|
145
136
|
console.error('\n❌ Une erreur est survenue lors de la création du projet :', error.message);
|
|
146
|
-
// Nettoyage en cas d'erreur
|
|
147
137
|
const dirToDelete = path.join(process.cwd(), projectName);
|
|
148
138
|
if (fs.existsSync(dirToDelete)) {
|
|
149
139
|
console.log(' Nettoyage du répertoire du projet...');
|
|
150
140
|
fs.rmSync(dirToDelete, { recursive: true, force: true });
|
|
151
141
|
}
|
|
142
|
+
const extractedDir = path.join(process.cwd(), `${repoName}-main`);
|
|
143
|
+
if (fs.existsSync(extractedDir)) {
|
|
144
|
+
console.log(' Nettoyage du répertoire temporaire...');
|
|
145
|
+
fs.rmSync(extractedDir, { recursive: true, force: true });
|
|
146
|
+
}
|
|
152
147
|
process.exit(1);
|
|
153
148
|
}
|
|
154
149
|
}
|
|
155
150
|
|
|
156
|
-
setupProject();
|
|
151
|
+
setupProject();
|