create-fleetbo-project 1.0.35 → 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 +34 -75
- 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,78 +63,48 @@ function fetchProjectKeys(token) {
|
|
|
75
63
|
});
|
|
76
64
|
}
|
|
77
65
|
|
|
78
|
-
|
|
79
|
-
* Fonction de copie récursive robuste pour garantir que tous les fichiers sont copiés.
|
|
80
|
-
* @param {string} src Le chemin source.
|
|
81
|
-
* @param {string} dest Le chemin de destination.
|
|
82
|
-
*/
|
|
83
|
-
function copyRecursiveSync(src, dest) {
|
|
84
|
-
const exists = fs.existsSync(src);
|
|
85
|
-
const stats = exists && fs.statSync(src);
|
|
86
|
-
const isDirectory = exists && stats.isDirectory();
|
|
87
|
-
if (isDirectory) {
|
|
88
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
89
|
-
fs.readdirSync(src).forEach(childItemName => {
|
|
90
|
-
copyRecursiveSync(
|
|
91
|
-
path.join(src, childItemName),
|
|
92
|
-
path.join(dest, childItemName)
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
} else {
|
|
96
|
-
fs.copyFileSync(src, dest);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
66
|
+
// --- Fonction Principale ---
|
|
99
67
|
|
|
100
|
-
/**
|
|
101
|
-
* Fonction Principale Asynchrone (Version pro avec téléchargement direct et gestion de fichiers robuste)
|
|
102
|
-
*/
|
|
103
68
|
async function setupProject() {
|
|
104
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);
|
|
105
74
|
const projectDir = path.join(process.cwd(), projectName);
|
|
106
|
-
const tempDir = path.join(process.cwd(), `fleetbo-temp-${Date.now()}`);
|
|
107
75
|
|
|
108
76
|
try {
|
|
109
|
-
// Étape 1 : Téléchargement et décompression
|
|
110
|
-
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...');
|
|
111
79
|
await new Promise((resolve, reject) => {
|
|
112
80
|
https.get(repoUrl, (response) => {
|
|
113
81
|
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
114
82
|
return https.get(response.headers.location, (redirectResponse) => {
|
|
115
|
-
redirectResponse.pipe(unzipper.Extract({ path:
|
|
83
|
+
redirectResponse.pipe(unzipper.Extract({ path: process.cwd() }))
|
|
116
84
|
.on('finish', resolve)
|
|
117
85
|
.on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
|
|
118
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}`)));
|
|
119
93
|
}
|
|
120
|
-
if (response.statusCode !== 200) {
|
|
121
|
-
return reject(new Error(`Échec du téléchargement. Statut: ${response.statusCode}`));
|
|
122
|
-
}
|
|
123
|
-
response.pipe(unzipper.Extract({ path: tempDir }))
|
|
124
|
-
.on('finish', resolve)
|
|
125
|
-
.on('error', (err) => reject(new Error(`Erreur de décompression: ${err.message}`)));
|
|
126
94
|
}).on('error', (err) => reject(new Error(`Erreur réseau: ${err.message}`)));
|
|
127
95
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const nestedProjectDir = fs.readdirSync(sourceDir).find(file => {
|
|
136
|
-
const fullPath = path.join(sourceDir, file);
|
|
137
|
-
return fs.statSync(fullPath).isDirectory() && fs.existsSync(path.join(fullPath, 'package.json'));
|
|
138
|
-
});
|
|
139
|
-
if (!nestedProjectDir) throw new Error('Impossible de trouver le fichier package.json dans le template téléchargé.');
|
|
140
|
-
sourceDir = path.join(sourceDir, nestedProjectDir);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Étape 2 ter : Copier les fichiers vers la destination finale
|
|
144
|
-
fs.mkdirSync(projectDir, { recursive: true });
|
|
145
|
-
for (const file of fs.readdirSync(sourceDir)) {
|
|
146
|
-
copyRecursiveSync(path.join(sourceDir, file), path.join(projectDir, file));
|
|
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.`);
|
|
147
103
|
}
|
|
148
|
-
|
|
104
|
+
|
|
105
|
+
// Étape 3 : Se déplacer dans le dossier du projet et continuer
|
|
149
106
|
process.chdir(projectDir);
|
|
107
|
+
|
|
150
108
|
console.log(' [3/5] 🔑 Récupération des clés de projet...');
|
|
151
109
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
152
110
|
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
@@ -160,6 +118,7 @@ async function setupProject() {
|
|
|
160
118
|
console.log(' [5/5] 📦 Installation des dépendances...');
|
|
161
119
|
execSync('npm install', { stdio: 'inherit' });
|
|
162
120
|
|
|
121
|
+
// Personnalisation du package.json
|
|
163
122
|
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
164
123
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
165
124
|
packageJson.name = projectName;
|
|
@@ -172,13 +131,13 @@ async function setupProject() {
|
|
|
172
131
|
|
|
173
132
|
} catch (error) {
|
|
174
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
|
+
}
|
|
175
138
|
if (fs.existsSync(projectDir)) {
|
|
176
139
|
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
177
140
|
}
|
|
178
|
-
} finally {
|
|
179
|
-
if (fs.existsSync(tempDir)) {
|
|
180
|
-
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
181
|
-
}
|
|
182
141
|
}
|
|
183
142
|
}
|
|
184
143
|
|