create-fleetbo-project 1.0.43 → 1.0.45
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/brouillon.js +122 -0
- package/install-react-template.js +14 -15
- package/package.json +1 -1
package/brouillon.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const https = require('https');
|
|
7
|
+
|
|
8
|
+
// --- Configuration ---
|
|
9
|
+
const repoOwner = 'FleetFleetbo';
|
|
10
|
+
const repoName = 'dev.fleetbo.io';
|
|
11
|
+
const branchName = 'master'; // Assurez-vous que c'est la bonne branche
|
|
12
|
+
|
|
13
|
+
const repoGitUrl = `https://github.com/${repoOwner}/${repoName}.git`;
|
|
14
|
+
const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
|
|
15
|
+
|
|
16
|
+
// --- Analyse des Arguments ---
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
const projectNameArg = args.find(arg => !arg.startsWith('--'));
|
|
19
|
+
const tokenArg = args.find(arg => arg.startsWith('--token='));
|
|
20
|
+
|
|
21
|
+
if (!projectNameArg) {
|
|
22
|
+
console.error('\n Error: Please specify a name for your project.');
|
|
23
|
+
console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bootstrapToken = tokenArg ? tokenArg.split('=')[1] : null;
|
|
28
|
+
|
|
29
|
+
if (!bootstrapToken) {
|
|
30
|
+
console.error('\n Error: The bootstrap token is missing.');
|
|
31
|
+
console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const projectName = projectNameArg;
|
|
36
|
+
|
|
37
|
+
// --- Fonctions Utilitaires ---
|
|
38
|
+
|
|
39
|
+
function fetchProjectKeys(token) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const postData = JSON.stringify({ token });
|
|
42
|
+
const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } };
|
|
43
|
+
const req = https.request(bootstrapUrl, options, (res) => {
|
|
44
|
+
let data = '';
|
|
45
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
46
|
+
res.on('end', () => {
|
|
47
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
48
|
+
try {
|
|
49
|
+
resolve(JSON.parse(data));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
reject(new Error('Invalid response from the key server.'));
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
const errorMsg = JSON.parse(data).error || `Server error (code: ${res.statusCode})`;
|
|
55
|
+
reject(new Error(errorMsg));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
req.on('error', (e) => reject(e));
|
|
60
|
+
req.write(postData);
|
|
61
|
+
req.end();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// --- Fonction Principale ---
|
|
66
|
+
|
|
67
|
+
async function setupProject() {
|
|
68
|
+
console.log(`\nCreating your Fleetbo project "${projectName}"...`);
|
|
69
|
+
const projectDir = path.join(process.cwd(), projectName);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
// Étape 1 : Télécharger la structure de base du projet
|
|
73
|
+
console.log(' [1/5] Initializing project structure...');
|
|
74
|
+
// On redirige la sortie d'erreur (stderr) vers null pour masquer les messages de progression de Git
|
|
75
|
+
execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}" 2> /dev/null`);
|
|
76
|
+
|
|
77
|
+
// Étape 2 : Se déplacer dans le dossier du projet et nettoyer
|
|
78
|
+
console.log(' [2/5] Project structure initialized. Configuring...');
|
|
79
|
+
process.chdir(projectDir);
|
|
80
|
+
|
|
81
|
+
// Supprimer l'historique Git pour commencer avec un projet propre
|
|
82
|
+
fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
|
|
83
|
+
|
|
84
|
+
// Étape 3 : Récupération des clés de projet
|
|
85
|
+
console.log(' [3/5] Fetching project keys...');
|
|
86
|
+
const keys = await fetchProjectKeys(bootstrapToken);
|
|
87
|
+
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
88
|
+
throw new Error("Received keys from the server are invalid.");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Étape 4 : Configuration du fichier .env
|
|
92
|
+
console.log(' [4/5] .env file configured successfully.');
|
|
93
|
+
//const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`; //99b426483d543b042209671dd53fb18
|
|
94
|
+
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=99b426483d543b042209671dd53fb18\n`;
|
|
95
|
+
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
96
|
+
|
|
97
|
+
// Étape 5 : Installation des dépendances
|
|
98
|
+
console.log(' [5/5] Installing dependencies...');
|
|
99
|
+
execSync('npm install', { stdio: 'inherit' });
|
|
100
|
+
|
|
101
|
+
// Personnalisation du package.json
|
|
102
|
+
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
103
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
104
|
+
packageJson.name = projectName;
|
|
105
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
106
|
+
|
|
107
|
+
console.log('\n 🚀 Your Fleetbo project is ready !');
|
|
108
|
+
console.log(`\n To get started, run the following commands :`);
|
|
109
|
+
console.log(` cd ${projectName}`);
|
|
110
|
+
console.log(` npm start`);
|
|
111
|
+
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('\n An error occurred while creating the project :', error.message);
|
|
114
|
+
// Nettoyage en cas d'erreur
|
|
115
|
+
if (fs.existsSync(projectDir)) {
|
|
116
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
setupProject();
|
|
122
|
+
|
|
@@ -19,7 +19,7 @@ const projectNameArg = args.find(arg => !arg.startsWith('--'));
|
|
|
19
19
|
const tokenArg = args.find(arg => arg.startsWith('--token='));
|
|
20
20
|
|
|
21
21
|
if (!projectNameArg) {
|
|
22
|
-
console.error('\n
|
|
22
|
+
console.error('\n❌ Erreur : Veuillez spécifier un nom pour votre projet.');
|
|
23
23
|
console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
|
|
24
24
|
process.exit(1);
|
|
25
25
|
}
|
|
@@ -27,7 +27,7 @@ if (!projectNameArg) {
|
|
|
27
27
|
const bootstrapToken = tokenArg ? tokenArg.split('=')[1] : null;
|
|
28
28
|
|
|
29
29
|
if (!bootstrapToken) {
|
|
30
|
-
console.error('\n
|
|
30
|
+
console.error('\n❌ Erreur : Le token d\'amorçage est manquant.');
|
|
31
31
|
console.log(' Usage: npx create-fleetbo-project <nom-du-projet> --token=<votre-token>');
|
|
32
32
|
process.exit(1);
|
|
33
33
|
}
|
|
@@ -48,10 +48,10 @@ function fetchProjectKeys(token) {
|
|
|
48
48
|
try {
|
|
49
49
|
resolve(JSON.parse(data));
|
|
50
50
|
} catch (e) {
|
|
51
|
-
reject(new Error('
|
|
51
|
+
reject(new Error('Réponse invalide du serveur de clés.'));
|
|
52
52
|
}
|
|
53
53
|
} else {
|
|
54
|
-
const errorMsg = JSON.parse(data).error || `
|
|
54
|
+
const errorMsg = JSON.parse(data).error || `Erreur serveur (code: ${res.statusCode})`;
|
|
55
55
|
reject(new Error(errorMsg));
|
|
56
56
|
}
|
|
57
57
|
});
|
|
@@ -65,37 +65,37 @@ function fetchProjectKeys(token) {
|
|
|
65
65
|
// --- Fonction Principale ---
|
|
66
66
|
|
|
67
67
|
async function setupProject() {
|
|
68
|
-
console.log(`\
|
|
68
|
+
console.log(`\nCréation de votre projet Fleetbo "${projectName}"...`);
|
|
69
69
|
const projectDir = path.join(process.cwd(), projectName);
|
|
70
70
|
|
|
71
71
|
try {
|
|
72
72
|
// Étape 1 : Télécharger la structure de base du projet
|
|
73
|
-
console.log(' [1/5]
|
|
73
|
+
console.log(' [1/5] Initialisation de la structure du projet...');
|
|
74
74
|
// On redirige la sortie d'erreur (stderr) vers null pour masquer les messages de progression de Git
|
|
75
75
|
execSync(`git clone --depth 1 --branch ${branchName} ${repoGitUrl} "${projectName}" 2> /dev/null`);
|
|
76
76
|
|
|
77
77
|
// Étape 2 : Se déplacer dans le dossier du projet et nettoyer
|
|
78
|
-
console.log(' [2/5]
|
|
78
|
+
console.log(' [2/5] Structure du projet initialisée. Configuration en cours...');
|
|
79
79
|
process.chdir(projectDir);
|
|
80
80
|
|
|
81
81
|
// Supprimer l'historique Git pour commencer avec un projet propre
|
|
82
82
|
fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
|
|
83
83
|
|
|
84
84
|
// Étape 3 : Récupération des clés de projet
|
|
85
|
-
console.log(' [3/5]
|
|
85
|
+
console.log(' [3/5] Récupération des clés de projet...');
|
|
86
86
|
const keys = await fetchProjectKeys(bootstrapToken);
|
|
87
87
|
if (!keys.enterpriseId || !keys.fleetboDBKey) {
|
|
88
|
-
throw new Error("
|
|
88
|
+
throw new Error("Les clés reçues du serveur sont invalides.");
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
// Étape 4 : Configuration du fichier .env
|
|
92
|
-
console.log(' [4/5] .env
|
|
92
|
+
console.log(' [4/5] Fichier .env configuré avec succès.');
|
|
93
93
|
//const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=${keys.enterpriseId}\n`; //99b426483d543b042209671dd53fb18
|
|
94
94
|
const envContent = `REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}\nREACT_APP_ENTERPRISE_ID=99b426483d543b042209671dd53fb18\n`;
|
|
95
95
|
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
96
96
|
|
|
97
97
|
// Étape 5 : Installation des dépendances
|
|
98
|
-
console.log(' [5/5]
|
|
98
|
+
console.log(' [5/5] Installation des dépendances...');
|
|
99
99
|
execSync('npm install', { stdio: 'inherit' });
|
|
100
100
|
|
|
101
101
|
// Personnalisation du package.json
|
|
@@ -104,13 +104,13 @@ async function setupProject() {
|
|
|
104
104
|
packageJson.name = projectName;
|
|
105
105
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
106
106
|
|
|
107
|
-
console.log('\n
|
|
108
|
-
console.log(`\
|
|
107
|
+
console.log('\n🚀 Votre projet Fleetbo est prêt !');
|
|
108
|
+
console.log(`\nPour commencer, exécutez les commandes suivantes :`);
|
|
109
109
|
console.log(` cd ${projectName}`);
|
|
110
110
|
console.log(` npm start`);
|
|
111
111
|
|
|
112
112
|
} catch (error) {
|
|
113
|
-
console.error('\n
|
|
113
|
+
console.error('\n Une erreur est survenue lors de la création du projet :', error.message);
|
|
114
114
|
// Nettoyage en cas d'erreur
|
|
115
115
|
if (fs.existsSync(projectDir)) {
|
|
116
116
|
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
@@ -119,4 +119,3 @@ async function setupProject() {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
setupProject();
|
|
122
|
-
|