create-fleetbo-project 1.0.25 → 1.0.27

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.
@@ -4,15 +4,12 @@ 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 unzipper = require('unzipper');
8
7
 
9
8
  // --- Configuration ---
10
9
  const repoOwner = 'FleetFleetbo'; // Assurez-vous que c'est le bon nom d'utilisateur GitHub
11
10
  const repoName = 'dev.fleetbo.io'; // Assurez-vous que c'est le bon nom de dépôt
12
11
  const branchName = 'master'; // Le nom de la branche est maintenant configurable
13
12
 
14
- const repoUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.zip`;
15
-
16
13
  // URL de votre Cloud Function.
17
14
  const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
18
15
 
@@ -63,60 +60,19 @@ function fetchProjectKeys(token) {
63
60
  }
64
61
 
65
62
  /**
66
- * Fonction Principale Asynchrone (Version avec manipulation de fichiers plus robuste)
63
+ * Fonction Principale Asynchrone (Version utilisant degit pour un clonage fiable)
67
64
  */
68
65
  async function setupProject() {
69
66
  console.log(`\nCréation de votre projet Fleetbo "${projectName}"...`);
70
67
  const projectDir = path.join(process.cwd(), projectName);
71
- const tempDir = path.join(process.cwd(), `${repoName}-${branchName}`);
72
68
 
73
69
  try {
74
- console.log(' [1/5] 📥 Téléchargement du template...');
75
- await new Promise((resolve, reject) => {
76
- https.get(repoUrl, (response) => {
77
- if (response.statusCode === 301 || response.statusCode === 302) {
78
- const redirectUrl = response.headers.location;
79
- console.log(` -> Redirection détectée, suivi du lien : ${redirectUrl}`);
80
- https.get(redirectUrl, (redirectResponse) => {
81
- if (redirectResponse.statusCode !== 200) {
82
- return reject(new Error(`Échec du téléchargement après redirection. L'URL n'existe pas (Code: ${redirectResponse.statusCode})`));
83
- }
84
- redirectResponse.pipe(unzipper.Extract({ path: process.cwd() }))
85
- .on('finish', resolve)
86
- .on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
87
- }).on('error', (err) => reject(new Error(`Erreur réseau après redirection: ${err.message}`)));
88
- return;
89
- }
90
- if (response.statusCode !== 200) {
91
- return reject(new Error(`Échec du téléchargement (Code: ${response.statusCode})`));
92
- }
93
- response.pipe(unzipper.Extract({ path: process.cwd() }))
94
- .on('finish', resolve)
95
- .on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
96
- }).on('error', (err) => reject(new Error(`Erreur réseau: ${err.message}`)));
97
- });
98
-
99
- console.log(' [2/5] ✅ Template décompressé. Réorganisation des fichiers...');
100
-
101
- // *** DÉBUT DE LA NOUVELLE LOGIQUE DE DÉPLACEMENT DE FICHIERS ***
102
- let sourceDir = tempDir;
103
- const tempDirContents = fs.readdirSync(tempDir);
104
- const significantContent = tempDirContents.filter(f => !f.startsWith('.'));
105
-
106
- // Si le dossier décompressé ne contient qu'un seul dossier, c'est notre source
107
- if (significantContent.length === 1 && fs.statSync(path.join(tempDir, significantContent[0])).isDirectory()) {
108
- console.log(` -> Structure imbriquée détectée. Utilisation du sous-dossier "${significantContent[0]}".`);
109
- sourceDir = path.join(tempDir, significantContent[0]);
110
- }
111
-
112
- // Crée le dossier final du projet
113
- fs.mkdirSync(projectDir);
114
-
115
- // Déplace le contenu du dossier source vers le dossier final
116
- const sourceContents = fs.readdirSync(sourceDir);
117
- for (const item of sourceContents) {
118
- fs.renameSync(path.join(sourceDir, item), path.join(projectDir, item));
119
- }
70
+ // *** DÉBUT DE LA NOUVELLE LOGIQUE DE CLONAGE AVEC DEGIT ***
71
+ console.log(` [1/5] 📥 Clonage du template via degit (cela peut prendre un moment)...`);
72
+ const degitRepo = `${repoOwner}/${repoName}#${branchName}`;
73
+ // Utilise npx pour s'assurer que degit est disponible sans installation globale
74
+ execSync(`npx degit ${degitRepo} ${projectName}`, { stdio: 'inherit' });
75
+ console.log(' [2/5] Template cloné avec succès.');
120
76
  // *** FIN DE LA NOUVELLE LOGIQUE ***
121
77
 
122
78
  process.chdir(projectDir);
@@ -149,11 +105,7 @@ async function setupProject() {
149
105
  console.log(' Nettoyage du répertoire du projet...');
150
106
  fs.rmSync(projectDir, { recursive: true, force: true });
151
107
  }
152
- } finally {
153
- // Nettoyage final du dossier temporaire
154
- if (fs.existsSync(tempDir)) {
155
- fs.rmSync(tempDir, { recursive: true, force: true });
156
- }
108
+ process.exit(1);
157
109
  }
158
110
  }
159
111
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {