create-fleetbo-project 1.0.24 → 1.0.25
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 +35 -39
- 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,43 @@ 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
|
-
fs.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
fs.
|
|
120
|
-
console.log(' -> Déplacement terminé.');
|
|
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));
|
|
121
119
|
}
|
|
122
|
-
// *** FIN DE LA
|
|
120
|
+
// *** FIN DE LA NOUVELLE LOGIQUE ***
|
|
123
121
|
|
|
124
122
|
process.chdir(projectDir);
|
|
125
123
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
@@ -130,12 +128,12 @@ async function setupProject() {
|
|
|
130
128
|
|
|
131
129
|
console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
|
|
132
130
|
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`;
|
|
133
|
-
fs.writeFileSync(path.join(
|
|
131
|
+
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
134
132
|
|
|
135
133
|
console.log(' [5/5] 📦 Installation des dépendances (cela peut prendre quelques minutes)...');
|
|
136
134
|
execSync('npm install', { stdio: 'inherit' });
|
|
137
135
|
|
|
138
|
-
const packageJsonPath = path.join(
|
|
136
|
+
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
139
137
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
140
138
|
packageJson.name = projectName;
|
|
141
139
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
@@ -147,17 +145,15 @@ async function setupProject() {
|
|
|
147
145
|
|
|
148
146
|
} catch (error) {
|
|
149
147
|
console.error('\n❌ Une erreur est survenue lors de la création du projet :', error.message);
|
|
150
|
-
|
|
151
|
-
if (fs.existsSync(dirToDelete)) {
|
|
148
|
+
if (fs.existsSync(projectDir)) {
|
|
152
149
|
console.log(' Nettoyage du répertoire du projet...');
|
|
153
|
-
fs.rmSync(
|
|
150
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
154
151
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
152
|
+
} finally {
|
|
153
|
+
// Nettoyage final du dossier temporaire
|
|
154
|
+
if (fs.existsSync(tempDir)) {
|
|
155
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
159
156
|
}
|
|
160
|
-
process.exit(1);
|
|
161
157
|
}
|
|
162
158
|
}
|
|
163
159
|
|