@gallop.software/studio 2.0.6 → 2.1.0

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/bin/studio.mjs CHANGED
@@ -1,22 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { spawn } from 'child_process'
4
- import { resolve, dirname } from 'path'
5
- import { fileURLToPath } from 'url'
3
+ import { resolve } from 'path'
6
4
  import { existsSync } from 'fs'
7
5
 
8
- const __filename = fileURLToPath(import.meta.url)
9
- const __dirname = dirname(__filename)
10
-
11
6
  // Parse command line arguments
12
7
  const args = process.argv.slice(2)
13
8
  let workspace = process.cwd()
9
+ let port = 3001
14
10
  let shouldOpen = false
15
11
 
16
12
  for (let i = 0; i < args.length; i++) {
17
13
  if (args[i] === '--workspace' && args[i + 1]) {
18
14
  workspace = resolve(args[i + 1])
19
15
  i++
16
+ } else if (args[i] === '--port' && args[i + 1]) {
17
+ port = parseInt(args[i + 1], 10)
18
+ i++
20
19
  } else if (args[i] === '--open' || args[i] === '-o') {
21
20
  shouldOpen = true
22
21
  } else if (args[i] === '--help' || args[i] === '-h') {
@@ -28,13 +27,14 @@ Usage:
28
27
 
29
28
  Options:
30
29
  --workspace <path> Path to the project workspace (default: current directory)
30
+ --port <number> Port to run the server on (default: 3001)
31
31
  --open, -o Open browser automatically
32
32
  --help, -h Show this help message
33
33
 
34
34
  Examples:
35
35
  studio # Run in current directory
36
36
  studio --workspace ~/my-project # Run for specific project
37
- studio --workspace . --open # Open browser automatically
37
+ studio --port 3002 --open # Use custom port and open browser
38
38
  `)
39
39
  process.exit(0)
40
40
  }
@@ -54,57 +54,14 @@ if (!existsSync(publicPath)) {
54
54
  process.exit(1)
55
55
  }
56
56
 
57
- console.log(`
58
- ┌─────────────────────────────────────┐
59
- Studio - Media Manager │
60
- ├─────────────────────────────────────┤
61
- │ Workspace: ${workspace.length > 24 ? '...' + workspace.slice(-21) : workspace.padEnd(24)}│
62
- │ URL: http://localhost:3001 │
63
- └─────────────────────────────────────┘
64
- `)
65
-
66
- // Find the next binary
67
- const studioRoot = resolve(__dirname, '..')
68
- const nextBin = resolve(studioRoot, 'node_modules', '.bin', 'next')
69
-
70
- if (!existsSync(nextBin)) {
71
- console.error('Error: Next.js not found. Please run: npm install')
57
+ // Start the server
58
+ import('../dist/server/index.js').then((mod) => {
59
+ mod.startServer({
60
+ port,
61
+ workspace,
62
+ open: shouldOpen,
63
+ })
64
+ }).catch((error) => {
65
+ console.error('Failed to start Studio server:', error)
72
66
  process.exit(1)
73
- }
74
-
75
- // Set up environment
76
- const env = {
77
- ...process.env,
78
- STUDIO_WORKSPACE: workspace,
79
- NODE_ENV: 'development',
80
- }
81
-
82
- // Start Next.js dev server
83
- const child = spawn(nextBin, ['dev', '-p', '3001'], {
84
- stdio: 'inherit',
85
- cwd: studioRoot,
86
- env,
87
- })
88
-
89
- // Open browser if requested
90
- if (shouldOpen) {
91
- setTimeout(async () => {
92
- const open = (await import('open')).default
93
- open('http://localhost:3001')
94
- }, 2000)
95
- }
96
-
97
- // Handle process termination
98
- process.on('SIGINT', () => {
99
- child.kill('SIGINT')
100
- process.exit(0)
101
- })
102
-
103
- process.on('SIGTERM', () => {
104
- child.kill('SIGTERM')
105
- process.exit(0)
106
- })
107
-
108
- child.on('close', (code) => {
109
- process.exit(code || 0)
110
67
  })