create-fleetbo-project 1.0.15 → 1.0.17
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 +114 -88
- package/package.json +1 -1
|
@@ -1,89 +1,115 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// install-react-template.js (Version
|
|
3
|
-
const { execSync } = require('child_process');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const https = require('https');
|
|
7
|
-
const unzipper = require('unzipper');
|
|
8
|
-
const axios = require('axios');
|
|
9
|
-
const ora = require('ora');
|
|
10
|
-
const chalk = require('chalk');
|
|
11
|
-
|
|
12
|
-
// --- Configuration ---
|
|
13
|
-
const projectName = process.argv[2];
|
|
14
|
-
const tokenArgIndex = process.argv.indexOf('--token');
|
|
15
|
-
const bootstrapToken = tokenArgIndex !== -1 ? process.argv[tokenArgIndex + 1] : null;
|
|
16
|
-
const repoUrl = 'https://github.com/FleetFleetbo/dev.fleetbo.io/archive/refs/heads/main.zip';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Fichier : install-react-template.js (Version corrigée)
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const https = require('https');
|
|
7
|
+
const unzipper = require('unzipper');
|
|
8
|
+
const axios = require('axios');
|
|
9
|
+
const ora = require('ora');
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
|
|
12
|
+
// --- Configuration ---
|
|
13
|
+
const projectName = process.argv[2];
|
|
14
|
+
const tokenArgIndex = process.argv.indexOf('--token');
|
|
15
|
+
const bootstrapToken = tokenArgIndex !== -1 ? process.argv[tokenArgIndex + 1] : null;
|
|
16
|
+
const repoUrl = 'https://github.com/FleetFleetbo/dev.fleetbo.io/archive/refs/heads/main.zip';
|
|
17
|
+
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
18
|
+
|
|
19
|
+
// --- Validation ---
|
|
20
|
+
if (!projectName || !bootstrapToken) {
|
|
21
|
+
console.error(chalk.red('Erreur : Nom du projet ou token manquant.'));
|
|
22
|
+
console.log('Usage: npx create-fleetbo-project <nom-du-projet> --token <votre-token>');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// --- Fonction pour attendre que le dossier existe ---
|
|
27
|
+
function waitForDirectory(dirPath, timeout = 10000) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const startTime = Date.now();
|
|
30
|
+
const interval = setInterval(() => {
|
|
31
|
+
if (fs.existsSync(dirPath)) {
|
|
32
|
+
clearInterval(interval);
|
|
33
|
+
// Attendre un peu plus pour s'assurer que tous les fichiers sont écrits
|
|
34
|
+
setTimeout(() => resolve(), 500);
|
|
35
|
+
} else if (Date.now() - startTime > timeout) {
|
|
36
|
+
clearInterval(interval);
|
|
37
|
+
reject(new Error(`Le dossier ${dirPath} n'a pas été créé dans le délai imparti`));
|
|
38
|
+
}
|
|
39
|
+
}, 100);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// --- Fonction Principale ---
|
|
44
|
+
async function setupProject() {
|
|
45
|
+
console.log(chalk.blue(`Création de votre projet Fleetbo "${projectName}"...`));
|
|
46
|
+
const spinner = ora();
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
spinner.start('Récupération de la configuration sécurisée...');
|
|
50
|
+
const response = await axios.post(bootstrapUrl, { token: bootstrapToken });
|
|
51
|
+
const projectSecrets = response.data;
|
|
52
|
+
spinner.succeed(chalk.green('Configuration récupérée !'));
|
|
53
|
+
|
|
54
|
+
spinner.start('Téléchargement du template...');
|
|
55
|
+
const responseStream = await new Promise((resolve, reject) => {
|
|
56
|
+
https.get(repoUrl, res => resolve(res)).on('error', err => reject(err));
|
|
57
|
+
});
|
|
58
|
+
spinner.succeed(chalk.green('Template téléchargé.'));
|
|
59
|
+
|
|
60
|
+
spinner.start('Décompression des fichiers...');
|
|
61
|
+
|
|
62
|
+
// Décompression avec gestion d'erreur améliorée
|
|
63
|
+
await new Promise((resolve, reject) => {
|
|
64
|
+
responseStream
|
|
65
|
+
.pipe(unzipper.Extract({ path: '.' }))
|
|
66
|
+
.on('close', resolve) // 'close' est plus fiable que 'finish'
|
|
67
|
+
.on('error', reject);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Attendre que le dossier soit bien créé
|
|
71
|
+
const extractedDir = 'dev.fleetbo.io-main';
|
|
72
|
+
await waitForDirectory(extractedDir);
|
|
73
|
+
|
|
74
|
+
// Vérifier que le dossier existe avant de renommer
|
|
75
|
+
if (!fs.existsSync(extractedDir)) {
|
|
76
|
+
throw new Error(`Le dossier ${extractedDir} n'a pas été créé après la décompression`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Vérifier que le dossier cible n'existe pas déjà
|
|
80
|
+
if (fs.existsSync(projectName)) {
|
|
81
|
+
throw new Error(`Le dossier ${projectName} existe déjà`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fs.renameSync(extractedDir, projectName);
|
|
85
|
+
spinner.succeed(chalk.green('Fichiers décompressés.'));
|
|
86
|
+
|
|
87
|
+
process.chdir(projectName);
|
|
88
|
+
|
|
89
|
+
spinner.start('Configuration du projet...');
|
|
90
|
+
const envContent = `REACT_APP_FLEETBO_DB_KEY=${projectSecrets.fleetboDB}\nREACT_APP_ENTERPRISE_ID=${projectSecrets.appId}\n`;
|
|
91
|
+
fs.writeFileSync('.env', envContent, 'utf8');
|
|
92
|
+
|
|
93
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
94
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
95
|
+
packageJson.name = projectName;
|
|
96
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
97
|
+
spinner.succeed(chalk.green('Projet configuré.'));
|
|
98
|
+
|
|
99
|
+
spinner.start('Installation des dépendances (cela peut prendre quelques minutes)...');
|
|
100
|
+
execSync('npm install', { stdio: 'inherit' });
|
|
101
|
+
spinner.succeed(chalk.green('Dépendances installées.'));
|
|
102
|
+
|
|
103
|
+
console.log(chalk.green.bold('\n🚀 Votre projet Fleetbo est prêt !'));
|
|
104
|
+
console.log(`\nPour commencer :`);
|
|
105
|
+
console.log(chalk.cyan(` cd ${projectName}`));
|
|
106
|
+
console.log(chalk.cyan(` npm start`));
|
|
107
|
+
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (spinner.isSpinning) spinner.fail();
|
|
110
|
+
console.error(chalk.red('\n❌ Une erreur est survenue :'), error.response ? error.response.data : error.message);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
89
115
|
setupProject();
|