create-fleetbo-project 1.2.6 → 1.2.8
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 +128 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { execSync } = require('child_process');
|
|
3
|
+
{/*const { execSync } = require('child_process');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const https = require('https');
|
|
@@ -119,3 +119,130 @@ async function setupProject() {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
setupProject();
|
|
122
|
+
*/}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
const { execSync } = require('child_process');
|
|
127
|
+
const fs = require('fs');
|
|
128
|
+
const path = require('path');
|
|
129
|
+
const https = require('https');
|
|
130
|
+
|
|
131
|
+
// --- Configuration ---
|
|
132
|
+
const repoOwner = 'FleetFleetbo';
|
|
133
|
+
const repoName = 'dev.fleetbo.io';
|
|
134
|
+
const branchName = 'master'; // Assurez-vous que c'est la bonne branche
|
|
135
|
+
|
|
136
|
+
const repoGitUrl = `https://github.com/${repoOwner}/${repoName}.git`;
|
|
137
|
+
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
138
|
+
|
|
139
|
+
// --- Analyse des Arguments ---
|
|
140
|
+
const args = process.argv.slice(2);
|
|
141
|
+
const projectNameArg = args.find(arg => !arg.startsWith('--'));
|
|
142
|
+
const tokenArg = args.find(arg => arg.startsWith('--token='));
|
|
143
|
+
|
|
144
|
+
if (!projectNameArg) {
|
|
145
|
+
console.error('\n Error : Please specify a name for your project.');
|
|
146
|
+
console.log(' Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const bootstrapToken = tokenArg ? tokenArg.split('=')[1] : null;
|
|
151
|
+
|
|
152
|
+
if (!bootstrapToken) {
|
|
153
|
+
console.error('\n Error : "The bootstrap token is missing.');
|
|
154
|
+
console.log(' Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const projectName = projectNameArg;
|
|
159
|
+
|
|
160
|
+
// --- Fonctions Utilitaires ---
|
|
161
|
+
|
|
162
|
+
function fetchProjectKeys(token) {
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
const postData = JSON.stringify({ token });
|
|
165
|
+
const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } };
|
|
166
|
+
const req = https.request(bootstrapUrl, options, (res) => {
|
|
167
|
+
let data = '';
|
|
168
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
169
|
+
res.on('end', () => {
|
|
170
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
171
|
+
try {
|
|
172
|
+
resolve(JSON.parse(data));
|
|
173
|
+
} catch (e) {
|
|
174
|
+
reject(new Error('Invalid response from the key server.'));
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
const errorMsg = JSON.parse(data).error || `Server error (code: ${res.statusCode})`;
|
|
178
|
+
reject(new Error(errorMsg));
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
req.on('error', (e) => reject(e));
|
|
183
|
+
req.write(postData);
|
|
184
|
+
req.end();
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// --- Fonction Principale ---
|
|
189
|
+
|
|
190
|
+
async function setupProject() {
|
|
191
|
+
console.log(`\nCreating your Fleetbo project "${projectName}"...`);
|
|
192
|
+
const projectDir = path.join(process.cwd(), projectName);
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
// Étape 1 : Télécharger la structure de base du projet
|
|
196
|
+
console.log(' [1/6] Initializing project structure...');
|
|
197
|
+
// On redirige la sortie d'erreur (stderr) vers null pour masquer les messages de progression de Git
|
|
198
|
+
execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}" 2> /dev/null`);
|
|
199
|
+
|
|
200
|
+
// Étape 2 : Se déplacer dans le dossier du projet et nettoyer
|
|
201
|
+
console.log(' [2/6] Project structure initialized. Configuring...');
|
|
202
|
+
process.chdir(projectDir);
|
|
203
|
+
|
|
204
|
+
// Supprimer l'historique Git pour commencer avec un projet propre
|
|
205
|
+
fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
|
|
206
|
+
|
|
207
|
+
// Étape 3 : Récupération des clés de projet
|
|
208
|
+
console.log(' [3/6] Fetching project keys...');
|
|
209
|
+
const keys = await fetchProjectKeys(bootstrapToken);
|
|
210
|
+
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
211
|
+
throw new Error("Received keys from the server are invalid.");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Étape 4 : Configuration du fichier .env
|
|
215
|
+
console.log(' [4/6] .env file configured successfully.');
|
|
216
|
+
// Les variables d'environnement sont mises à jour pour le projet
|
|
217
|
+
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=99b426483d543b042209671dd53fb18\nREACT_KEY_APP=${projectName}\n`;
|
|
218
|
+
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
219
|
+
|
|
220
|
+
// Étape 5 : Installation des dépendances (principales)
|
|
221
|
+
console.log(' [5/6] Installing core dependencies...');
|
|
222
|
+
execSync('npm install', { stdio: 'inherit' }); // Installe toutes les dépendances listées dans package.json
|
|
223
|
+
|
|
224
|
+
// Étape 6 : Installation de ngrok (nécessaire pour le Hot Reloading sur le simulateur en ligne)
|
|
225
|
+
console.log(' [6/6] Installing ngrok for secure tunneling...');
|
|
226
|
+
execSync('npm install ngrok', { stdio: 'inherit' });
|
|
227
|
+
|
|
228
|
+
// Personnalisation du package.json (Nom du projet)
|
|
229
|
+
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
230
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
231
|
+
packageJson.name = projectName;
|
|
232
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
233
|
+
|
|
234
|
+
console.log('\n🚀 Your Fleetbo project is ready !');
|
|
235
|
+
console.log(`\nTo get started, run the following commands :`);
|
|
236
|
+
console.log(` cd ${projectName}`);
|
|
237
|
+
console.log(` npx fleetbo start`);
|
|
238
|
+
|
|
239
|
+
} catch (error) {
|
|
240
|
+
console.error('\n An error occurred while creating the project :', error.message);
|
|
241
|
+
// Nettoyage en cas d'erreur
|
|
242
|
+
if (fs.existsSync(projectDir)) {
|
|
243
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
setupProject();
|