@gallop.software/studio 2.0.7 → 2.1.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/bin/studio.mjs CHANGED
@@ -1,23 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { spawn } from 'child_process'
4
- import { resolve, dirname, join } from 'path'
5
- import { fileURLToPath } from 'url'
6
- import { existsSync, mkdirSync, cpSync, writeFileSync, rmSync } from 'fs'
7
- import { tmpdir } from 'os'
8
-
9
- const __filename = fileURLToPath(import.meta.url)
10
- const __dirname = dirname(__filename)
3
+ import { resolve } from 'path'
4
+ import { existsSync } from 'fs'
11
5
 
12
6
  // Parse command line arguments
13
7
  const args = process.argv.slice(2)
14
8
  let workspace = process.cwd()
9
+ let port = 3001
15
10
  let shouldOpen = false
16
11
 
17
12
  for (let i = 0; i < args.length; i++) {
18
13
  if (args[i] === '--workspace' && args[i + 1]) {
19
14
  workspace = resolve(args[i + 1])
20
15
  i++
16
+ } else if (args[i] === '--port' && args[i + 1]) {
17
+ port = parseInt(args[i + 1], 10)
18
+ i++
21
19
  } else if (args[i] === '--open' || args[i] === '-o') {
22
20
  shouldOpen = true
23
21
  } else if (args[i] === '--help' || args[i] === '-h') {
@@ -29,13 +27,14 @@ Usage:
29
27
 
30
28
  Options:
31
29
  --workspace <path> Path to the project workspace (default: current directory)
30
+ --port <number> Port to run the server on (default: 3001)
32
31
  --open, -o Open browser automatically
33
32
  --help, -h Show this help message
34
33
 
35
34
  Examples:
36
35
  studio # Run in current directory
37
36
  studio --workspace ~/my-project # Run for specific project
38
- studio --workspace . --open # Open browser automatically
37
+ studio --port 3002 --open # Use custom port and open browser
39
38
  `)
40
39
  process.exit(0)
41
40
  }
@@ -55,120 +54,14 @@ if (!existsSync(publicPath)) {
55
54
  process.exit(1)
56
55
  }
57
56
 
58
- console.log(`
59
- ┌─────────────────────────────────────┐
60
- Studio - Media Manager │
61
- ├─────────────────────────────────────┤
62
- │ Workspace: ${workspace.length > 24 ? '...' + workspace.slice(-21) : workspace.padEnd(24)}│
63
- │ URL: http://localhost:3001 │
64
- └─────────────────────────────────────┘
65
- `)
66
-
67
- // Create a temp directory for the Studio app
68
- const studioRoot = resolve(__dirname, '..')
69
- const tempDir = join(tmpdir(), 'gallop-studio')
70
-
71
- // Clean up and recreate temp directory
72
- if (existsSync(tempDir)) {
73
- rmSync(tempDir, { recursive: true, force: true })
74
- }
75
- mkdirSync(tempDir, { recursive: true })
76
-
77
- // Copy app files to temp directory
78
- cpSync(join(studioRoot, 'app'), join(tempDir, 'app'), { recursive: true })
79
- cpSync(join(studioRoot, 'dist'), join(tempDir, 'dist'), { recursive: true })
80
-
81
- // Create package.json for the temp app
82
- const packageJson = {
83
- name: 'studio-temp',
84
- private: true,
85
- type: 'module',
86
- dependencies: {}
87
- }
88
- writeFileSync(join(tempDir, 'package.json'), JSON.stringify(packageJson, null, 2))
89
-
90
- // Create next.config.mjs
91
- const nextConfig = `/** @type {import('next').NextConfig} */
92
- const nextConfig = {
93
- output: 'standalone',
94
- compiler: {
95
- emotion: true,
96
- },
97
- env: {
98
- NEXT_PUBLIC_STUDIO_WORKSPACE: process.env.STUDIO_WORKSPACE || process.cwd(),
99
- },
100
- }
101
-
102
- export default nextConfig
103
- `
104
- writeFileSync(join(tempDir, 'next.config.mjs'), nextConfig)
105
-
106
- // Create symlinks to node_modules from studioRoot
107
- const nodeModulesSource = join(studioRoot, 'node_modules')
108
- const nodeModulesTarget = join(tempDir, 'node_modules')
109
-
110
- try {
111
- // Use cpSync with dereference to copy node_modules (or symlink if possible)
112
- // For performance, we'll just create a symlink
113
- const { symlinkSync } = await import('fs')
114
- symlinkSync(nodeModulesSource, nodeModulesTarget, 'junction')
115
- } catch (e) {
116
- // If symlink fails, copy (slower but works)
117
- console.log('Creating node_modules link...')
118
- cpSync(nodeModulesSource, nodeModulesTarget, { recursive: true })
119
- }
120
-
121
- // Find the next binary
122
- const nextBin = join(nodeModulesTarget, '.bin', 'next')
123
-
124
- if (!existsSync(nextBin)) {
125
- 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)
126
66
  process.exit(1)
127
- }
128
-
129
- // Set up environment
130
- const env = {
131
- ...process.env,
132
- STUDIO_WORKSPACE: workspace,
133
- NODE_ENV: 'development',
134
- }
135
-
136
- // Start Next.js dev server from temp directory
137
- const child = spawn(nextBin, ['dev', '-p', '3001'], {
138
- stdio: 'inherit',
139
- cwd: tempDir,
140
- env,
141
- })
142
-
143
- // Open browser if requested
144
- if (shouldOpen) {
145
- setTimeout(async () => {
146
- const open = (await import('open')).default
147
- open('http://localhost:3001')
148
- }, 2000)
149
- }
150
-
151
- // Handle process termination
152
- const cleanup = () => {
153
- child.kill('SIGINT')
154
- // Clean up temp directory
155
- try {
156
- rmSync(tempDir, { recursive: true, force: true })
157
- } catch (e) {
158
- // Ignore cleanup errors
159
- }
160
- process.exit(0)
161
- }
162
-
163
- process.on('SIGINT', cleanup)
164
- process.on('SIGTERM', cleanup)
165
-
166
- child.on('close', (code) => {
167
- // Clean up temp directory
168
- try {
169
- rmSync(tempDir, { recursive: true, force: true })
170
- } catch (e) {
171
- // Ignore cleanup errors
172
- }
173
- process.exit(code || 0)
174
67
  })