create-fleetbo-project 1.0.14 → 1.0.16
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 +77 -82
- package/package.json +1 -1
|
@@ -1,83 +1,78 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// install-react-template.js (Version amélioré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
|
-
// ⚠️ REMPLACEZ PAR L'URL DE VOTRE FONCTION bootstrapProject
|
|
18
|
-
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
19
|
-
|
|
20
|
-
// --- Validation ---
|
|
21
|
-
if (!projectName || !bootstrapToken) {
|
|
22
|
-
console.error(chalk.red('Erreur : Nom du projet ou token manquant.'));
|
|
23
|
-
console.log('Usage: npx create-fleetbo-project <nom-du-projet> --token <votre-token>');
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// --- Fonction Principale ---
|
|
28
|
-
async function setupProject() {
|
|
29
|
-
console.log(chalk.blue(`Création de votre projet Fleetbo "${projectName}"...`));
|
|
30
|
-
const spinner = ora();
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
spinner.start('Récupération de la configuration sécurisée...');
|
|
34
|
-
const response = await axios.post(bootstrapUrl, { token: bootstrapToken });
|
|
35
|
-
const projectSecrets = response.data;
|
|
36
|
-
spinner.succeed(chalk.green('Configuration récupérée !'));
|
|
37
|
-
|
|
38
|
-
spinner.start('Téléchargement du template...');
|
|
39
|
-
const responseStream = await new Promise((resolve, reject) => https.get(repoUrl, res => resolve(res)).on('error', err => reject(err)));
|
|
40
|
-
spinner.succeed(chalk.green('Template téléchargé.'));
|
|
41
|
-
|
|
42
|
-
spinner.start('Décompression des fichiers...');
|
|
43
|
-
await new Promise((resolve, reject) => {
|
|
44
|
-
responseStream.pipe(unzipper.Extract({ path: '.' }))
|
|
45
|
-
.on('finish', resolve).on('error', reject);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
fs.writeFileSync(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.error(chalk.red('\n❌ Une erreur est survenue :'), error.response ? error.response.data : error.message);
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// install-react-template.js (Version amélioré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
|
+
// ⚠️ REMPLACEZ PAR L'URL DE VOTRE FONCTION bootstrapProject
|
|
18
|
+
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
19
|
+
|
|
20
|
+
// --- Validation ---
|
|
21
|
+
if (!projectName || !bootstrapToken) {
|
|
22
|
+
console.error(chalk.red('Erreur : Nom du projet ou token manquant.'));
|
|
23
|
+
console.log('Usage: npx create-fleetbo-project <nom-du-projet> --token <votre-token>');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// --- Fonction Principale ---
|
|
28
|
+
async function setupProject() {
|
|
29
|
+
console.log(chalk.blue(`Création de votre projet Fleetbo "${projectName}"...`));
|
|
30
|
+
const spinner = ora();
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
spinner.start('Récupération de la configuration sécurisée...');
|
|
34
|
+
const response = await axios.post(bootstrapUrl, { token: bootstrapToken });
|
|
35
|
+
const projectSecrets = response.data;
|
|
36
|
+
spinner.succeed(chalk.green('Configuration récupérée !'));
|
|
37
|
+
|
|
38
|
+
spinner.start('Téléchargement du template...');
|
|
39
|
+
const responseStream = await new Promise((resolve, reject) => https.get(repoUrl, res => resolve(res)).on('error', err => reject(err)));
|
|
40
|
+
spinner.succeed(chalk.green('Template téléchargé.'));
|
|
41
|
+
|
|
42
|
+
spinner.start('Décompression des fichiers...');
|
|
43
|
+
await new Promise((resolve, reject) => {
|
|
44
|
+
responseStream.pipe(unzipper.Extract({ path: '.' }))
|
|
45
|
+
.on('finish', resolve).on('error', reject);
|
|
46
|
+
});
|
|
47
|
+
fs.renameSync(`dev.fleetbo.io-main`, projectName);
|
|
48
|
+
spinner.succeed(chalk.green('Fichiers décompressés.'));
|
|
49
|
+
|
|
50
|
+
process.chdir(projectName);
|
|
51
|
+
|
|
52
|
+
spinner.start('Configuration du projet...');
|
|
53
|
+
const envContent = `REACT_APP_FLEETBO_DB_KEY="${projectSecrets.fleetboDB}"\nREACT_APP_ENTERPRISE_ID=${projectSecrets.appId}\n`;
|
|
54
|
+
fs.writeFileSync('.env', envContent, 'utf8');
|
|
55
|
+
|
|
56
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
57
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
58
|
+
packageJson.name = projectName;
|
|
59
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
60
|
+
spinner.succeed(chalk.green('Projet configuré.'));
|
|
61
|
+
|
|
62
|
+
spinner.start('Installation des dépendances (cela peut prendre quelques minutes)...');
|
|
63
|
+
execSync('npm install', { stdio: 'inherit' });
|
|
64
|
+
spinner.succeed(chalk.green('Dépendances installées.'));
|
|
65
|
+
|
|
66
|
+
console.log(chalk.green.bold('\n🚀 Votre projet Fleetbo est prêt !'));
|
|
67
|
+
console.log(`\nPour commencer :`);
|
|
68
|
+
console.log(chalk.cyan(` cd ${projectName}`));
|
|
69
|
+
console.log(chalk.cyan(` npm start`));
|
|
70
|
+
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (spinner.isSpinning) spinner.fail();
|
|
73
|
+
console.error(chalk.red('\n❌ Une erreur est survenue :'), error.response ? error.response.data : error.message);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
83
78
|
setupProject();
|