create-fleetbo-project 1.0.34 → 1.0.36
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 -54
- package/package.json +1 -1
|
@@ -6,23 +6,12 @@ const path = require('path');
|
|
|
6
6
|
const https = require('https');
|
|
7
7
|
const unzipper = require('unzipper');
|
|
8
8
|
|
|
9
|
-
// --- Vérification de la version de Node.js ---
|
|
10
|
-
const [major, minor] = process.versions.node.split('.').map(parseFloat);
|
|
11
|
-
if (major < 16 || (major === 16 && minor < 7)) {
|
|
12
|
-
console.error(`\n❌ Erreur : Ce script requiert Node.js v16.7.0 ou une version supérieure pour fonctionner correctement.`);
|
|
13
|
-
console.error(` Votre version actuelle est ${process.versions.node}.`);
|
|
14
|
-
console.log(` Veuillez mettre à jour votre installation de Node.js.`);
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
9
|
// --- Configuration ---
|
|
19
|
-
const repoOwner = 'FleetFleetbo';
|
|
20
|
-
const repoName = 'dev.fleetbo.io';
|
|
21
|
-
const branchName = 'master'; //
|
|
10
|
+
const repoOwner = 'FleetFleetbo';
|
|
11
|
+
const repoName = 'dev.fleetbo.io';
|
|
12
|
+
const branchName = 'master'; // Assurez-vous que c'est la bonne branche
|
|
22
13
|
|
|
23
14
|
const repoUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/${branchName}.zip`;
|
|
24
|
-
|
|
25
|
-
// URL de votre Cloud Function.
|
|
26
15
|
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
27
16
|
|
|
28
17
|
// --- Analyse des Arguments ---
|
|
@@ -46,9 +35,8 @@ if (!bootstrapToken) {
|
|
|
46
35
|
|
|
47
36
|
const projectName = projectNameArg;
|
|
48
37
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*/
|
|
38
|
+
// --- Fonctions Utilitaires ---
|
|
39
|
+
|
|
52
40
|
function fetchProjectKeys(token) {
|
|
53
41
|
return new Promise((resolve, reject) => {
|
|
54
42
|
const postData = JSON.stringify({ token });
|
|
@@ -75,56 +63,48 @@ function fetchProjectKeys(token) {
|
|
|
75
63
|
});
|
|
76
64
|
}
|
|
77
65
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*/
|
|
66
|
+
// --- Fonction Principale ---
|
|
67
|
+
|
|
81
68
|
async function setupProject() {
|
|
82
69
|
console.log(`\nCréation de votre projet Fleetbo "${projectName}"...`);
|
|
70
|
+
|
|
71
|
+
// Le nom du dossier que GitHub crée dans le .zip
|
|
72
|
+
const unzippedDirName = `${repoName}-${branchName}`;
|
|
73
|
+
const sourceDir = path.join(process.cwd(), unzippedDirName);
|
|
83
74
|
const projectDir = path.join(process.cwd(), projectName);
|
|
84
|
-
const tempDir = path.join(process.cwd(), `fleetbo-temp-${Date.now()}`);
|
|
85
75
|
|
|
86
76
|
try {
|
|
87
|
-
// Étape 1 : Téléchargement et décompression
|
|
88
|
-
console.log(
|
|
77
|
+
// Étape 1 : Téléchargement et décompression (votre modèle)
|
|
78
|
+
console.log(' [1/5] 📥 Téléchargement et décompression du template...');
|
|
89
79
|
await new Promise((resolve, reject) => {
|
|
90
80
|
https.get(repoUrl, (response) => {
|
|
91
81
|
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
92
82
|
return https.get(response.headers.location, (redirectResponse) => {
|
|
93
|
-
redirectResponse.pipe(unzipper.Extract({ path:
|
|
83
|
+
redirectResponse.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
94
84
|
.on('finish', resolve)
|
|
95
85
|
.on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
|
|
96
86
|
}).on('error', (err) => reject(new Error(`Erreur réseau après redirection: ${err.message}`)));
|
|
87
|
+
} else if (response.statusCode !== 200) {
|
|
88
|
+
return reject(new Error(`Échec du téléchargement. Statut: ${response.statusCode}`));
|
|
89
|
+
} else {
|
|
90
|
+
response.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
91
|
+
.on('finish', resolve)
|
|
92
|
+
.on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
|
|
97
93
|
}
|
|
98
|
-
if (response.statusCode !== 200) {
|
|
99
|
-
return reject(new Error(`Échec du téléchargement. Statut: ${response.statusCode}`));
|
|
100
|
-
}
|
|
101
|
-
response.pipe(unzipper.Extract({ path: tempDir }))
|
|
102
|
-
.on('finish', resolve)
|
|
103
|
-
.on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
|
|
104
94
|
}).on('error', (err) => reject(new Error(`Erreur réseau: ${err.message}`)));
|
|
105
95
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const nestedProjectDir = fs.readdirSync(sourceDir).find(file => {
|
|
114
|
-
const fullPath = path.join(sourceDir, file);
|
|
115
|
-
return fs.statSync(fullPath).isDirectory() && fs.existsSync(path.join(fullPath, 'package.json'));
|
|
116
|
-
});
|
|
117
|
-
if (!nestedProjectDir) throw new Error('Impossible de trouver le fichier package.json dans le template téléchargé.');
|
|
118
|
-
sourceDir = path.join(sourceDir, nestedProjectDir);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Étape 2 ter : Copier les fichiers vers la destination finale
|
|
122
|
-
fs.mkdirSync(projectDir, { recursive: true });
|
|
123
|
-
for (const file of fs.readdirSync(sourceDir)) {
|
|
124
|
-
fs.cpSync(path.join(sourceDir, file), path.join(projectDir, file), { recursive: true });
|
|
96
|
+
|
|
97
|
+
// Étape 2 : Renommer le dossier décompressé
|
|
98
|
+
console.log(' [2/5] ✅ Template décompressé. Renommage du dossier...');
|
|
99
|
+
if (fs.existsSync(sourceDir)) {
|
|
100
|
+
fs.renameSync(sourceDir, projectDir);
|
|
101
|
+
} else {
|
|
102
|
+
throw new Error(`Le dossier attendu "${unzippedDirName}" n'a pas été trouvé après la décompression.`);
|
|
125
103
|
}
|
|
126
|
-
|
|
104
|
+
|
|
105
|
+
// Étape 3 : Se déplacer dans le dossier du projet et continuer
|
|
127
106
|
process.chdir(projectDir);
|
|
107
|
+
|
|
128
108
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
129
109
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
130
110
|
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
@@ -138,6 +118,7 @@ async function setupProject() {
|
|
|
138
118
|
console.log(' [5/5] 📦 Installation des dépendances...');
|
|
139
119
|
execSync('npm install', { stdio: 'inherit' });
|
|
140
120
|
|
|
121
|
+
// Personnalisation du package.json
|
|
141
122
|
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
142
123
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
143
124
|
packageJson.name = projectName;
|
|
@@ -150,13 +131,13 @@ async function setupProject() {
|
|
|
150
131
|
|
|
151
132
|
} catch (error) {
|
|
152
133
|
console.error('\n❌ Une erreur est survenue lors de la création du projet :', error.message);
|
|
134
|
+
// Nettoyage en cas d'erreur
|
|
135
|
+
if (fs.existsSync(sourceDir)) {
|
|
136
|
+
fs.rmSync(sourceDir, { recursive: true, force: true });
|
|
137
|
+
}
|
|
153
138
|
if (fs.existsSync(projectDir)) {
|
|
154
139
|
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
155
140
|
}
|
|
156
|
-
} finally {
|
|
157
|
-
if (fs.existsSync(tempDir)) {
|
|
158
|
-
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
159
|
-
}
|
|
160
141
|
}
|
|
161
142
|
}
|
|
162
143
|
|