create-fleetbo-project 1.0.24 → 1.0.26
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 +42 -38
- package/package.json +1 -1
|
@@ -63,10 +63,12 @@ function fetchProjectKeys(token) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
* Fonction Principale Asynchrone (Version avec
|
|
66
|
+
* Fonction Principale Asynchrone (Version avec manipulation de fichiers plus robuste)
|
|
67
67
|
*/
|
|
68
68
|
async function setupProject() {
|
|
69
69
|
console.log(`\nCréation de votre projet Fleetbo "${projectName}"...`);
|
|
70
|
+
const projectDir = path.join(process.cwd(), projectName);
|
|
71
|
+
const tempDir = path.join(process.cwd(), `${repoName}-${branchName}`);
|
|
70
72
|
|
|
71
73
|
try {
|
|
72
74
|
console.log(' [1/5] 📥 Téléchargement du template...');
|
|
@@ -79,47 +81,51 @@ async function setupProject() {
|
|
|
79
81
|
if (redirectResponse.statusCode !== 200) {
|
|
80
82
|
return reject(new Error(`Échec du téléchargement après redirection. L'URL n'existe pas (Code: ${redirectResponse.statusCode})`));
|
|
81
83
|
}
|
|
82
|
-
redirectResponse.pipe(unzipper.Extract({ path:
|
|
84
|
+
redirectResponse.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
83
85
|
.on('finish', resolve)
|
|
84
86
|
.on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
|
|
85
87
|
}).on('error', (err) => reject(new Error(`Erreur réseau après redirection: ${err.message}`)));
|
|
86
88
|
return;
|
|
87
89
|
}
|
|
88
|
-
|
|
89
90
|
if (response.statusCode !== 200) {
|
|
90
|
-
return reject(new Error(`Échec du téléchargement
|
|
91
|
+
return reject(new Error(`Échec du téléchargement (Code: ${response.statusCode})`));
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
response.pipe(unzipper.Extract({ path: '.' }))
|
|
93
|
+
response.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
94
94
|
.on('finish', resolve)
|
|
95
95
|
.on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
|
|
96
|
-
|
|
97
|
-
}).on('error', (err) => reject(new Error(`Erreur réseau lors du téléchargement: ${err.message}`)));
|
|
96
|
+
}).on('error', (err) => reject(new Error(`Erreur réseau: ${err.message}`)));
|
|
98
97
|
});
|
|
99
98
|
|
|
100
|
-
console.log(' [2/5] ✅ Template
|
|
99
|
+
console.log(' [2/5] ✅ Template décompressé. Réorganisation des fichiers...');
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
// *** DÉBUT DE LA LOGIQUE CORRIGÉE POUR TROUVER LA RACINE DU PROJET ***
|
|
102
|
+
let sourceDir = tempDir;
|
|
103
|
+
// Si package.json n'est pas à la racine du dossier temporaire...
|
|
104
|
+
if (!fs.existsSync(path.join(tempDir, 'package.json'))) {
|
|
105
|
+
const tempDirContents = fs.readdirSync(tempDir);
|
|
106
|
+
// ...on cherche le premier sous-dossier qui le contient.
|
|
107
|
+
const projectSubDir = tempDirContents.find(f => {
|
|
108
|
+
const fullPath = path.join(tempDir, f);
|
|
109
|
+
return fs.statSync(fullPath).isDirectory() && fs.existsSync(path.join(fullPath, 'package.json'));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (projectSubDir) {
|
|
113
|
+
console.log(` -> Structure imbriquée détectée. Utilisation du sous-dossier "${projectSubDir}".`);
|
|
114
|
+
sourceDir = path.join(tempDir, projectSubDir);
|
|
115
|
+
} else {
|
|
116
|
+
throw new Error('Impossible de localiser le fichier package.json dans le template. La structure du dépôt est peut-être incorrecte.');
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
fs.rmdirSync(nestedProjectDir);
|
|
120
|
-
console.log(' -> Déplacement terminé.');
|
|
121
118
|
}
|
|
122
|
-
|
|
119
|
+
|
|
120
|
+
// Crée le dossier final du projet
|
|
121
|
+
fs.mkdirSync(projectDir);
|
|
122
|
+
|
|
123
|
+
// Déplace le contenu du dossier source vers le dossier final
|
|
124
|
+
const sourceContents = fs.readdirSync(sourceDir);
|
|
125
|
+
for (const item of sourceContents) {
|
|
126
|
+
fs.renameSync(path.join(sourceDir, item), path.join(projectDir, item));
|
|
127
|
+
}
|
|
128
|
+
// *** FIN DE LA LOGIQUE CORRIGÉE ***
|
|
123
129
|
|
|
124
130
|
process.chdir(projectDir);
|
|
125
131
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
@@ -130,12 +136,12 @@ async function setupProject() {
|
|
|
130
136
|
|
|
131
137
|
console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
|
|
132
138
|
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`;
|
|
133
|
-
fs.writeFileSync(path.join(
|
|
139
|
+
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
134
140
|
|
|
135
141
|
console.log(' [5/5] 📦 Installation des dépendances (cela peut prendre quelques minutes)...');
|
|
136
142
|
execSync('npm install', { stdio: 'inherit' });
|
|
137
143
|
|
|
138
|
-
const packageJsonPath = path.join(
|
|
144
|
+
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
139
145
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
140
146
|
packageJson.name = projectName;
|
|
141
147
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
@@ -147,17 +153,15 @@ async function setupProject() {
|
|
|
147
153
|
|
|
148
154
|
} catch (error) {
|
|
149
155
|
console.error('\n❌ Une erreur est survenue lors de la création du projet :', error.message);
|
|
150
|
-
|
|
151
|
-
if (fs.existsSync(dirToDelete)) {
|
|
156
|
+
if (fs.existsSync(projectDir)) {
|
|
152
157
|
console.log(' Nettoyage du répertoire du projet...');
|
|
153
|
-
fs.rmSync(
|
|
158
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
154
159
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
} finally {
|
|
161
|
+
// Nettoyage final du dossier temporaire
|
|
162
|
+
if (fs.existsSync(tempDir)) {
|
|
163
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
159
164
|
}
|
|
160
|
-
process.exit(1);
|
|
161
165
|
}
|
|
162
166
|
}
|
|
163
167
|
|