create-fleetbo-project 1.0.5 → 1.0.7

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,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  const { execSync } = require('child_process');
2
3
  const fs = require('fs');
3
4
  const path = require('path');
@@ -12,8 +13,7 @@ const projectName = process.argv[2];
12
13
  const tokenArgIndex = process.argv.indexOf('--token');
13
14
  const bootstrapToken = tokenArgIndex !== -1 ? process.argv[tokenArgIndex + 1] : null;
14
15
  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
+ const bootstrapUrl = 'https://us-central1-myapp-259bf.cloudfunctions.net/bootstrapProject';
17
17
 
18
18
  // --- Validation ---
19
19
  if (!projectName || !bootstrapToken) {
@@ -26,49 +26,129 @@ if (!projectName || !bootstrapToken) {
26
26
  async function setupProject() {
27
27
  console.log(chalk.blue(`Creating your Fleetbo project "${projectName}"...`));
28
28
  const spinner = ora();
29
-
29
+
30
30
  try {
31
+ // 1. Fetch configuration
31
32
  spinner.start('Fetching secure configuration...');
32
33
  const response = await axios.post(bootstrapUrl, { token: bootstrapToken });
33
34
  const projectSecrets = response.data;
34
35
  spinner.succeed(chalk.green('Configuration retrieved!'));
36
+
37
+ console.log(chalk.dim('Config received:'), {
38
+ fleetboDB: projectSecrets.fleetboDB ? '✓' : '✗',
39
+ appId: projectSecrets.appId ? '✓' : '✗'
40
+ });
35
41
 
42
+ // 2. Download template
36
43
  spinner.start('Downloading template...');
37
- const responseStream = await new Promise((resolve, reject) => https.get(repoUrl, res => resolve(res)).on('error', err => reject(err)));
44
+ const responseStream = await new Promise((resolve, reject) =>
45
+ https.get(repoUrl, res => resolve(res)).on('error', err => reject(err))
46
+ );
38
47
  spinner.succeed(chalk.green('Template downloaded.'));
39
48
 
49
+ // 3. Unzip files
40
50
  spinner.start('Unzipping files...');
41
51
  await new Promise((resolve, reject) => {
42
- responseStream.pipe(unzipper.Extract({ path: '.' }))
43
- .on('finish', resolve).on('error', reject);
52
+ responseStream.pipe(unzipper.Extract({ path: '.' }))
53
+ .on('finish', resolve)
54
+ .on('error', reject);
44
55
  });
45
- fs.renameSync(`dev.fleetbo.io-main`, projectName);
46
- spinner.succeed(chalk.green('Files unzipped.'));
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
+ }
47
65
 
48
- process.chdir(projectName);
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()}`));
49
70
 
71
+ // 5. Configure project
50
72
  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
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
54
90
  const packageJsonPath = path.join(process.cwd(), 'package.json');
55
91
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
56
92
  packageJson.name = projectName;
57
93
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
94
+
58
95
  spinner.succeed(chalk.green('Project configured.'));
59
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
60
118
  spinner.start('Installing dependencies (this may take a few minutes)...');
61
119
  execSync('npm install', { stdio: 'inherit' });
62
120
  spinner.succeed(chalk.green('Dependencies installed.'));
63
121
 
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`));
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.'));
68
137
 
69
138
  } catch (error) {
70
139
  if (spinner.isSpinning) spinner.fail();
71
- console.error(chalk.red('\n❌ An error occurred:'), error.response ? error.response.data : error.message);
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);
72
152
  process.exit(1);
73
153
  }
74
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fleetbo-project",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Creates a new Fleetbo project.",
5
5
  "main": "install-react-template.js",
6
6
  "bin": {