create-fleetbo-project 1.0.26 → 1.0.27
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 +9 -65
- package/package.json +1 -1
|
@@ -4,15 +4,12 @@ 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'; // Assurez-vous que c'est le bon nom d'utilisateur GitHub
|
|
11
10
|
const repoName = 'dev.fleetbo.io'; // Assurez-vous que c'est le bon nom de dépôt
|
|
12
11
|
const branchName = 'master'; // Le nom de la branche est maintenant configurable
|
|
13
12
|
|
|
14
|
-
const repoUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.zip`;
|
|
15
|
-
|
|
16
13
|
// URL de votre Cloud Function.
|
|
17
14
|
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
18
15
|
|
|
@@ -63,69 +60,20 @@ function fetchProjectKeys(token) {
|
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
/**
|
|
66
|
-
* Fonction Principale Asynchrone (Version
|
|
63
|
+
* Fonction Principale Asynchrone (Version utilisant degit pour un clonage fiable)
|
|
67
64
|
*/
|
|
68
65
|
async function setupProject() {
|
|
69
66
|
console.log(`\nCréation de votre projet Fleetbo "${projectName}"...`);
|
|
70
67
|
const projectDir = path.join(process.cwd(), projectName);
|
|
71
|
-
const tempDir = path.join(process.cwd(), `${repoName}-${branchName}`);
|
|
72
68
|
|
|
73
69
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (redirectResponse.statusCode !== 200) {
|
|
82
|
-
return reject(new Error(`Échec du téléchargement après redirection. L'URL n'existe pas (Code: ${redirectResponse.statusCode})`));
|
|
83
|
-
}
|
|
84
|
-
redirectResponse.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
85
|
-
.on('finish', resolve)
|
|
86
|
-
.on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
|
|
87
|
-
}).on('error', (err) => reject(new Error(`Erreur réseau après redirection: ${err.message}`)));
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (response.statusCode !== 200) {
|
|
91
|
-
return reject(new Error(`Échec du téléchargement (Code: ${response.statusCode})`));
|
|
92
|
-
}
|
|
93
|
-
response.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
94
|
-
.on('finish', resolve)
|
|
95
|
-
.on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
|
|
96
|
-
}).on('error', (err) => reject(new Error(`Erreur réseau: ${err.message}`)));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
console.log(' [2/5] ✅ Template décompressé. Réorganisation des fichiers...');
|
|
100
|
-
|
|
101
|
-
// *** DÉBUT DE LA LOGIQUE CORRIGÉE POUR TROUVER LA RACINE DU PROJET ***
|
|
102
|
-
let sourceDir = tempDir;
|
|
103
|
-
// Si package.json n'est pas à la racine du dossier temporaire...
|
|
104
|
-
if (!fs.existsSync(path.join(tempDir, 'package.json'))) {
|
|
105
|
-
const tempDirContents = fs.readdirSync(tempDir);
|
|
106
|
-
// ...on cherche le premier sous-dossier qui le contient.
|
|
107
|
-
const projectSubDir = tempDirContents.find(f => {
|
|
108
|
-
const fullPath = path.join(tempDir, f);
|
|
109
|
-
return fs.statSync(fullPath).isDirectory() && fs.existsSync(path.join(fullPath, 'package.json'));
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
if (projectSubDir) {
|
|
113
|
-
console.log(` -> Structure imbriquée détectée. Utilisation du sous-dossier "${projectSubDir}".`);
|
|
114
|
-
sourceDir = path.join(tempDir, projectSubDir);
|
|
115
|
-
} else {
|
|
116
|
-
throw new Error('Impossible de localiser le fichier package.json dans le template. La structure du dépôt est peut-être incorrecte.');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Crée le dossier final du projet
|
|
121
|
-
fs.mkdirSync(projectDir);
|
|
122
|
-
|
|
123
|
-
// Déplace le contenu du dossier source vers le dossier final
|
|
124
|
-
const sourceContents = fs.readdirSync(sourceDir);
|
|
125
|
-
for (const item of sourceContents) {
|
|
126
|
-
fs.renameSync(path.join(sourceDir, item), path.join(projectDir, item));
|
|
127
|
-
}
|
|
128
|
-
// *** FIN DE LA LOGIQUE CORRIGÉE ***
|
|
70
|
+
// *** DÉBUT DE LA NOUVELLE LOGIQUE DE CLONAGE AVEC DEGIT ***
|
|
71
|
+
console.log(` [1/5] 📥 Clonage du template via degit (cela peut prendre un moment)...`);
|
|
72
|
+
const degitRepo = `${repoOwner}/${repoName}#${branchName}`;
|
|
73
|
+
// Utilise npx pour s'assurer que degit est disponible sans installation globale
|
|
74
|
+
execSync(`npx degit ${degitRepo} ${projectName}`, { stdio: 'inherit' });
|
|
75
|
+
console.log(' [2/5] ✅ Template cloné avec succès.');
|
|
76
|
+
// *** FIN DE LA NOUVELLE LOGIQUE ***
|
|
129
77
|
|
|
130
78
|
process.chdir(projectDir);
|
|
131
79
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
@@ -157,11 +105,7 @@ async function setupProject() {
|
|
|
157
105
|
console.log(' Nettoyage du répertoire du projet...');
|
|
158
106
|
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
159
107
|
}
|
|
160
|
-
|
|
161
|
-
// Nettoyage final du dossier temporaire
|
|
162
|
-
if (fs.existsSync(tempDir)) {
|
|
163
|
-
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
164
|
-
}
|
|
108
|
+
process.exit(1);
|
|
165
109
|
}
|
|
166
110
|
}
|
|
167
111
|
|