@shumai-one/shumai-transcode 0.0.4 → 0.0.6

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.
@@ -2,7 +2,7 @@
2
2
  import { spawn } from 'node:child_process'
3
3
  import { join, dirname } from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
- import { existsSync } from 'node:fs'
5
+ import { existsSync, readFileSync } from 'node:fs'
6
6
 
7
7
  const __dirname = dirname(fileURLToPath(import.meta.url))
8
8
  const platform = process.platform
@@ -54,19 +54,106 @@ if (!binaryPath) {
54
54
 
55
55
  const appJsPath = join(__dirname, 'shumai-transcode-app.js')
56
56
 
57
- const child = spawn(binaryPath, ['run', appJsPath, ...process.argv.slice(2)], {
58
- stdio: 'inherit',
59
- env: {
60
- ...process.env,
61
- BUN_BE_BUN: '1',
62
- },
63
- })
57
+ let activeProcess = null
64
58
 
65
- child.on('close', (code) => {
66
- process.exit(code ?? 0)
67
- })
59
+ function startApp() {
60
+ activeProcess = spawn(binaryPath, ['run', appJsPath, ...process.argv.slice(2)], {
61
+ stdio: 'inherit',
62
+ env: {
63
+ ...process.env,
64
+ BUN_BE_BUN: '1',
65
+ },
66
+ })
67
+
68
+ activeProcess.on('close', (code) => {
69
+ process.exit(code ?? 0)
70
+ })
71
+
72
+ activeProcess.on('error', (err) => {
73
+ console.error(`Failed to start child process:`, err)
74
+ process.exit(1)
75
+ })
76
+ }
77
+
78
+ // Simple .env parser to load env files from process.cwd()
79
+ function loadEnv() {
80
+ const envFiles = ['.env.production.local', '.env.local', '.env.production', '.env']
81
+ for (const file of envFiles) {
82
+ const envPath = join(process.cwd(), file)
83
+ if (existsSync(envPath)) {
84
+ try {
85
+ const content = readFileSync(envPath, 'utf8')
86
+ const lines = content.split(/\r?\n/)
87
+ for (const line of lines) {
88
+ const trimmed = line.trim()
89
+ if (!trimmed || trimmed.startsWith('#')) continue
90
+ const match = trimmed.match(/^([^=]+)=(.*)$/)
91
+ if (match) {
92
+ const key = match[1].trim()
93
+ let value = match[2].trim()
94
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
95
+ value = value.substring(1, value.length - 1)
96
+ }
97
+ if (process.env[key] === undefined) {
98
+ process.env[key] = value
99
+ }
100
+ }
101
+ }
102
+ } catch (err) {
103
+ console.error('⚠️ [shumai] Error reading env file:', err)
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ // Load env files on startup
110
+ loadEnv()
111
+
112
+ console.log(`ℹ️ [shumai-transcode] Running from CWD: ${process.cwd()}`)
113
+ console.log(`ℹ️ [shumai-transcode] DATABASE_URL is: ${process.env.DATABASE_URL ? '(defined)' : '(undefined)'}`)
114
+
115
+ const prismaSchemaPath = join(__dirname, '..', 'prisma', 'schema.prisma')
116
+ if (existsSync(prismaSchemaPath)) {
117
+ console.log('🔄 Running database migrations...')
118
+ activeProcess = spawn(
119
+ binaryPath,
120
+ ['run', 'prisma', 'migrate', 'deploy', '--schema', './prisma/schema.prisma'],
121
+ {
122
+ stdio: 'inherit',
123
+ cwd: join(__dirname, '..'),
124
+ env: {
125
+ ...process.env,
126
+ BUN_BE_BUN: '1',
127
+ },
128
+ }
129
+ )
130
+
131
+ activeProcess.on('close', (code) => {
132
+ if (code !== 0) {
133
+ console.error(`❌ Database migration failed with code ${code}. Exiting.`)
134
+ process.exit(code ?? 1)
135
+ }
136
+ startApp()
137
+ })
138
+
139
+ activeProcess.on('error', (err) => {
140
+ console.error('❌ Failed to run database migrations:', err)
141
+ process.exit(1)
142
+ })
143
+ } else {
144
+ startApp()
145
+ }
146
+
147
+ // Forward kill signals to the active child process
148
+ const cleanupAndExit = (signal) => {
149
+ if (activeProcess && !activeProcess.killed) {
150
+ activeProcess.kill(signal)
151
+ } else {
152
+ process.exit(0)
153
+ }
154
+ }
155
+
156
+ process.on('SIGINT', () => cleanupAndExit('SIGINT'))
157
+ process.on('SIGTERM', () => cleanupAndExit('SIGTERM'))
158
+ process.on('SIGQUIT', () => cleanupAndExit('SIGQUIT'))
68
159
 
69
- child.on('error', (err) => {
70
- console.error(`Failed to start child process:`, err)
71
- process.exit(1)
72
- })
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@shumai-one/shumai-transcode",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Media transcoding worker for the shumai media workspace",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "shumai-transcode": "./bin/shumai-transcode.js"
8
8
  },
9
9
  "files": [
10
- "bin"
10
+ "bin",
11
+ "prisma",
12
+ "prisma.config.ts"
11
13
  ],
12
14
  "dependencies": {
13
15
  "@prisma/client": "7.8.0",
@@ -23,12 +25,12 @@
23
25
  "prisma": "7.8.0"
24
26
  },
25
27
  "optionalDependencies": {
26
- "@shumai-one/shumai-transcode-darwin-arm64": "0.0.4",
27
- "@shumai-one/shumai-transcode-darwin-x64": "0.0.4",
28
- "@shumai-one/shumai-transcode-linux-arm64": "0.0.4",
29
- "@shumai-one/shumai-transcode-linux-x64": "0.0.4",
30
- "@shumai-one/shumai-transcode-win32-arm64": "0.0.4",
31
- "@shumai-one/shumai-transcode-win32-x64": "0.0.4"
28
+ "@shumai-one/shumai-transcode-darwin-arm64": "0.0.6",
29
+ "@shumai-one/shumai-transcode-darwin-x64": "0.0.6",
30
+ "@shumai-one/shumai-transcode-linux-arm64": "0.0.6",
31
+ "@shumai-one/shumai-transcode-linux-x64": "0.0.6",
32
+ "@shumai-one/shumai-transcode-win32-arm64": "0.0.6",
33
+ "@shumai-one/shumai-transcode-win32-x64": "0.0.6"
32
34
  },
33
35
  "repository": {
34
36
  "type": "git",