create-fleetbo-project 1.0.7 → 1.0.9

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.
@@ -1,156 +1,78 @@
1
- #!/usr/bin/env node
2
- const { execSync } = require('child_process');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const https = require('https');
6
- const unzipper = require('unzipper');
7
- const axios = require('axios');
8
- const ora = require('ora');
9
- const chalk = require('chalk');
10
-
11
- // --- Configuration ---
12
- const projectName = process.argv[2];
13
- const tokenArgIndex = process.argv.indexOf('--token');
14
- const bootstrapToken = tokenArgIndex !== -1 ? process.argv[tokenArgIndex + 1] : null;
15
- const repoUrl = 'https://github.com/FleetFleetbo/dev.fleetbo.io/archive/refs/heads/main.zip';
16
- const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
17
-
18
- // --- Validation ---
19
- if (!projectName || !bootstrapToken) {
20
- console.error(chalk.red('Error: Missing project name or token.'));
21
- console.log('Usage: npx create-fleetbo-project <project-name> --token <your-token>');
22
- process.exit(1);
23
- }
24
-
25
- // --- Main Function ---
26
- async function setupProject() {
27
- console.log(chalk.blue(`Creating your Fleetbo project "${projectName}"...`));
28
- const spinner = ora();
29
-
30
- try {
31
- // 1. Fetch configuration
32
- spinner.start('Fetching secure configuration...');
33
- const response = await axios.post(bootstrapUrl, { token: bootstrapToken });
34
- const projectSecrets = response.data;
35
- spinner.succeed(chalk.green('Configuration retrieved!'));
36
-
37
- console.log(chalk.dim('Config received:'), {
38
- fleetboDB: projectSecrets.fleetboDB ? '✓' : '✗',
39
- appId: projectSecrets.appId ? '' : '✗'
40
- });
41
-
42
- // 2. Download template
43
- spinner.start('Downloading template...');
44
- const responseStream = await new Promise((resolve, reject) =>
45
- https.get(repoUrl, res => resolve(res)).on('error', err => reject(err))
46
- );
47
- spinner.succeed(chalk.green('Template downloaded.'));
48
-
49
- // 3. Unzip files
50
- spinner.start('Unzipping files...');
51
- await new Promise((resolve, reject) => {
52
- responseStream.pipe(unzipper.Extract({ path: '.' }))
53
- .on('finish', resolve)
54
- .on('error', reject);
55
- });
56
-
57
- // Rename directory
58
- const extractedDir = 'dev.fleetbo.io-main';
59
- if (fs.existsSync(extractedDir)) {
60
- fs.renameSync(extractedDir, projectName);
61
- spinner.succeed(chalk.green('Files unzipped.'));
62
- } else {
63
- throw new Error(`Extracted directory not found: ${extractedDir}`);
64
- }
65
-
66
- // 4. Change to project directory
67
- const projectPath = path.resolve(projectName);
68
- process.chdir(projectPath);
69
- console.log(chalk.dim(`Working directory: ${process.cwd()}`));
70
-
71
- // 5. Configure project
72
- spinner.start('Configuring project...');
73
-
74
- // Create .env file
75
- const envContent = `REACT_APP_FLEETBO_DB_KEY="${projectSecrets.fleetboDB}"
76
- REACT_APP_ENTERPRISE_ID=${projectSecrets.appId}
77
- `;
78
- const envPath = path.join(process.cwd(), '.env');
79
- fs.writeFileSync(envPath, envContent, 'utf8');
80
-
81
- // Verify .env was created
82
- if (fs.existsSync(envPath)) {
83
- console.log(chalk.green('✓ .env file created successfully'));
84
- console.log(chalk.dim(` Location: ${envPath}`));
85
- } else {
86
- throw new Error('.env file was not created');
87
- }
88
-
89
- // Update package.json
90
- const packageJsonPath = path.join(process.cwd(), 'package.json');
91
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
92
- packageJson.name = projectName;
93
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
94
-
95
- spinner.succeed(chalk.green('Project configured.'));
96
-
97
- // 6. Create .env.example for reference
98
- const envExampleContent = `# Fleetbo Configuration
99
- # These values are automatically configured during project setup
100
- REACT_APP_FLEETBO_DB_KEY="your-fleetbo-db-key"
101
- REACT_APP_ENTERPRISE_ID=your-app-id
102
- `;
103
- fs.writeFileSync('.env.example', envExampleContent, 'utf8');
104
- console.log(chalk.dim('✓ .env.example created'));
105
-
106
- // 7. Ensure .gitignore includes .env
107
- const gitignorePath = path.join(process.cwd(), '.gitignore');
108
- if (fs.existsSync(gitignorePath)) {
109
- let gitignoreContent = fs.readFileSync(gitignorePath, 'utf8');
110
- if (!gitignoreContent.includes('.env')) {
111
- gitignoreContent += '\n# Environment variables\n.env\n.env.local\n';
112
- fs.writeFileSync(gitignorePath, gitignoreContent, 'utf8');
113
- console.log(chalk.dim('✓ .gitignore updated'));
114
- }
115
- }
116
-
117
- // 8. Install dependencies
118
- spinner.start('Installing dependencies (this may take a few minutes)...');
119
- execSync('npm install', { stdio: 'inherit' });
120
- spinner.succeed(chalk.green('Dependencies installed.'));
121
-
122
- // 9. Final verification
123
- console.log(chalk.green.bold('\n🚀 Your Fleetbo project is ready!\n'));
124
-
125
- // Verify configuration
126
- if (fs.existsSync(envPath)) {
127
- console.log(chalk.green('✓ Configuration file verified'));
128
- } else {
129
- console.log(chalk.yellow('⚠️ Warning: .env file not found after setup'));
130
- }
131
-
132
- console.log(chalk.cyan('\nTo get started:'));
133
- console.log(chalk.cyan(` cd ${projectName}`));
134
- console.log(chalk.cyan(` npm start`));
135
-
136
- console.log(chalk.dim('\nNote: Your .env file contains sensitive credentials and is excluded from git.'));
137
-
138
- } catch (error) {
139
- if (spinner.isSpinning) spinner.fail();
140
- console.error(chalk.red('\n❌ An error occurred:'));
141
-
142
- if (error.response) {
143
- console.error(chalk.red('API Error:'), error.response.data);
144
- } else if (error.code === 'ENOENT') {
145
- console.error(chalk.red('File Error:'), error.message);
146
- console.error(chalk.yellow('This might be a permissions issue.'));
147
- } else {
148
- console.error(chalk.red(error.message));
149
- }
150
-
151
- console.error(chalk.dim('\nStack trace:'), error.stack);
152
- process.exit(1);
153
- }
154
- }
155
-
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
+
156
78
  setupProject();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {