create-fleetbo-project 1.0.23 → 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 +37 -23
- 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...');
|
|
@@ -74,36 +76,50 @@ async function setupProject() {
|
|
|
74
76
|
https.get(repoUrl, (response) => {
|
|
75
77
|
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
76
78
|
const redirectUrl = response.headers.location;
|
|
77
|
-
// Log de l'URL pour faciliter le débogage
|
|
78
79
|
console.log(` -> Redirection détectée, suivi du lien : ${redirectUrl}`);
|
|
79
80
|
https.get(redirectUrl, (redirectResponse) => {
|
|
80
81
|
if (redirectResponse.statusCode !== 200) {
|
|
81
82
|
return reject(new Error(`Échec du téléchargement après redirection. L'URL n'existe pas (Code: ${redirectResponse.statusCode})`));
|
|
82
83
|
}
|
|
83
|
-
redirectResponse.pipe(unzipper.Extract({ path:
|
|
84
|
+
redirectResponse.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
84
85
|
.on('finish', resolve)
|
|
85
86
|
.on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
|
|
86
87
|
}).on('error', (err) => reject(new Error(`Erreur réseau après redirection: ${err.message}`)));
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
|
-
|
|
90
90
|
if (response.statusCode !== 200) {
|
|
91
|
-
return reject(new Error(`Échec du téléchargement
|
|
91
|
+
return reject(new Error(`Échec du téléchargement (Code: ${response.statusCode})`));
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
response.pipe(unzipper.Extract({ path: '.' }))
|
|
93
|
+
response.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
95
94
|
.on('finish', resolve)
|
|
96
95
|
.on('error', (err) => reject(new Error(`Erreur lors de la décompression: ${err.message}`)));
|
|
97
|
-
|
|
98
|
-
}).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}`)));
|
|
99
97
|
});
|
|
100
98
|
|
|
101
|
-
console.log(' [2/5] ✅ Template
|
|
99
|
+
console.log(' [2/5] ✅ Template décompressé. Réorganisation des fichiers...');
|
|
102
100
|
|
|
103
|
-
//
|
|
104
|
-
|
|
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
|
+
}
|
|
120
|
+
// *** FIN DE LA NOUVELLE LOGIQUE ***
|
|
105
121
|
|
|
106
|
-
process.chdir(
|
|
122
|
+
process.chdir(projectDir);
|
|
107
123
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
108
124
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
109
125
|
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
@@ -112,12 +128,12 @@ async function setupProject() {
|
|
|
112
128
|
|
|
113
129
|
console.log(' [4/5] ✅ Fichier .env configuré avec succès.');
|
|
114
130
|
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`;
|
|
115
|
-
fs.writeFileSync(path.join(
|
|
131
|
+
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
116
132
|
|
|
117
133
|
console.log(' [5/5] 📦 Installation des dépendances (cela peut prendre quelques minutes)...');
|
|
118
134
|
execSync('npm install', { stdio: 'inherit' });
|
|
119
135
|
|
|
120
|
-
const packageJsonPath = path.join(
|
|
136
|
+
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
121
137
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
122
138
|
packageJson.name = projectName;
|
|
123
139
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
@@ -129,17 +145,15 @@ async function setupProject() {
|
|
|
129
145
|
|
|
130
146
|
} catch (error) {
|
|
131
147
|
console.error('\n❌ Une erreur est survenue lors de la création du projet :', error.message);
|
|
132
|
-
|
|
133
|
-
if (fs.existsSync(dirToDelete)) {
|
|
148
|
+
if (fs.existsSync(projectDir)) {
|
|
134
149
|
console.log(' Nettoyage du répertoire du projet...');
|
|
135
|
-
fs.rmSync(
|
|
150
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
136
151
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
152
|
+
} finally {
|
|
153
|
+
// Nettoyage final du dossier temporaire
|
|
154
|
+
if (fs.existsSync(tempDir)) {
|
|
155
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
141
156
|
}
|
|
142
|
-
process.exit(1);
|
|
143
157
|
}
|
|
144
158
|
}
|
|
145
159
|
|