create-fleetbo-project 1.0.4 → 1.0.6

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,65 +1,153 @@
1
- #!/usr/bin/env node
2
- // Fichier : install-react-template.js (Version améliorée)
3
-
4
1
  const { execSync } = require('child_process');
5
2
  const fs = require('fs');
6
3
  const path = require('path');
7
4
  const https = require('https');
8
- const unzipper = require('unzipper'); // Une librairie pour décompresser les archives
5
+ const unzipper = require('unzipper');
6
+ const axios = require('axios');
7
+ const ora = require('ora');
8
+ const chalk = require('chalk');
9
9
 
10
10
  // --- Configuration ---
11
11
  const projectName = process.argv[2];
12
- const repoOwner = 'FleetFleetbo';
13
- const repoName = 'dev.fleetbo.io';
14
- const repoUrl = `https://github.com/${repoOwner}/${repoName}/archive/refs/heads/main.zip`;
12
+ const tokenArgIndex = process.argv.indexOf('--token');
13
+ const bootstrapToken = tokenArgIndex !== -1 ? process.argv[tokenArgIndex + 1] : null;
14
+ const repoUrl = 'https://github.com/FleetFleetbo/dev.fleetbo.io/archive/refs/heads/main.zip';
15
+ const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
15
16
 
16
- // --- Validation de l'entrée ---
17
- if (!projectName) {
18
- console.error('Erreur : Veuillez spécifier un nom pour votre projet.');
19
- console.log('Usage: npx create-fleetbo-project <nom-du-projet>');
17
+ // --- Validation ---
18
+ if (!projectName || !bootstrapToken) {
19
+ console.error(chalk.red('Error: Missing project name or token.'));
20
+ console.log('Usage: npx create-fleetbo-project <project-name> --token <your-token>');
20
21
  process.exit(1);
21
22
  }
22
23
 
23
- // --- Fonction Principale Asynchrone ---
24
+ // --- Main Function ---
24
25
  async function setupProject() {
25
- console.log(`Création de votre projet Fleetbo "${projectName}"...`);
26
-
26
+ console.log(chalk.blue(`Creating your Fleetbo project "${projectName}"...`));
27
+ const spinner = ora();
28
+
27
29
  try {
28
- // 1. Télécharger le template depuis GitHub
29
- console.log('Téléchargement du template...');
30
- const response = await new Promise((resolve, reject) => {
31
- https.get(repoUrl, res => resolve(res)).on('error', err => reject(err));
30
+ // 1. Fetch configuration
31
+ spinner.start('Fetching secure configuration...');
32
+ const response = await axios.post(bootstrapUrl, { token: bootstrapToken });
33
+ const projectSecrets = response.data;
34
+ spinner.succeed(chalk.green('Configuration retrieved!'));
35
+
36
+ console.log(chalk.dim('Config received:'), {
37
+ fleetboDB: projectSecrets.fleetboDB ? '✓' : '✗',
38
+ appId: projectSecrets.appId ? '✓' : '✗'
32
39
  });
33
40
 
34
- // 2. Décompresser l'archive dans le dossier du projet
35
- // Le contenu du zip est dans un sous-dossier (ex: dev.fleetbo.io-main), on le gère avec .pipe()
41
+ // 2. Download template
42
+ spinner.start('Downloading template...');
43
+ const responseStream = await new Promise((resolve, reject) =>
44
+ https.get(repoUrl, res => resolve(res)).on('error', err => reject(err))
45
+ );
46
+ spinner.succeed(chalk.green('Template downloaded.'));
47
+
48
+ // 3. Unzip files
49
+ spinner.start('Unzipping files...');
36
50
  await new Promise((resolve, reject) => {
37
- response.pipe(unzipper.Extract({ path: '.' }))
38
- .on('finish', resolve)
39
- .on('error', reject);
51
+ responseStream.pipe(unzipper.Extract({ path: '.' }))
52
+ .on('finish', resolve)
53
+ .on('error', reject);
40
54
  });
41
55
 
42
- // Le dossier décompressé aura un nom comme "repoName-main", on le renomme
43
- fs.renameSync(`${repoName}-main`, projectName);
56
+ // Rename directory
57
+ const extractedDir = 'dev.fleetbo.io-main';
58
+ if (fs.existsSync(extractedDir)) {
59
+ fs.renameSync(extractedDir, projectName);
60
+ spinner.succeed(chalk.green('Files unzipped.'));
61
+ } else {
62
+ throw new Error(`Extracted directory not found: ${extractedDir}`);
63
+ }
44
64
 
45
- // 3. Se déplacer dans le nouveau dossier et installer les dépendances
46
- process.chdir(projectName);
47
- console.log('Installation des dépendances (cela peut prendre quelques minutes)...');
48
- execSync('npm install', { stdio: 'inherit' });
65
+ // 4. Change to project directory
66
+ const projectPath = path.resolve(projectName);
67
+ process.chdir(projectPath);
68
+ console.log(chalk.dim(`Working directory: ${process.cwd()}`));
49
69
 
50
- // 4. Mettre à jour le package.json avec le nom du projet
70
+ // 5. Configure project
71
+ spinner.start('Configuring project...');
72
+
73
+ // Create .env file
74
+ const envContent = `REACT_APP_FLEETBO_DB_KEY="${projectSecrets.fleetboDB}"
75
+ REACT_APP_ENTERPRISE_ID=${projectSecrets.appId}
76
+ `;
77
+ const envPath = path.join(process.cwd(), '.env');
78
+ fs.writeFileSync(envPath, envContent, 'utf8');
79
+
80
+ // Verify .env was created
81
+ if (fs.existsSync(envPath)) {
82
+ console.log(chalk.green('✓ .env file created successfully'));
83
+ console.log(chalk.dim(` Location: ${envPath}`));
84
+ } else {
85
+ throw new Error('.env file was not created');
86
+ }
87
+
88
+ // Update package.json
51
89
  const packageJsonPath = path.join(process.cwd(), 'package.json');
52
90
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
53
91
  packageJson.name = projectName;
54
92
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
93
+
94
+ spinner.succeed(chalk.green('Project configured.'));
55
95
 
56
- console.log('\n🚀 Votre projet Fleetbo est prêt !');
57
- console.log(`\nPour commencer, exécutez les commandes suivantes :`);
58
- console.log(` cd ${projectName}`);
59
- console.log(` npm start`);
96
+ // 6. Create .env.example for reference
97
+ const envExampleContent = `# Fleetbo Configuration
98
+ # These values are automatically configured during project setup
99
+ REACT_APP_FLEETBO_DB_KEY="your-fleetbo-db-key"
100
+ REACT_APP_ENTERPRISE_ID=your-app-id
101
+ `;
102
+ fs.writeFileSync('.env.example', envExampleContent, 'utf8');
103
+ console.log(chalk.dim('✓ .env.example created'));
104
+
105
+ // 7. Ensure .gitignore includes .env
106
+ const gitignorePath = path.join(process.cwd(), '.gitignore');
107
+ if (fs.existsSync(gitignorePath)) {
108
+ let gitignoreContent = fs.readFileSync(gitignorePath, 'utf8');
109
+ if (!gitignoreContent.includes('.env')) {
110
+ gitignoreContent += '\n# Environment variables\n.env\n.env.local\n';
111
+ fs.writeFileSync(gitignorePath, gitignoreContent, 'utf8');
112
+ console.log(chalk.dim('✓ .gitignore updated'));
113
+ }
114
+ }
115
+
116
+ // 8. Install dependencies
117
+ spinner.start('Installing dependencies (this may take a few minutes)...');
118
+ execSync('npm install', { stdio: 'inherit' });
119
+ spinner.succeed(chalk.green('Dependencies installed.'));
120
+
121
+ // 9. Final verification
122
+ console.log(chalk.green.bold('\n🚀 Your Fleetbo project is ready!\n'));
123
+
124
+ // Verify configuration
125
+ if (fs.existsSync(envPath)) {
126
+ console.log(chalk.green('✓ Configuration file verified'));
127
+ } else {
128
+ console.log(chalk.yellow('⚠️ Warning: .env file not found after setup'));
129
+ }
130
+
131
+ console.log(chalk.cyan('\nTo get started:'));
132
+ console.log(chalk.cyan(` cd ${projectName}`));
133
+ console.log(chalk.cyan(` npm start`));
134
+
135
+ console.log(chalk.dim('\nNote: Your .env file contains sensitive credentials and is excluded from git.'));
60
136
 
61
137
  } catch (error) {
62
- console.error('\n❌ Une erreur est survenue lors de la création du projet :', error);
138
+ if (spinner.isSpinning) spinner.fail();
139
+ console.error(chalk.red('\n❌ An error occurred:'));
140
+
141
+ if (error.response) {
142
+ console.error(chalk.red('API Error:'), error.response.data);
143
+ } else if (error.code === 'ENOENT') {
144
+ console.error(chalk.red('File Error:'), error.message);
145
+ console.error(chalk.yellow('This might be a permissions issue.'));
146
+ } else {
147
+ console.error(chalk.red(error.message));
148
+ }
149
+
150
+ console.error(chalk.dim('\nStack trace:'), error.stack);
63
151
  process.exit(1);
64
152
  }
65
153
  }
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.0.4",
4
- "description": "Crée une nouvelle application mobile avec le framework Fleetbo.",
3
+ "version": "1.0.6",
4
+ "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {
7
7
  "create-fleetbo-project": "install-react-template.js"
8
8
  },
9
9
  "dependencies": {
10
+ "axios": "^1.12.2",
11
+ "chalk": "^4.1.2",
12
+ "ora": "^5.4.1",
10
13
  "unzipper": "^0.10.14",
11
14
  "yargs-parser": "^21.1.1"
12
15
  },
@@ -16,6 +19,6 @@
16
19
  "fullstack",
17
20
  "fleetbo"
18
21
  ],
19
- "author": "Fleetbo",
22
+ "author": "Jean Aubain Tcheuffa",
20
23
  "license": "ISC"
21
24
  }