create-fleetbo-project 1.2.32 → 1.2.34
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.
- package/install-react-template.js +112 -34
- package/package.json +1 -1
|
@@ -19,10 +19,95 @@ const path = require('path');
|
|
|
19
19
|
const axios = require('axios');
|
|
20
20
|
const dotenv = require('dotenv');
|
|
21
21
|
const os = require('os');
|
|
22
|
+
const archiver = require('archiver');
|
|
23
|
+
const FormData = require('form-data');
|
|
22
24
|
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
+
const CLOUD_ENGINE_URL = "https://us-central1-myapp-259bf.cloudfunctions.net/uploadLogicBundle";
|
|
26
|
+
const UPDATE_NETWORK_URL = 'https://us-central1-myapp-259bf.cloudfunctions.net/updateDeveloperNetwork';
|
|
27
|
+
const PORT = 3000;
|
|
28
|
+
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
const command = args[0];
|
|
31
|
+
|
|
32
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
33
|
+
if (!fs.existsSync(envPath)) {
|
|
34
|
+
console.error('❌ Error: Configuration file (.env) not found.');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
dotenv.config({ path: envPath });
|
|
38
|
+
|
|
39
|
+
const projectId = process.env.REACT_APP_ENTERPRISE_ID;
|
|
40
|
+
const keyApp = process.env.REACT_KEY_APP;
|
|
41
|
+
const testerEmail = process.env.REACT_APP_TESTER_EMAIL;
|
|
42
|
+
|
|
43
|
+
if (command === 'deploy') {
|
|
44
|
+
|
|
45
|
+
(async () => {
|
|
46
|
+
console.log('\\n\\x1b[36m%s\\x1b[0m', '⚡ FLEETBO CLOUD ENGINE v1.0');
|
|
47
|
+
console.log('\\x1b[32m%s\\x1b[0m', 'Target Runtime:', keyApp);
|
|
48
|
+
console.log('------------------------------------------------');
|
|
49
|
+
|
|
50
|
+
console.log('🔨 \\x1b[33mCompiling local assets...\\x1b[0m');
|
|
51
|
+
try {
|
|
52
|
+
execSync('npm run build', { stdio: 'inherit' });
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error('\\n❌ Build failed. Fix errors and try again.');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let buildDir = 'dist';
|
|
59
|
+
if (!fs.existsSync(path.join(process.cwd(), 'dist')) && fs.existsSync(path.join(process.cwd(), 'build'))) {
|
|
60
|
+
buildDir = 'build';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!fs.existsSync(path.join(process.cwd(), buildDir))) {
|
|
64
|
+
console.error(\`\\n❌ Error: Build folder '\${buildDir}' not found.\`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log('\\n📦 \\x1b[33mProcessing Neural Logic...\\x1b[0m');
|
|
69
|
+
console.log(\` Detected stack: React (\${buildDir})\`);
|
|
70
|
+
|
|
71
|
+
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
72
|
+
const form = new FormData();
|
|
73
|
+
|
|
74
|
+
form.append('file', archive, { filename: 'bundle.zip' });
|
|
75
|
+
archive.directory(path.join(process.cwd(), buildDir), false);
|
|
76
|
+
archive.finalize();
|
|
77
|
+
|
|
78
|
+
console.log('☁️ \\x1b[33mEstablishing Uplink to Switch-Engine...\\x1b[0m');
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const response = await axios.post(CLOUD_ENGINE_URL, form, {
|
|
82
|
+
headers: {
|
|
83
|
+
...form.getHeaders(),
|
|
84
|
+
'x-project-id': projectId,
|
|
85
|
+
'Content-Length': form.getLengthSync()
|
|
86
|
+
},
|
|
87
|
+
maxContentLength: Infinity,
|
|
88
|
+
maxBodyLength: Infinity
|
|
89
|
+
});
|
|
25
90
|
|
|
91
|
+
console.log('------------------------------------------------');
|
|
92
|
+
console.log('✅ \\x1b[1m\\x1b[32mDEPLOYMENT SUCCESSFUL\\x1b[0m');
|
|
93
|
+
console.log(\` Build ID: \${response.data.buildId}\`);
|
|
94
|
+
console.log(\` Payload: \${response.data.size}\`);
|
|
95
|
+
console.log('\\n📱 \\x1b[36mNative Runtime has been hot-swapped.\\x1b[0m');
|
|
96
|
+
console.log(' Your app is live.\\n');
|
|
97
|
+
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error('\\n❌ \\x1b[31mCRITICAL FAILURE\\x1b[0m');
|
|
100
|
+
if (error.response) {
|
|
101
|
+
console.error(\` Server responded with \${error.response.status}: \${JSON.stringify(error.response.data)}\`);
|
|
102
|
+
} else {
|
|
103
|
+
console.error(\` \${error.message}\`);
|
|
104
|
+
}
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
108
|
+
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
26
111
|
|
|
27
112
|
const GENERATOR_COMMANDS = ['page', 'g', 'generate', 'android', 'ios'];
|
|
28
113
|
|
|
@@ -31,20 +116,12 @@ if (GENERATOR_COMMANDS.includes(command)) {
|
|
|
31
116
|
require('./page.js');
|
|
32
117
|
} catch (error) {
|
|
33
118
|
console.error('\\x1b[31m%s\\x1b[0m', ' CRITICAL ERROR in Fleetbo Generator:');
|
|
34
|
-
|
|
35
|
-
console.error(". The generator script (scripts/page.js) is missing.");
|
|
36
|
-
console.error(" Please update your Fleetbo SDK.");
|
|
37
|
-
} else {
|
|
38
|
-
console.error(error.message);
|
|
39
|
-
}
|
|
119
|
+
console.error(error.message);
|
|
40
120
|
process.exit(1);
|
|
41
121
|
}
|
|
42
122
|
return;
|
|
43
123
|
}
|
|
44
124
|
|
|
45
|
-
const UPDATE_NETWORK_URL = 'https://us-central1-myapp-259bf.cloudfunctions.net/updateDeveloperNetwork';
|
|
46
|
-
const PORT = 3000;
|
|
47
|
-
|
|
48
125
|
const NULL_DEV = process.platform === 'win32' ? '>nul 2>&1' : '2>/dev/null';
|
|
49
126
|
|
|
50
127
|
function killProcessOnPort(port) {
|
|
@@ -82,9 +159,10 @@ async function syncFirebase(keyApp, networkUrl, testerEmail) {
|
|
|
82
159
|
networkUrl,
|
|
83
160
|
tester: testerEmail
|
|
84
161
|
});
|
|
85
|
-
console.log('\\n[Fleetbo]
|
|
162
|
+
console.log('\\n[Fleetbo] ---------------------------------------------------\\n');
|
|
86
163
|
console.log(\`[Fleetbo] ✅ Uplink Status: Online for \${testerEmail}\`);
|
|
87
164
|
console.log(\`[Fleetbo] 🚀 Simulator: https://fleetbo.io/studio/view/\${keyApp}\`);
|
|
165
|
+
console.log(\'[Fleetbo] 👉 Your studio is ready. You can now open the link above.\n');
|
|
88
166
|
console.log('[Fleetbo] ---------------------------------------------------\\n');
|
|
89
167
|
} catch (err) {
|
|
90
168
|
console.error(\`[Fleetbo] ⚠️ Sync Error: \${err.message}\`);
|
|
@@ -97,15 +175,6 @@ async function runDevEnvironment() {
|
|
|
97
175
|
killNetworkService();
|
|
98
176
|
killProcessOnPort(PORT);
|
|
99
177
|
|
|
100
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
101
|
-
if (!fs.existsSync(envPath)) {
|
|
102
|
-
console.error('Error: Configuration file not found.');
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
dotenv.config({ path: envPath });
|
|
106
|
-
const keyApp = process.env.REACT_KEY_APP;
|
|
107
|
-
const testerEmail = process.env.REACT_APP_TESTER_EMAIL;
|
|
108
|
-
|
|
109
178
|
if (!testerEmail) {
|
|
110
179
|
console.error('Error: REACT_APP_TESTER_EMAIL missing in .env');
|
|
111
180
|
process.exit(1);
|
|
@@ -131,14 +200,15 @@ async function runDevEnvironment() {
|
|
|
131
200
|
if (!connectionStarted && (output.includes('Local:') || output.includes('Compiled successfully'))) {
|
|
132
201
|
connectionStarted = true;
|
|
133
202
|
console.log(\`\\n[Fleetbo] 🔗 Local Server Ready. Establishing Secure Uplink...\`);
|
|
203
|
+
console.log(\`\\n[Fleetbo] 🛑 STOP! DO NOT open the Studio yet.\`);
|
|
204
|
+
console.log(\`\\n[Fleetbo] ⏳ Establishing Secure Uplink... Please wait...\`);
|
|
205
|
+
|
|
134
206
|
|
|
135
207
|
const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
136
208
|
|
|
137
209
|
const uplink = spawn(npxCmd, ['cloudflared', 'tunnel', '--url', \`http://localhost:\${PORT}\`], { shell: true });
|
|
138
|
-
|
|
139
210
|
uplink.stderr.on('data', (chunk) => {
|
|
140
211
|
const log = chunk.toString();
|
|
141
|
-
|
|
142
212
|
const match = log.match(/https:\\/\\/[a-zA-Z0-9-]+\\.trycloudflare\\.com/);
|
|
143
213
|
|
|
144
214
|
if (match) {
|
|
@@ -160,7 +230,6 @@ async function runDevEnvironment() {
|
|
|
160
230
|
runDevEnvironment();
|
|
161
231
|
`;
|
|
162
232
|
|
|
163
|
-
// --- LOGIQUE D'INSTALLATION (INCHANGÉE) ---
|
|
164
233
|
const args = process.argv.slice(2);
|
|
165
234
|
const projectNameArg = args.find(arg => !arg.startsWith('--'));
|
|
166
235
|
const tokenArg = args.find(arg => arg.startsWith('--token='));
|
|
@@ -248,13 +317,13 @@ async function setupProject() {
|
|
|
248
317
|
|
|
249
318
|
console.log(' [4/6] ⚙️ Configuring environment & CLI...');
|
|
250
319
|
|
|
251
|
-
const envContent =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
320
|
+
const envContent =
|
|
321
|
+
`REACT_APP_FLEETBO_DB_KEY=${keys.fleetboDBKey}
|
|
322
|
+
REACT_APP_ENTERPRISE_ID=${keys.enterpriseId}
|
|
323
|
+
REACT_KEY_APP=${projectName}
|
|
324
|
+
REACT_APP_TESTER_EMAIL=${userEmailArg}
|
|
325
|
+
DANGEROUSLY_DISABLE_HOST_CHECK=true
|
|
326
|
+
WDS_SOCKET_PORT=0 `;
|
|
258
327
|
|
|
259
328
|
fs.writeFileSync(path.join(projectDir, '.env'), envContent, 'utf8');
|
|
260
329
|
const scriptsDir = path.join(projectDir, 'scripts');
|
|
@@ -267,17 +336,26 @@ async function setupProject() {
|
|
|
267
336
|
console.log(' [5/6] 📚 Installing dependencies...');
|
|
268
337
|
execSync('npm install', { stdio: 'inherit' });
|
|
269
338
|
|
|
270
|
-
execSync('npm install cloudflared dotenv axios --save-dev', { stdio: 'ignore' });
|
|
339
|
+
execSync('npm install cloudflared dotenv axios archiver form-data --save-dev', { stdio: 'ignore' });
|
|
271
340
|
|
|
272
341
|
console.log(' [6/6] ✨ Finalizing setup...');
|
|
273
342
|
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
274
343
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
344
|
+
|
|
275
345
|
packageJson.name = projectName;
|
|
276
|
-
|
|
346
|
+
|
|
347
|
+
packageJson.scripts = {
|
|
348
|
+
...packageJson.scripts,
|
|
349
|
+
"fleetbo": "node scripts/cli.js",
|
|
350
|
+
"dev": "node scripts/cli.js"
|
|
351
|
+
};
|
|
352
|
+
|
|
277
353
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
278
354
|
|
|
279
355
|
console.log('\n [Fleetbo] ✅ Project successfully created!');
|
|
280
|
-
console.log(`\n👉 Run: cd ${projectName}
|
|
356
|
+
console.log(`\n👉 Run: cd ${projectName}`);
|
|
357
|
+
console.log(`👉 Start Dev: npm run fleetbo`);
|
|
358
|
+
console.log(`👉 Deploy App: npm run fleetbo deploy`);
|
|
281
359
|
|
|
282
360
|
} catch (error) {
|
|
283
361
|
console.error('\n❌ Setup failed:', error.message);
|