create-fleetbo-project 1.2.8 → 1.2.9
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 +106 -50
- package/package.json +3 -1
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
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 os = require('os');
|
|
7
8
|
|
|
8
9
|
// --- Configuration ---
|
|
10
|
+
// On cible l'archive (zip/tar) plutôt que le repo git
|
|
9
11
|
const repoOwner = 'FleetFleetbo';
|
|
10
12
|
const repoName = 'dev.fleetbo.io';
|
|
11
|
-
const branchName = 'master';
|
|
13
|
+
const branchName = 'master';
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
// URL de téléchargement direct de l'archive (plus rapide, pas de .git)
|
|
16
|
+
const archiveUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.tar.gz`;
|
|
14
17
|
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
15
18
|
|
|
16
19
|
// --- Analyse des Arguments ---
|
|
@@ -19,24 +22,26 @@ const projectNameArg = args.find(arg => !arg.startsWith('--'));
|
|
|
19
22
|
const tokenArg = args.find(arg => arg.startsWith('--token='));
|
|
20
23
|
|
|
21
24
|
if (!projectNameArg) {
|
|
22
|
-
console.error('\n Error : Please specify a name for your project.');
|
|
23
|
-
console.log(' Usage: npx create-fleetbo-project <
|
|
25
|
+
console.error('\n ❌ Error : Please specify a name for your project.');
|
|
26
|
+
console.log(' Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
|
|
24
27
|
process.exit(1);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
const bootstrapToken = tokenArg ? tokenArg.split('=')[1] : null;
|
|
28
31
|
|
|
29
32
|
if (!bootstrapToken) {
|
|
30
|
-
console.error('\n Error :
|
|
31
|
-
console.log(' Usage: npx create-fleetbo-project <
|
|
33
|
+
console.error('\n ❌ Error : The bootstrap token is missing.');
|
|
34
|
+
console.log(' Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
|
|
32
35
|
process.exit(1);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
const projectName = projectNameArg;
|
|
39
|
+
const projectDir = path.join(process.cwd(), projectName);
|
|
36
40
|
|
|
37
41
|
// --- Fonctions Utilitaires ---
|
|
38
42
|
|
|
39
43
|
function fetchProjectKeys(token) {
|
|
44
|
+
// ... (Code inchangé pour la récupération des clés) ...
|
|
40
45
|
return new Promise((resolve, reject) => {
|
|
41
46
|
const postData = JSON.stringify({ token });
|
|
42
47
|
const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } };
|
|
@@ -62,67 +67,118 @@ function fetchProjectKeys(token) {
|
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
69
|
|
|
70
|
+
// Fonction pour télécharger l'archive
|
|
71
|
+
function downloadEngine(url, dest) {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const file = fs.createWriteStream(dest);
|
|
74
|
+
https.get(url, (response) => {
|
|
75
|
+
if (response.statusCode !== 200) {
|
|
76
|
+
reject(new Error(`Failed to download engine (Status: ${response.statusCode})`));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
response.pipe(file);
|
|
80
|
+
file.on('finish', () => {
|
|
81
|
+
file.close(resolve);
|
|
82
|
+
});
|
|
83
|
+
}).on('error', (err) => {
|
|
84
|
+
fs.unlink(dest, () => {}); // Supprimer le fichier partiel
|
|
85
|
+
reject(err);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
65
90
|
// --- Fonction Principale ---
|
|
66
91
|
|
|
67
92
|
async function setupProject() {
|
|
68
|
-
console.log(`\
|
|
69
|
-
|
|
70
|
-
|
|
93
|
+
console.log(`\n⚡ Initializing Fleetbo Framework for "${projectName}"...`);
|
|
94
|
+
|
|
71
95
|
try {
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
96
|
+
// Création du dossier
|
|
97
|
+
if (fs.existsSync(projectDir)) {
|
|
98
|
+
throw new Error(`Directory "${projectName}" already exists.`);
|
|
99
|
+
}
|
|
100
|
+
fs.mkdirSync(projectDir);
|
|
101
|
+
|
|
102
|
+
// Étape 1 : Téléchargement du Moteur (Sans Git)
|
|
103
|
+
console.log(' [1/6] 📥 Downloading Fleetbo Core Engine...');
|
|
104
|
+
const archivePath = path.join(projectDir, 'engine.tar.gz');
|
|
105
|
+
await downloadEngine(archiveUrl, archivePath);
|
|
106
|
+
|
|
107
|
+
// Étape 2 : Extraction (Scaffolding)
|
|
108
|
+
console.log(' [2/6] 📦 Scaffolding project structure...');
|
|
109
|
+
// On utilise 'tar' qui est présent sur Win10+, Mac et Linux.
|
|
110
|
+
// --strip-components=1 permet de retirer le dossier racine "dev.fleetbo.io-master" de l'archive
|
|
111
|
+
try {
|
|
112
|
+
execSync(`tar -xf "${archivePath}" -C "${projectDir}" --strip-components=1`);
|
|
113
|
+
fs.unlinkSync(archivePath); // Nettoyage de l'archive
|
|
114
|
+
} catch (e) {
|
|
115
|
+
throw new Error("Failed to extract the engine. Ensure 'tar' is available on your system.");
|
|
116
|
+
}
|
|
76
117
|
|
|
77
|
-
//
|
|
78
|
-
console.log(' [2/5] Project structure initialized. Configuring...');
|
|
118
|
+
// On se déplace dans le dossier (Plus besoin de supprimer .git car il n'y en a pas !)
|
|
79
119
|
process.chdir(projectDir);
|
|
80
120
|
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// Étape 3 : Récupération des clés de projet
|
|
85
|
-
console.log(' [3/5] Fetching project keys...');
|
|
121
|
+
// Étape 3 : Récupération des clés (Authentication)
|
|
122
|
+
console.log(' [3/6] 🔑 Authenticating with Fleetbo Cloud...');
|
|
86
123
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
87
124
|
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
88
125
|
throw new Error("Received keys from the server are invalid.");
|
|
89
126
|
}
|
|
90
127
|
|
|
91
|
-
// Étape 4 : Configuration
|
|
92
|
-
console.log(' [4/
|
|
93
|
-
//
|
|
94
|
-
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID
|
|
128
|
+
// Étape 4 : Configuration de l'environnement
|
|
129
|
+
console.log(' [4/6] ⚙️ Configuring environment...');
|
|
130
|
+
// Configuration .env optimisée pour le simulateur (DANGEROUSLY_DISABLE_HOST_CHECK)
|
|
131
|
+
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\nREACT_KEY_APP=${projectName}\nDANGEROUSLY_DISABLE_HOST_CHECK=true\n`;
|
|
95
132
|
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
96
133
|
|
|
97
134
|
// Étape 5 : Installation des dépendances
|
|
98
|
-
console.log(' [5/
|
|
99
|
-
|
|
135
|
+
console.log(' [5/6] 📚 Installing dependencies (this may take a moment)...');
|
|
136
|
+
// Installation silencieuse pour faire plus "pro" (pipe stdio si erreur)
|
|
137
|
+
execSync('npm install', { stdio: 'inherit' });
|
|
138
|
+
|
|
139
|
+
// Installation des outils de dev (Ngrok est vital pour le flow)
|
|
140
|
+
console.log(' Installing development tools...');
|
|
141
|
+
execSync('npm install ngrok dotenv --save-dev', { stdio: 'ignore' });
|
|
100
142
|
|
|
101
|
-
//
|
|
143
|
+
// Étape 6 : Finalisation
|
|
144
|
+
console.log(' [6/6] ✨ Finalizing setup...');
|
|
145
|
+
|
|
102
146
|
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
103
147
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
104
148
|
packageJson.name = projectName;
|
|
149
|
+
|
|
150
|
+
// On ajoute la commande 'fleetbo'
|
|
151
|
+
packageJson.scripts = {
|
|
152
|
+
...packageJson.scripts,
|
|
153
|
+
"fleetbo": "node cli.js",
|
|
154
|
+
"dev": "node cli.js"
|
|
155
|
+
};
|
|
105
156
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
106
157
|
|
|
107
|
-
console.log('\n
|
|
108
|
-
console.log(`\
|
|
158
|
+
console.log('\n✅ Project successfully created!');
|
|
159
|
+
console.log(`\n👉 Get started with:`);
|
|
109
160
|
console.log(` cd ${projectName}`);
|
|
110
|
-
console.log(`
|
|
161
|
+
console.log(` npm run fleetbo`);
|
|
111
162
|
|
|
112
163
|
} catch (error) {
|
|
113
|
-
console.error('\n
|
|
164
|
+
console.error('\n❌ Setup failed:', error.message);
|
|
114
165
|
// Nettoyage en cas d'erreur
|
|
115
166
|
if (fs.existsSync(projectDir)) {
|
|
116
|
-
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
167
|
+
try { fs.rmSync(projectDir, { recursive: true, force: true }); } catch(e){}
|
|
117
168
|
}
|
|
169
|
+
process.exit(1);
|
|
118
170
|
}
|
|
119
171
|
}
|
|
120
172
|
|
|
121
173
|
setupProject();
|
|
122
|
-
*/}
|
|
123
174
|
|
|
124
175
|
|
|
125
176
|
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
{/*
|
|
181
|
+
|
|
126
182
|
const { execSync } = require('child_process');
|
|
127
183
|
const fs = require('fs');
|
|
128
184
|
const path = require('path');
|
|
@@ -143,7 +199,7 @@ const tokenArg = args.find(arg => arg.startsWith('--token='));
|
|
|
143
199
|
|
|
144
200
|
if (!projectNameArg) {
|
|
145
201
|
console.error('\n Error : Please specify a name for your project.');
|
|
146
|
-
console.log(' Usage: npx create-fleetbo-project <
|
|
202
|
+
console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
|
|
147
203
|
process.exit(1);
|
|
148
204
|
}
|
|
149
205
|
|
|
@@ -151,7 +207,7 @@ const bootstrapToken = tokenArg ? tokenArg.split('=')[1] : null;
|
|
|
151
207
|
|
|
152
208
|
if (!bootstrapToken) {
|
|
153
209
|
console.error('\n Error : "The bootstrap token is missing.');
|
|
154
|
-
console.log(' Usage: npx create-fleetbo-project <
|
|
210
|
+
console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
|
|
155
211
|
process.exit(1);
|
|
156
212
|
}
|
|
157
213
|
|
|
@@ -193,39 +249,35 @@ async function setupProject() {
|
|
|
193
249
|
|
|
194
250
|
try {
|
|
195
251
|
// Étape 1 : Télécharger la structure de base du projet
|
|
196
|
-
console.log(' [1/
|
|
252
|
+
console.log(' [1/5] Initializing project structure...');
|
|
197
253
|
// On redirige la sortie d'erreur (stderr) vers null pour masquer les messages de progression de Git
|
|
198
254
|
execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}" 2> /dev/null`);
|
|
199
255
|
|
|
200
256
|
// Étape 2 : Se déplacer dans le dossier du projet et nettoyer
|
|
201
|
-
console.log(' [2/
|
|
257
|
+
console.log(' [2/5] Project structure initialized. Configuring...');
|
|
202
258
|
process.chdir(projectDir);
|
|
203
259
|
|
|
204
260
|
// Supprimer l'historique Git pour commencer avec un projet propre
|
|
205
261
|
fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
|
|
206
262
|
|
|
207
263
|
// Étape 3 : Récupération des clés de projet
|
|
208
|
-
console.log(' [3/
|
|
264
|
+
console.log(' [3/5] Fetching project keys...');
|
|
209
265
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
210
266
|
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
211
267
|
throw new Error("Received keys from the server are invalid.");
|
|
212
268
|
}
|
|
213
269
|
|
|
214
270
|
// Étape 4 : Configuration du fichier .env
|
|
215
|
-
console.log(' [4/
|
|
216
|
-
//
|
|
271
|
+
console.log(' [4/5] .env file configured successfully.');
|
|
272
|
+
//const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`; //99b426483d543b042209671dd53fb18
|
|
217
273
|
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=99b426483d543b042209671dd53fb18\nREACT_KEY_APP=${projectName}\n`;
|
|
218
274
|
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
219
275
|
|
|
220
|
-
// Étape 5 : Installation des dépendances
|
|
221
|
-
console.log(' [5/
|
|
222
|
-
execSync('npm install', { stdio: 'inherit' });
|
|
276
|
+
// Étape 5 : Installation des dépendances
|
|
277
|
+
console.log(' [5/5] Installing dependencies...');
|
|
278
|
+
execSync('npm install', { stdio: 'inherit' });
|
|
223
279
|
|
|
224
|
-
//
|
|
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)
|
|
280
|
+
// Personnalisation du package.json
|
|
229
281
|
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
230
282
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
231
283
|
packageJson.name = projectName;
|
|
@@ -245,4 +297,8 @@ async function setupProject() {
|
|
|
245
297
|
}
|
|
246
298
|
}
|
|
247
299
|
|
|
248
|
-
setupProject();
|
|
300
|
+
setupProject();
|
|
301
|
+
*/}
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-fleetbo-project",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "Creates a new Fleetbo project.",
|
|
5
5
|
"main": "install-react-template.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"axios": "^1.12.2",
|
|
11
11
|
"chalk": "^4.1.2",
|
|
12
|
+
"dotenv": "^16.6.1",
|
|
13
|
+
"ngrok": "^5.0.0-beta.2",
|
|
12
14
|
"ora": "^5.4.1",
|
|
13
15
|
"unzipper": "^0.10.14",
|
|
14
16
|
"yargs-parser": "^21.1.1"
|