create-fleetbo-project 1.0.21 → 1.0.23
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 +25 -34
- 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
|
-
const repoOwner = 'FleetFleetbo';
|
|
11
|
-
const repoName = 'dev.fleetbo.io';
|
|
12
|
-
const
|
|
10
|
+
const repoOwner = 'FleetFleetbo'; // Assurez-vous que c'est le bon nom d'utilisateur GitHub
|
|
11
|
+
const repoName = 'dev.fleetbo.io'; // Assurez-vous que c'est le bon nom de dépôt
|
|
12
|
+
const branchName = 'master'; // Le nom de la branche est maintenant configurable
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const repoUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.zip`;
|
|
15
|
+
|
|
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
|
-
/**
|
|
74
|
-
* Fonction Principale Asynchrone
|
|
75
|
-
*/
|
|
76
65
|
/**
|
|
77
|
-
* Fonction Principale Asynchrone (Version
|
|
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,12 +87,10 @@ 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}`)));
|
|
@@ -112,8 +99,10 @@ async function setupProject() {
|
|
|
112
99
|
});
|
|
113
100
|
|
|
114
101
|
console.log(' [2/5] ✅ Template téléchargé et décompressé.');
|
|
102
|
+
|
|
103
|
+
// Le dossier décompressé aura un nom comme "repoName-master", on le renomme
|
|
104
|
+
fs.renameSync(`${repoName}-${branchName}`, projectName);
|
|
115
105
|
|
|
116
|
-
// Le reste du script continue ici
|
|
117
106
|
process.chdir(projectName);
|
|
118
107
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
119
108
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
@@ -121,16 +110,13 @@ async function setupProject() {
|
|
|
121
110
|
throw new Error("Les clés reçues du serveur sont invalides.");
|
|
122
111
|
}
|
|
123
112
|
|
|
124
|
-
|
|
113
|
+
console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
|
|
125
114
|
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`;
|
|
126
115
|
fs.writeFileSync(path.join(process.cwd(), '.env'), envContent, 'utf8');
|
|
127
|
-
console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
|
|
128
116
|
|
|
129
|
-
// 5. Installer les dépendances
|
|
130
117
|
console.log(' [5/5] 📦 Installation des dépendances (cela peut prendre quelques minutes)...');
|
|
131
118
|
execSync('npm install', { stdio: 'inherit' });
|
|
132
119
|
|
|
133
|
-
// Mise à jour du package.json
|
|
134
120
|
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
135
121
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
136
122
|
packageJson.name = projectName;
|
|
@@ -143,14 +129,19 @@ async function setupProject() {
|
|
|
143
129
|
|
|
144
130
|
} catch (error) {
|
|
145
131
|
console.error('\n❌ Une erreur est survenue lors de la création du projet :', error.message);
|
|
146
|
-
// Nettoyage en cas d'erreur
|
|
147
132
|
const dirToDelete = path.join(process.cwd(), projectName);
|
|
148
133
|
if (fs.existsSync(dirToDelete)) {
|
|
149
134
|
console.log(' Nettoyage du répertoire du projet...');
|
|
150
135
|
fs.rmSync(dirToDelete, { recursive: true, force: true });
|
|
151
136
|
}
|
|
137
|
+
const extractedDir = path.join(process.cwd(), `${repoName}-${branchName}`);
|
|
138
|
+
if (fs.existsSync(extractedDir)) {
|
|
139
|
+
console.log(' Nettoyage du répertoire temporaire...');
|
|
140
|
+
fs.rmSync(extractedDir, { recursive: true, force: true });
|
|
141
|
+
}
|
|
152
142
|
process.exit(1);
|
|
153
143
|
}
|
|
154
144
|
}
|
|
155
145
|
|
|
156
|
-
setupProject();
|
|
146
|
+
setupProject();
|
|
147
|
+
|