create-fleetbo-project 1.0.3 → 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,43 +1,76 @@
1
- #!/usr/bin/env node
2
-
3
1
  const { execSync } = require('child_process');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const rimraf = require('rimraf'); // Ajoutez cette ligne pour gérer la suppression du dossier .git
7
- const packageInfo = require('./package.json');
8
-
9
- // Générer le contenu du fichier .env
10
- const envContent = `REACT_APP_PROJECT_NAME="${packageInfo.name}"\n`;
11
-
12
- // Écrire dans le fichier .env
13
- fs.writeFileSync('.env', envContent, 'utf8');
14
- console.log('.env file has been updated with project name!');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const https = require('https');
5
+ const unzipper = require('unzipper');
6
+ const axios = require('axios');
7
+ const ora = require('ora');
8
+ const chalk = require('chalk');
15
9
 
10
+ // --- Configuration ---
11
+ const projectName = process.argv[2];
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';
16
17
 
17
- if (process.argv.length < 3) {
18
- console.error('Usage: create-fleetbo-project <project-name>');
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>');
19
22
  process.exit(1);
20
23
  }
21
24
 
22
- const projectName = process.argv[2];
23
- const repoUrl = 'https://github.com/FleetFleetbo/dev.fleetbo.io.git'; // Remplacez par l'URL de votre modèle
24
-
25
- try {
26
- execSync(`git clone ${repoUrl} ${projectName}`, { stdio: 'inherit' });
27
- process.chdir(projectName);
28
- execSync('npm install', { stdio: 'inherit' });
29
-
30
- // Supprimer le dossier .git
31
- const gitDir = path.join(process.cwd(), '.git');
32
- rimraf.sync(gitDir); // Cette ligne supprime le dossier .git
33
-
34
- // Mettre à jour le nom dans package.json
35
- const packageJsonPath = path.join(process.cwd(), 'package.json');
36
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
37
- packageJson.name = projectName;
38
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
39
-
40
- console.log('Project setup complete!');
41
- } catch (error) {
42
- console.error('Error setting up project:', error);
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
+ 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
+ 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...');
41
+ await new Promise((resolve, reject) => {
42
+ responseStream.pipe(unzipper.Extract({ path: '.' }))
43
+ .on('finish', resolve).on('error', reject);
44
+ });
45
+ fs.renameSync(`dev.fleetbo.io-main`, projectName);
46
+ spinner.succeed(chalk.green('Files unzipped.'));
47
+
48
+ process.chdir(projectName);
49
+
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
+
54
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
55
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
56
+ packageJson.name = projectName;
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.'));
63
+
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`));
68
+
69
+ } catch (error) {
70
+ if (spinner.isSpinning) spinner.fail();
71
+ console.error(chalk.red('\n❌ An error occurred:'), error.response ? error.response.data : error.message);
72
+ process.exit(1);
73
+ }
43
74
  }
75
+
76
+ setupProject();
package/package.json CHANGED
@@ -1,18 +1,24 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.0.3",
4
- "description": "",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
7
- },
3
+ "version": "1.0.5",
4
+ "description": "Creates a new Fleetbo project.",
8
5
  "main": "install-react-template.js",
9
6
  "bin": {
10
7
  "create-fleetbo-project": "install-react-template.js"
11
8
  },
12
9
  "dependencies": {
13
- "rimraf": "^4.4.0"
10
+ "axios": "^1.12.2",
11
+ "chalk": "^4.1.2",
12
+ "ora": "^5.4.1",
13
+ "unzipper": "^0.10.14",
14
+ "yargs-parser": "^21.1.1"
14
15
  },
15
- "keywords": [],
16
- "author": "",
16
+ "keywords": [
17
+ "react",
18
+ "mobile",
19
+ "fullstack",
20
+ "fleetbo"
21
+ ],
22
+ "author": "Jean Aubain Tcheuffa",
17
23
  "license": "ISC"
18
24
  }