create-fleetbo-project 1.2.12 → 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');
@@ -118,8 +119,17 @@ const projectDir = path.join(process.cwd(), projectName);
118
119
  function fetchProjectKeys(token) {
119
120
  return new Promise((resolve, reject) => {
120
121
  const postData = JSON.stringify({ token });
121
- const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } };
122
- 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) => {
123
133
  let data = '';
124
134
  res.on('data', (chunk) => { data += chunk; });
125
135
  res.on('end', () => {
@@ -134,20 +144,57 @@ function fetchProjectKeys(token) {
134
144
  });
135
145
  }
136
146
 
147
+ // --- CORRECTION MAJEURE : Ajout du User-Agent pour éviter l'erreur 503 ---
137
148
  function downloadEngine(url, dest) {
138
149
  return new Promise((resolve, reject) => {
139
- 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)
140
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
141
170
  downloadEngine(response.headers.location, dest).then(resolve).catch(reject);
142
171
  return;
143
172
  }
144
- 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
145
181
  const file = fs.createWriteStream(dest);
146
182
  response.pipe(file);
147
- file.on('finish', () => file.close(resolve));
148
- 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);
149
197
  });
150
- request.on('error', (err) => reject(err));
151
198
  });
152
199
  }
153
200
 
@@ -187,7 +234,6 @@ async function setupProject() {
187
234
  // 5. Deps
188
235
  console.log(' [5/6] 📚 Installing dependencies...');
189
236
  execSync('npm install', { stdio: 'inherit' });
190
- // AJOUT DE AXIOS ICI
191
237
  execSync('npm install ngrok dotenv axios --save-dev', { stdio: 'ignore' });
192
238
 
193
239
  // 6. Finalize
@@ -198,7 +244,7 @@ async function setupProject() {
198
244
  packageJson.scripts = { ...packageJson.scripts, "fleetbo": "node cli.js", "dev": "node cli.js" };
199
245
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
200
246
 
201
- console.log('\n✅ Project successfully created!');
247
+ console.log('\n✅ [Fleetbo] Project successfully created!');
202
248
  console.log(`\n👉 Run: cd ${projectName} && npm run fleetbo`);
203
249
 
204
250
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {