spine-framework 0.3.26 → 0.3.28

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,16 +1,68 @@
1
1
  #!/usr/bin/env node
2
- import { createRequire } from 'module'
3
- import { fileURLToPath } from 'url'
4
- import { dirname, resolve } from 'path'
5
- import { spawnSync } from 'child_process'
2
+ // Thin shebang wrapper — invokes the TypeScript CLI via tsx.
3
+ // This file is the npm bin entry point for spine-framework.
4
+ const { execFileSync } = require('child_process')
5
+ const { resolve } = require('path')
6
+ const fs = require('fs')
6
7
 
7
- const __dirname = dirname(fileURLToPath(import.meta.url))
8
- const tsEntry = resolve(__dirname, 'index.ts')
8
+ const pkgRoot = resolve(__dirname, '..')
9
+ const projectRoot = resolve(pkgRoot, '../..')
9
10
 
10
- // Find tsx relative to this package or globally
11
- const result = spawnSync('npx', ['--yes', 'tsx', tsEntry, ...process.argv.slice(2)], {
12
- stdio: 'inherit',
13
- shell: true,
14
- })
11
+ // Handle no-args case — show welcome before spawning tsx
12
+ if (process.argv.length === 2) {
13
+ console.log('\nSpine Framework CLI')
14
+ console.log('Usage: spine-framework <command>\n')
15
+ console.log('Commands:')
16
+ console.log(' init Scaffold a new Spine Framework project')
17
+ console.log(' migrate Apply database migrations')
18
+ console.log(' install-app Install a Spine Framework app from npm')
19
+ console.log(' status Show installed apps and framework version')
20
+ console.log('\nRun spine-framework --help for full command list\n')
21
+ process.exit(0)
22
+ }
15
23
 
16
- process.exit(result.status ?? 0)
24
+ // Pre-load .env from the consumer project root so db.ts sees env vars at module load time.
25
+ // tsx evaluates imports before Commander parses args, so we must inject here.
26
+ const args = process.argv.slice(2)
27
+ const childEnv = { ...process.env }
28
+
29
+ const dotenvPath = resolve(process.cwd(), '.env')
30
+ if (fs.existsSync(dotenvPath)) {
31
+ const lines = fs.readFileSync(dotenvPath, 'utf8').split('\n')
32
+ for (const line of lines) {
33
+ const trimmed = line.trim()
34
+ if (!trimmed || trimmed.startsWith('#')) continue
35
+ const eq = trimmed.indexOf('=')
36
+ if (eq === -1) continue
37
+ const key = trimmed.slice(0, eq).trim()
38
+ const val = trimmed.slice(eq + 1).trim()
39
+ if (key && !(key in childEnv)) childEnv[key] = val
40
+ }
41
+ }
42
+
43
+ // CLI flags override .env values
44
+ for (let i = 0; i < args.length; i++) {
45
+ if (args[i] === '--url' && args[i + 1]) childEnv.SUPABASE_URL = args[++i]
46
+ if (args[i] === '--anon-key' && args[i + 1]) childEnv.SUPABASE_ANON_KEY = args[++i]
47
+ if (args[i] === '--service-role-key' && args[i + 1]) childEnv.SUPABASE_SERVICE_ROLE_KEY = args[++i]
48
+ }
49
+
50
+ const entry = resolve(pkgRoot, 'bin/ws-shim.ts')
51
+
52
+ // Find tsx: prefer consuming project's copy, fall back to our own
53
+ const tsxPaths = [
54
+ resolve(projectRoot, 'node_modules/.bin/tsx'),
55
+ resolve(pkgRoot, 'node_modules/.bin/tsx'),
56
+ ]
57
+ const tsx = tsxPaths.find(p => { try { fs.accessSync(p); return true } catch { return false } })
58
+
59
+ if (!tsx) {
60
+ console.error('spine-framework: tsx not found. Run: npm install tsx')
61
+ process.exit(1)
62
+ }
63
+
64
+ try {
65
+ execFileSync(tsx, [entry, ...process.argv.slice(2)], { stdio: 'inherit', env: childEnv })
66
+ } catch (e) {
67
+ process.exit(e.status ?? 1)
68
+ }
package/bin/ws-shim.ts ADDED
@@ -0,0 +1,10 @@
1
+ // Entry point for the CLI on Node < 22.
2
+ // Sets globalThis.WebSocket before any supabase-js module is imported,
3
+ // preventing the "Node.js 20 detected without native WebSocket" crash.
4
+ import { WebSocket } from 'ws'
5
+ if (typeof globalThis.WebSocket === 'undefined') {
6
+ ;(globalThis as any).WebSocket = WebSocket
7
+ }
8
+
9
+ // Now import the real CLI — all supabase createClient() calls happen after this point
10
+ import('../.framework/cli/index.ts')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spine-framework",
3
- "version": "0.3.26",
3
+ "version": "0.3.28",
4
4
  "description": "Multi-tenant, modular application platform for modern SaaS systems",
5
5
  "bin": {
6
6
  "spine-framework": "bin/spine-framework.js"