create-fleetbo-project 1.2.11 → 1.2.13

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.
@@ -9,10 +9,11 @@ const https = require('https');
9
9
  const repoOwner = 'FleetFleetbo';
10
10
  const repoName = 'dev.fleetbo.io';
11
11
  const branchName = 'master';
12
+ // URL de l'archive (On cible 'codeload' implicitement via GitHub)
12
13
  const archiveUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.tar.gz`;
13
14
  const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
14
15
 
15
- // --- LE CONTENU DU GARDIEN (Injecté dynamiquement) ---
16
+ // --- LE CONTENU DU GARDIEN (CLI.JS) ---
16
17
  const CLI_SCRIPT_CONTENT = `#!/usr/bin/env node
17
18
 
18
19
  const { spawn } = require('child_process');
@@ -103,24 +104,32 @@ runGuardian();
103
104
  const args = process.argv.slice(2);
104
105
  const projectNameArg = args.find(arg => !arg.startsWith('--'));
105
106
  const tokenArg = args.find(arg => arg.startsWith('--token='));
107
+ const bootstrapTokenArg = tokenArg ? tokenArg.split('=')[1] : null;
106
108
 
107
- if (!projectNameArg || !bootstrapToken(tokenArg)) {
109
+ if (!projectNameArg || !bootstrapTokenArg) {
108
110
  console.error('\n ❌ Usage: npx create-fleetbo-project <project-name> --token=<your-token>');
109
111
  process.exit(1);
110
112
  }
111
113
 
112
- function bootstrapToken(arg) { return arg ? arg.split('=')[1] : null; }
113
114
  const projectName = projectNameArg;
114
115
  const projectDir = path.join(process.cwd(), projectName);
115
- const bToken = bootstrapToken(tokenArg);
116
116
 
117
117
 
118
118
  // --- Fonctions Utilitaires ---
119
119
  function fetchProjectKeys(token) {
120
120
  return new Promise((resolve, reject) => {
121
121
  const postData = JSON.stringify({ token });
122
- const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } };
123
- const req = https.request(bootstrapUrl, options, (res) => {
122
+ const uri = new URL(bootstrapUrl);
123
+ const options = {
124
+ hostname: uri.hostname,
125
+ path: uri.pathname,
126
+ method: 'POST',
127
+ headers: {
128
+ 'Content-Type': 'application/json',
129
+ 'Content-Length': Buffer.byteLength(postData)
130
+ }
131
+ };
132
+ const req = https.request(options, (res) => {
124
133
  let data = '';
125
134
  res.on('data', (chunk) => { data += chunk; });
126
135
  res.on('end', () => {
@@ -135,20 +144,57 @@ function fetchProjectKeys(token) {
135
144
  });
136
145
  }
137
146
 
147
+ // --- CORRECTION MAJEURE : Ajout du User-Agent pour éviter l'erreur 503 ---
138
148
  function downloadEngine(url, dest) {
139
149
  return new Promise((resolve, reject) => {
140
- const request = https.get(url, (response) => {
150
+ // On parse l'URL pour pouvoir ajouter des headers
151
+ const uri = new URL(url);
152
+ const options = {
153
+ hostname: uri.hostname,
154
+ path: uri.pathname + uri.search,
155
+ method: 'GET',
156
+ headers: {
157
+ 'User-Agent': 'Fleetbo-CLI-Installer', // CRITIQUE POUR GITHUB
158
+ 'Accept': '*/*'
159
+ }
160
+ };
161
+
162
+ const request = https.get(options, (response) => {
163
+ // Gestion Redirection (301/302)
141
164
  if (response.statusCode === 301 || response.statusCode === 302) {
165
+ if (!response.headers.location) {
166
+ reject(new Error("Redirect found but no location header"));
167
+ return;
168
+ }
169
+ // Appel récursif avec la nouvelle URL
142
170
  downloadEngine(response.headers.location, dest).then(resolve).catch(reject);
143
171
  return;
144
172
  }
145
- if (response.statusCode !== 200) { reject(new Error(`Status: ${response.statusCode}`)); return; }
173
+
174
+ // Vérification du statut
175
+ if (response.statusCode !== 200) {
176
+ reject(new Error(`Failed to download (Status: ${response.statusCode})`));
177
+ return;
178
+ }
179
+
180
+ // Écriture du fichier
146
181
  const file = fs.createWriteStream(dest);
147
182
  response.pipe(file);
148
- file.on('finish', () => file.close(resolve));
149
- file.on('error', (err) => { fs.unlink(dest, () => {}); reject(err); });
183
+
184
+ file.on('finish', () => {
185
+ file.close(resolve);
186
+ });
187
+
188
+ file.on('error', (err) => {
189
+ fs.unlink(dest, () => {}); // Supprimer le fichier incomplet
190
+ reject(err);
191
+ });
192
+ });
193
+
194
+ request.on('error', (err) => {
195
+ fs.unlink(dest, () => {});
196
+ reject(err);
150
197
  });
151
- request.on('error', (err) => reject(err));
152
198
  });
153
199
  }
154
200
 
@@ -176,22 +222,19 @@ async function setupProject() {
176
222
 
177
223
  // 3. Auth
178
224
  console.log(' [3/6] 🔑 Authenticating with Fleetbo Cloud...');
179
- const keys = await fetchProjectKeys(bToken);
225
+ const keys = await fetchProjectKeys(bootstrapTokenArg);
180
226
  if (!keys.enterpriseId) throw new Error("Invalid keys.");
181
227
 
182
228
  // 4. Environment & CLI Generation
183
229
  console.log(' [4/6] ⚙️ Configuring environment & CLI...');
184
230
  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`;
185
231
  fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
186
-
187
- // --- ICI ON CRÉE LE FICHIER CLI.JS ---
188
232
  fs.writeFileSync(path.join(projectDir, 'cli.js'), CLI_SCRIPT_CONTENT, 'utf8');
189
- // -------------------------------------
190
233
 
191
234
  // 5. Deps
192
235
  console.log(' [5/6] 📚 Installing dependencies...');
193
236
  execSync('npm install', { stdio: 'inherit' });
194
- execSync('npm install ngrok dotenv --save-dev', { stdio: 'ignore' });
237
+ execSync('npm install ngrok dotenv axios --save-dev', { stdio: 'ignore' });
195
238
 
196
239
  // 6. Finalize
197
240
  console.log(' [6/6] ✨ Finalizing setup...');
@@ -201,7 +244,7 @@ async function setupProject() {
201
244
  packageJson.scripts = { ...packageJson.scripts, "fleetbo": "node cli.js", "dev": "node cli.js" };
202
245
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
203
246
 
204
- console.log('\n✅ Project successfully created!');
247
+ console.log('\n✅ [Fleetbo] Project successfully created!');
205
248
  console.log(`\n👉 Run: cd ${projectName} && npm run fleetbo`);
206
249
 
207
250
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {