create-fleetbo-project 1.0.4 → 1.0.5

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,74 @@
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
+ // ⚠️ REPLACE WITH YOUR bootstrapProject FUNCTION URL
16
+ const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
15
17
 
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>');
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>');
20
22
  process.exit(1);
21
23
  }
22
24
 
23
- // --- Fonction Principale Asynchrone ---
25
+ // --- Main Function ---
24
26
  async function setupProject() {
25
- console.log(`Création de votre projet Fleetbo "${projectName}"...`);
27
+ console.log(chalk.blue(`Creating your Fleetbo project "${projectName}"...`));
28
+ const spinner = ora();
26
29
 
27
30
  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));
32
- });
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!'));
33
35
 
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()
36
+ spinner.start('Downloading template...');
37
+ const responseStream = await new Promise((resolve, reject) => https.get(repoUrl, res => resolve(res)).on('error', err => reject(err)));
38
+ spinner.succeed(chalk.green('Template downloaded.'));
39
+
40
+ spinner.start('Unzipping files...');
36
41
  await new Promise((resolve, reject) => {
37
- response.pipe(unzipper.Extract({ path: '.' }))
38
- .on('finish', resolve)
39
- .on('error', reject);
42
+ responseStream.pipe(unzipper.Extract({ path: '.' }))
43
+ .on('finish', resolve).on('error', reject);
40
44
  });
41
-
42
- // Le dossier décompressé aura un nom comme "repoName-main", on le renomme
43
- fs.renameSync(`${repoName}-main`, projectName);
45
+ fs.renameSync(`dev.fleetbo.io-main`, projectName);
46
+ spinner.succeed(chalk.green('Files unzipped.'));
44
47
 
45
- // 3. Se déplacer dans le nouveau dossier et installer les dépendances
46
48
  process.chdir(projectName);
47
- console.log('Installation des dépendances (cela peut prendre quelques minutes)...');
48
- execSync('npm install', { stdio: 'inherit' });
49
49
 
50
- // 4. Mettre à jour le package.json avec le nom du projet
50
+ spinner.start('Configuring project...');
51
+ const envContent = `REACT_APP_FLEETBO_DB_KEY="${projectSecrets.fleetboDB}"\nREACT_APP_ENTERPRISE_ID=${projectSecrets.appId}\n`;
52
+ fs.writeFileSync('.env', envContent, 'utf8');
53
+
51
54
  const packageJsonPath = path.join(process.cwd(), 'package.json');
52
55
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
53
56
  packageJson.name = projectName;
54
57
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
58
+ spinner.succeed(chalk.green('Project configured.'));
59
+
60
+ spinner.start('Installing dependencies (this may take a few minutes)...');
61
+ execSync('npm install', { stdio: 'inherit' });
62
+ spinner.succeed(chalk.green('Dependencies installed.'));
55
63
 
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`);
64
+ console.log(chalk.green.bold('\n🚀 Your Fleetbo project is ready!'));
65
+ console.log(`\nTo get started:`);
66
+ console.log(chalk.cyan(` cd ${projectName}`));
67
+ console.log(chalk.cyan(` npm start`));
60
68
 
61
69
  } catch (error) {
62
- console.error('\n❌ Une erreur est survenue lors de la création du projet :', error);
70
+ if (spinner.isSpinning) spinner.fail();
71
+ console.error(chalk.red('\n❌ An error occurred:'), error.response ? error.response.data : error.message);
63
72
  process.exit(1);
64
73
  }
65
74
  }
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.5",
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
  }