flashorm 1.0.1

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/README.md ADDED
@@ -0,0 +1,601 @@
1
+ # FlashORM ORM
2
+
3
+ A powerful, database-agnostic migration CLI tool built in Go with multi-database support, visual database editor (FlashORM Studio), and type-safe code generation for JavaScript/TypeScript.
4
+
5
+ ## ✨ Features
6
+
7
+ - 🎨 **FlashORM Studio**: Visual database editor with React-based schema visualization
8
+ - 🗃️ **Multi-Database Support**: PostgreSQL, MySQL, SQLite
9
+ - 🔄 **Migration Management**: Create, apply, and track migrations
10
+ - 🔒 **Safe Migration System**: Transaction-based execution with automatic rollback
11
+ - 📤 **Smart Export System**: Multiple formats (JSON, CSV, SQLite)
12
+ - 🔧 **Type-Safe Code Generation**: Generate fully typed JavaScript/TypeScript code
13
+ - ⚡ **Blazing Fast**: 2.5x faster than Drizzle, 10x faster than Prisma
14
+ - 💻 **Raw SQL Execution**: Execute SQL files or inline queries
15
+ - 🎯 **Prisma-like Commands**: Familiar CLI interface
16
+ - 🎨 **Enum Support**: Full PostgreSQL ENUM support
17
+
18
+ ## 📊 Performance
19
+
20
+ | Operation | FlashORM | Drizzle | Prisma |
21
+ |-----------|-------|---------|--------|
22
+ | Insert 1000 Users | **158ms** | 224ms | 230ms |
23
+ | Complex Query x500 | **4071ms** | 12500ms | 56322ms |
24
+ | Mixed Workload x1000 | **186ms** | 1174ms | 10863ms |
25
+ | **TOTAL** | **6947ms** | **17149ms** | **71551ms** |
26
+
27
+ ## 🚀 Installation
28
+
29
+ ```bash
30
+ npm install -g flashorm
31
+ ```
32
+
33
+ ### For Bun Users
34
+
35
+ Bun blocks postinstall scripts by default. After installation, run:
36
+
37
+ ```bash
38
+ bun pm trust flashorm
39
+ ```
40
+
41
+ Or add to your `package.json`:
42
+ ```json
43
+ {
44
+ "trustedDependencies": ["flashorm"]
45
+ }
46
+ ```
47
+
48
+ ## 🏁 Quick Start
49
+
50
+ ### 1. Initialize Project
51
+
52
+ ```bash
53
+ flash init --postgresql # or --mysql, --sqlite
54
+ ```
55
+
56
+ This creates:
57
+ ```
58
+ your-project/
59
+ ├── flash.config.json
60
+ ├── .env
61
+ └── db/
62
+ ├── schema/
63
+ │ └── schema.sql
64
+ └── queries/
65
+ └── users.sql
66
+ ```
67
+
68
+ ### 2. Configure Database
69
+
70
+ ```bash
71
+ # .env file
72
+ DATABASE_URL=postgresql://user:password@localhost:5432/mydb
73
+ ```
74
+
75
+ ### 3. Define Schema
76
+
77
+ **db/schema/schema.sql**
78
+ ```sql
79
+ CREATE TABLE users (
80
+ id SERIAL PRIMARY KEY,
81
+ name VARCHAR(255) NOT NULL,
82
+ email VARCHAR(255) UNIQUE NOT NULL,
83
+ created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
84
+ updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
85
+ );
86
+ ```
87
+
88
+ ### 4. Write Queries
89
+
90
+ **db/queries/users.sql**
91
+ ```sql
92
+ -- name: GetUser :one
93
+ SELECT id, name, email, created_at, updated_at FROM users
94
+ WHERE id = $1 LIMIT 1;
95
+
96
+ -- name: CreateUser :one
97
+ INSERT INTO users (name, email)
98
+ VALUES ($1, $2)
99
+ RETURNING id, name, email, created_at, updated_at;
100
+
101
+ -- name: ListUsers :many
102
+ SELECT id, name, email, created_at, updated_at FROM users
103
+ ORDER BY created_at DESC;
104
+
105
+ -- name: UpdateUser :one
106
+ UPDATE users
107
+ SET name = $2, email = $3, updated_at = NOW()
108
+ WHERE id = $1
109
+ RETURNING id, name, email, created_at, updated_at;
110
+
111
+ -- name: DeleteUser :exec
112
+ DELETE FROM users WHERE id = $1;
113
+ ```
114
+
115
+ ### 5. Create Migration
116
+
117
+ ```bash
118
+ flash migrate "create users table"
119
+ ```
120
+
121
+ ### 6. Apply Migration
122
+
123
+ ```bash
124
+ flash apply
125
+ ```
126
+
127
+ ### 7. Generate Type-Safe Code
128
+
129
+ ```bash
130
+ flash gen
131
+ ```
132
+
133
+ **Generated Types (flash_gen/index.d.ts)**
134
+ ```typescript
135
+ // Code generated by FlashORM. DO NOT EDIT.
136
+
137
+ export interface Users {
138
+ id: number | null;
139
+ name: string;
140
+ email: string;
141
+ created_at: Date;
142
+ updated_at: Date;
143
+ }
144
+
145
+ export interface GetUserResult {
146
+ id: number | null;
147
+ name: string;
148
+ email: string;
149
+ created_at: Date;
150
+ updated_at: Date;
151
+ }
152
+
153
+ export class Queries {
154
+ constructor(db: any);
155
+
156
+ getUser(id: number): Promise<GetUserResult | null>;
157
+ createUser(name: string, email: string): Promise<Users | null>;
158
+ listUsers(): Promise<Users[]>;
159
+ updateUser(id: number, name: string, email: string): Promise<Users | null>;
160
+ deleteUser(id: number): Promise<void>;
161
+ }
162
+
163
+ export function New(db: any): Queries;
164
+ ```
165
+
166
+ ### 8. Use in Your Code
167
+
168
+ **index.ts**
169
+ ```typescript
170
+ import { Pool } from 'pg';
171
+ import { New } from './flash_gen/database';
172
+
173
+ const DATABASE_URL = process.env.DATABASE_URL || 'postgresql://postgres:postgres@localhost:5432/mydb';
174
+
175
+ async function main() {
176
+ const pool = new Pool({
177
+ connectionString: DATABASE_URL,
178
+ });
179
+
180
+ const db = New(pool);
181
+
182
+ // Create user - fully type-safe!
183
+ const newUser = await db.createUser('Alice', 'alice@example.com');
184
+ console.log('New user:', newUser);
185
+
186
+ // Get user by ID
187
+ const user = await db.getUser(newUser.id);
188
+ console.log('Found user:', user);
189
+
190
+ // List all users
191
+ const users = await db.listUsers();
192
+ console.log('All users:', users);
193
+
194
+ // Update user
195
+ const updated = await db.updateUser(newUser.id, 'Alice Smith', 'alice.smith@example.com');
196
+ console.log('Updated user:', updated);
197
+
198
+ await pool.end();
199
+ }
200
+
201
+ main().catch((err) => {
202
+ console.error('Error:', err);
203
+ process.exit(1);
204
+ });
205
+ ```
206
+
207
+ ## 📋 All Commands
208
+
209
+ ### Visual Database Editor
210
+
211
+ ```bash
212
+ # Launch FlashORM Studio (web-based database editor)
213
+ flash studio
214
+
215
+ # Launch on custom port
216
+ flash studio --port 3000
217
+
218
+ # Connect to any database directly
219
+ flash studio --db "postgresql://user:pass@localhost:5432/mydb"
220
+
221
+ # Launch without opening browser
222
+ flash studio --browser=false
223
+ ```
224
+
225
+ **Studio Features:**
226
+ - 📊 **Data Browser**: View and edit table data with inline editing
227
+ - 💻 **SQL Editor**: Execute queries with CodeMirror syntax highlighting
228
+ - 🎨 **Schema Visualization**: Interactive database diagram with React + ReactFlow
229
+ - 📤 **CSV Export**: Export query results to CSV
230
+ - 🔍 **Search & Filter**: Search across all tables
231
+ - ⚡ **Real-time Updates**: See changes immediately
232
+
233
+ ### Project Setup
234
+
235
+ ```bash
236
+ # Initialize new project
237
+ flash init --postgresql
238
+ flash init --mysql
239
+ flash init --sqlite
240
+ ```
241
+
242
+ ### Migrations
243
+
244
+ ```bash
245
+ # Create new migration
246
+ flash migrate "migration name"
247
+
248
+ # Create empty migration
249
+ flash migrate "custom migration" --empty
250
+
251
+ # Apply all pending migrations
252
+ flash apply
253
+
254
+ # Apply with force (skip confirmations)
255
+ flash apply --force
256
+
257
+ # Check migration status
258
+ flash status
259
+ ```
260
+
261
+ ### Code Generation
262
+
263
+ ```bash
264
+ # Generate type-safe code
265
+ flash gen
266
+ ```
267
+
268
+ ### Schema Management
269
+
270
+ ```bash
271
+ # Pull schema from existing database
272
+ flash pull
273
+
274
+ # Pull with backup
275
+ flash pull --backup
276
+
277
+ # Pull to custom file
278
+ flash pull --output custom-schema.sql
279
+ ```
280
+
281
+ ### Database Export
282
+
283
+ ```bash
284
+ # Export as JSON (default)
285
+ flash export
286
+ flash export --json
287
+
288
+ # Export as CSV
289
+ flash export --csv
290
+
291
+ # Export as SQLite
292
+ flash export --sqlite
293
+ ```
294
+
295
+ ### Database Operations
296
+
297
+ ```bash
298
+ # Reset database (destructive!)
299
+ flash reset
300
+
301
+ # Reset with force
302
+ flash reset --force
303
+
304
+ # Execute raw SQL file
305
+ flash raw script.sql
306
+ flash raw migrations/seed.sql
307
+
308
+ # Execute inline SQL query
309
+ flash raw -q "SELECT * FROM users WHERE active = true"
310
+ flash raw "SELECT COUNT(*) FROM orders"
311
+
312
+ # Force file mode
313
+ flash raw --file queries/complex.sql
314
+ ```
315
+
316
+ ### Help & Info
317
+
318
+ ```bash
319
+ # Launch FlashORM Studio
320
+ flash studio
321
+
322
+ # Show version
323
+ flash --version
324
+ flash -v
325
+
326
+ # Show help
327
+ flash --help
328
+ flash <command> --help
329
+ ```
330
+
331
+ ## ⚙️ Configuration
332
+
333
+ **flash.config.json**
334
+ ```json
335
+ {
336
+ "version": "2",
337
+ "schema_path": "db/schema/schema.sql",
338
+ "queries": "db/queries/",
339
+ "migrations_path": "db/migrations",
340
+ "export_path": "db/export",
341
+ "database": {
342
+ "provider": "postgresql",
343
+ "url_env": "DATABASE_URL"
344
+ },
345
+ "gen": {
346
+ "js": {
347
+ "enabled": true,
348
+ }
349
+ }
350
+ }
351
+ ```
352
+
353
+ ## 🎨 PostgreSQL ENUM Support
354
+
355
+ **Schema with ENUMs**
356
+ ```sql
357
+ CREATE TYPE user_role AS ENUM ('admin', 'user', 'guest');
358
+
359
+ CREATE TABLE users (
360
+ id SERIAL PRIMARY KEY,
361
+ name VARCHAR(255) NOT NULL,
362
+ role user_role NOT NULL DEFAULT 'user'
363
+ );
364
+ ```
365
+
366
+ **Query with ENUM**
367
+ ```sql
368
+ -- name: GetUsersByRole :many
369
+ SELECT id, name, role FROM users
370
+ WHERE role = $1;
371
+ ```
372
+
373
+ **Generated TypeScript**
374
+ ```typescript
375
+ export type UserRole = 'admin' | 'user' | 'guest';
376
+
377
+ export interface Users {
378
+ id: number | null;
379
+ name: string;
380
+ role: UserRole;
381
+ }
382
+ ```
383
+
384
+ ## 🔒 Safe Migrations
385
+
386
+ Every migration runs in a transaction with automatic rollback on failure:
387
+
388
+ ```bash
389
+ $ flash apply
390
+ 📦 Applying 2 migration(s)...
391
+ [1/2] 20251103_create_users
392
+ ✅ Applied
393
+ [2/2] 20251103_add_email_index
394
+ ✅ Applied
395
+ ✅ All migrations applied successfully
396
+ ```
397
+
398
+ If a migration fails:
399
+ ```bash
400
+ ❌ Failed at migration: 20251103_bad_migration
401
+ Error: syntax error at or near "INVALID"
402
+ Transaction rolled back. Fix the error and run 'flash apply' again.
403
+ ```
404
+
405
+ ## 🛡️ Conflict Detection
406
+
407
+ FlashORM automatically detects schema conflicts:
408
+
409
+ ```bash
410
+ ⚠️ Migration conflicts detected:
411
+ - Table 'users' already exists
412
+ - Column 'email' conflicts with existing column
413
+
414
+ Reset database to resolve conflicts? (y/n): y
415
+ Create export before applying? (y/n): y
416
+ 📦 Creating export...
417
+ ✅ Export created successfully
418
+ 🔄 Resetting database and applying all migrations...
419
+ ```
420
+
421
+ ## 📤 Export Formats
422
+
423
+ ### JSON Export
424
+ ```bash
425
+ flash export --json
426
+ ```
427
+ ```json
428
+ {
429
+ "timestamp": "2025-11-03 16:30:00",
430
+ "version": "1.0",
431
+ "tables": {
432
+ "users": [
433
+ {"id": 1, "name": "Alice", "email": "alice@example.com"}
434
+ ]
435
+ }
436
+ }
437
+ ```
438
+
439
+ ### CSV Export
440
+ ```bash
441
+ flash export --csv
442
+ ```
443
+ Creates directory with individual CSV files per table.
444
+
445
+ ### SQLite Export
446
+ ```bash
447
+ flash export --sqlite
448
+ ```
449
+ Creates portable `.db` file.
450
+
451
+ ## 🎨 FlashORM Studio
452
+
453
+ Launch the visual database editor:
454
+
455
+ ```bash
456
+ flash studio
457
+ ```
458
+
459
+ Open http://localhost:5555 (or your custom port)
460
+
461
+ **Features:**
462
+
463
+ ### 1. Data Browser (`/`)
464
+ - View all tables in sidebar
465
+ - Click any table to view/edit data
466
+ - Double-click cells for inline editing
467
+ - Add/delete rows with intuitive modals
468
+ - Pagination (50 rows per page)
469
+ - Search across tables
470
+ - Foreign key hints
471
+
472
+ ### 2. SQL Editor (`/sql`)
473
+ - Execute custom SQL queries
474
+ - CodeMirror editor with syntax highlighting
475
+ - Press Ctrl+Enter to run queries
476
+ - Export results to CSV
477
+ - Resizable split-pane interface
478
+ - Query history
479
+
480
+ ### 3. Schema Visualization (`/schema`)
481
+ - Interactive database diagram
482
+ - React + ReactFlow rendering
483
+ - Automatic layout with Dagre algorithm
484
+ - Drag and drop tables
485
+ - Zoom and pan controls
486
+ - Foreign key relationship arrows
487
+ - MiniMap for navigation
488
+
489
+ **Tech Stack:**
490
+ - Backend: Go Fiber v2.52.9
491
+ - Frontend: React 18.2.0, ReactFlow 12.8.4, CodeMirror 5.65.2
492
+ - All assets embedded in single binary
493
+
494
+ ## 💻 Raw SQL Execution
495
+
496
+ Execute SQL files or inline queries:
497
+
498
+ ```bash
499
+ # Execute SQL file
500
+ flash raw script.sql
501
+
502
+ # Execute inline query
503
+ flash raw -q "SELECT * FROM users LIMIT 10"
504
+
505
+ # Auto-detection (file if exists, otherwise query)
506
+ flash raw "SELECT COUNT(*) FROM orders"
507
+ ```
508
+
509
+ **Features:**
510
+ - ✅ Beautiful table output for SELECT queries
511
+ - ✅ Multi-statement execution
512
+ - ✅ Transaction support
513
+ - ✅ Auto-detection of file vs query
514
+ - ✅ Formatted error messages
515
+
516
+ **Example Output:**
517
+ ```bash
518
+ $ flash raw -q "SELECT id, name, email FROM users LIMIT 3"
519
+
520
+ 🎯 Database: postgresql
521
+
522
+ ⚡ Executing query...
523
+ ✅ Query executed successfully
524
+ 📊 3 row(s) returned
525
+
526
+ ┌────┬────────────┬─────────────────────┐
527
+ │ id │ name │ email │
528
+ ├────┼────────────┼─────────────────────┤
529
+ │ 1 │ Alice │ alice@example.com │
530
+ │ 2 │ Bob │ bob@example.com │
531
+ │ 3 │ Charlie │ charlie@example.com │
532
+ └────┴────────────┴─────────────────────┘
533
+ ```
534
+
535
+ ## 🔧 Programmatic API
536
+
537
+ ```javascript
538
+ const flash = require('flashorm');
539
+
540
+ // Execute commands
541
+ flash.exec('status');
542
+ flash.exec('migrate "add users"');
543
+ flash.exec('apply');
544
+ flash.exec('studio'); // Launch Studio
545
+
546
+ // Get binary path
547
+ const binaryPath = flash.getBinaryPath();
548
+ ```
549
+
550
+ ## 📚 Examples
551
+
552
+ Check out complete examples:
553
+ - [TypeScript Example](https://github.com/Lumos-Labs-HQ/FlashORM/tree/main/example/ts)
554
+ - [Go Example](https://github.com/Lumos-Labs-HQ/FlashORM/tree/main/example/go)
555
+
556
+ ## 🐛 Troubleshooting
557
+
558
+ ### Bun Postinstall Blocked
559
+
560
+ ```bash
561
+ bun pm trust flashorm
562
+ ```
563
+
564
+ ### Binary Not Found
565
+
566
+ ```bash
567
+ npm install -g flashorm --force
568
+ ```
569
+
570
+ ### Database Connection Failed
571
+
572
+ Check your `DATABASE_URL` in `.env` file.
573
+
574
+ ### Studio Not Loading
575
+
576
+ Make sure port 5555 is not in use, or specify a different port:
577
+ ```bash
578
+ flash studio --port 3000
579
+ ```
580
+
581
+ ## 📖 Documentation
582
+
583
+ - [Full Documentation](https://github.com/Lumos-Labs-HQ/FlashORM)
584
+ - [How It Works](https://github.com/Lumos-Labs-HQ/FlashORM/blob/main/docs/HOW_IT_WORKS.md)
585
+ - [Technology Stack](https://github.com/Lumos-Labs-HQ/FlashORM/blob/main/docs/TECHNOLOGY_STACK.md)
586
+ - [Contributing](https://github.com/Lumos-Labs-HQ/FlashORM/blob/main/docs/CONTRIBUTING.md)
587
+
588
+ ## 🌟 Key Highlights
589
+
590
+ - **Visual Database Editor**: Manage your database visually with FlashORM Studio
591
+ - **Raw SQL Support**: Execute SQL files or queries directly from CLI
592
+ - **Type-Safe**: Full TypeScript support with generated types
593
+ - **Fast**: 2.5x-10x faster than popular ORMs
594
+ - **Multi-DB**: PostgreSQL, MySQL, and SQLite support
595
+ - **Zero Config**: Works out of the box with sensible defaults
596
+
597
+ ## 📄 License
598
+
599
+ MIT License - see [LICENSE](https://github.com/Lumos-Labs-HQ/FlashORM/blob/main/LICENSE)
600
+
601
+ ---
package/bin/flash.js ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ const platform = process.platform;
8
+ const binaryName = platform === 'win32' ? 'flash.exe' : 'flash';
9
+ const binaryPath = path.join(__dirname, binaryName);
10
+
11
+ if (!fs.existsSync(binaryPath)) {
12
+ console.error('❌ flash binary not found. Please reinstall: npm install -g FlashORM-orm');
13
+ process.exit(1);
14
+ }
15
+
16
+ const child = spawn(binaryPath, process.argv.slice(2), {
17
+ stdio: 'inherit',
18
+ windowsHide: true
19
+ });
20
+
21
+ child.on('exit', (code) => {
22
+ process.exit(code || 0);
23
+ });
24
+
25
+ child.on('error', (err) => {
26
+ console.error('❌ Failed to start flash:', err);
27
+ process.exit(1);
28
+ });
package/index.js ADDED
@@ -0,0 +1,28 @@
1
+ const { execSync } = require('child_process');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ function getBinaryPath() {
6
+ const platform = process.platform;
7
+ const binaryName = platform === 'win32' ? 'flash.exe' : 'flash';
8
+ const binaryPath = path.join(__dirname, 'bin', binaryName);
9
+
10
+ if (!fs.existsSync(binaryPath)) {
11
+ throw new Error('flash binary not found. Please reinstall: npm install -g FlashORM-orm');
12
+ }
13
+
14
+ return binaryPath;
15
+ }
16
+
17
+ function exec(command, options = {}) {
18
+ const binaryPath = getBinaryPath();
19
+ return execSync(`"${binaryPath}" ${command}`, {
20
+ encoding: 'utf8',
21
+ ...options
22
+ });
23
+ }
24
+
25
+ module.exports = {
26
+ getBinaryPath,
27
+ exec
28
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "flashorm",
3
+ "version": "1.0.1",
4
+ "description": "A powerful, database-agnostic migration CLI tool with multi-database support and type-safe code generation",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "flash": "./bin/flash.js"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node scripts/install.js"
11
+ },
12
+ "keywords": [
13
+ "orm",
14
+ "database",
15
+ "migration",
16
+ "sqlc",
17
+ "postgresql",
18
+ "mysql",
19
+ "sqlite",
20
+ "cli",
21
+ "typescript",
22
+ "javascript",
23
+ "type-safe"
24
+ ],
25
+ "author": "Rana718",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/Lumos-Labs-HQ/FlashORM.git"
30
+ },
31
+ "homepage": "https://github.com/Lumos-Labs-HQ/FlashORM#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/Lumos-Labs-HQ/FlashORM/issues"
34
+ },
35
+ "engines": {
36
+ "node": ">=14.0.0"
37
+ },
38
+ "os": [
39
+ "darwin",
40
+ "linux",
41
+ "win32"
42
+ ],
43
+ "cpu": [
44
+ "x64",
45
+ "arm64"
46
+ ],
47
+ "files": [
48
+ "bin/",
49
+ "scripts/",
50
+ "index.js",
51
+ "README.md"
52
+ ]
53
+ }
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+
3
+ const https = require('https');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ const VERSION = '1.0.1';
8
+ const REPO = 'Lumos-Labs-HQ/FlashORM';
9
+
10
+ const platform = process.platform;
11
+ const arch = process.arch;
12
+
13
+ const platformMap = {
14
+ 'darwin': 'darwin',
15
+ 'linux': 'linux',
16
+ 'win32': 'windows'
17
+ };
18
+
19
+ const archMap = {
20
+ 'x64': 'amd64',
21
+ 'arm64': 'arm64'
22
+ };
23
+
24
+ const mappedPlatform = platformMap[platform];
25
+ const mappedArch = archMap[arch];
26
+
27
+ if (!mappedPlatform || !mappedArch) {
28
+ console.error(`❌ Unsupported platform: ${platform}-${arch}`);
29
+ process.exit(1);
30
+ }
31
+
32
+ const binaryName = platform === 'win32' ? 'flash.exe' : 'flash';
33
+ const downloadName = `flash-${mappedPlatform}-${mappedArch}${platform === 'win32' ? '.exe' : ''}`;
34
+ const downloadUrl = `https://github.com/${REPO}/releases/download/v${VERSION}/${downloadName}`;
35
+
36
+ const binDir = path.join(__dirname, '..', 'bin');
37
+ const binaryPath = path.join(binDir, binaryName);
38
+
39
+ console.log(`📦 Installing flash v${VERSION} for ${platform}-${arch}...`);
40
+ console.log(`📥 Downloading from: ${downloadUrl}`);
41
+
42
+ if (!fs.existsSync(binDir)) {
43
+ fs.mkdirSync(binDir, { recursive: true });
44
+ }
45
+
46
+ const file = fs.createWriteStream(binaryPath);
47
+
48
+ https.get(downloadUrl, (response) => {
49
+ if (response.statusCode === 302 || response.statusCode === 301) {
50
+ https.get(response.headers.location, (redirectResponse) => {
51
+ redirectResponse.pipe(file);
52
+ file.on('finish', () => {
53
+ file.close(() => {
54
+ fs.chmodSync(binaryPath, 0o755);
55
+ console.log(`✅ flash installed successfully!`);
56
+ console.log(`🚀 Run 'flash --help' to get started!`);
57
+ });
58
+ });
59
+ });
60
+ } else {
61
+ response.pipe(file);
62
+ file.on('finish', () => {
63
+ file.close(() => {
64
+ fs.chmodSync(binaryPath, 0o755);
65
+ console.log(`✅ flash installed successfully!`);
66
+ console.log(`🚀 Run 'flash --help' to get started!`);
67
+ });
68
+ });
69
+ }
70
+ }).on('error', (err) => {
71
+ fs.unlinkSync(binaryPath);
72
+ console.error(`❌ Download failed: ${err.message}`);
73
+ console.error(`Please check: ${downloadUrl}`);
74
+ process.exit(1);
75
+ });