Compare commits

...
4 Commits
Author SHA1 Message Date
yiling 02b009fbe1 Release v0.0.5 2026-06-13 10:32:59 +08:00
Yiling-J 6dcd08ae3a Merge pull request #101 from shumaiOne/feat/npm-auto-migration
feat(npm): auto deploy database migrations on package start
2026-06-13 10:27:11 +08:00
yiling d230a1fd4a feat(npm): add dotenv loading and fix variable interpolation in wrapper 2026-06-13 10:21:36 +08:00
yiling 210ed5f95a feat(npm): auto deploy database migrations on package start 2026-06-13 09:24:54 +08:00
14 changed files with 119 additions and 36 deletions
-3
View File
@@ -46,6 +46,3 @@ jobs:
- name: Test Local Release - name: Test Local Release
run: | run: |
bun run release:local --skip-check --out /tmp/shumai-local-release --force bun run release:local --skip-check --out /tmp/shumai-local-release --force
cd /tmp/shumai-local-release/node
npx shumai-agent
npx shumai-transcode
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/agent-app", "name": "@shumai/agent-app",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"bin": { "bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/transcode-app", "name": "@shumai/transcode-app",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"bin": { "bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/web-app", "name": "@shumai/web-app",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"dependencies": { "dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "shumai", "name": "shumai",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"repository": { "repository": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/agent", "name": "@shumai/agent",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/api", "name": "@shumai/api",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/core", "name": "@shumai/core",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/db", "name": "@shumai/db",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/dtos", "name": "@shumai/dtos",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/transcode", "name": "@shumai/transcode",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/webui", "name": "@shumai/webui",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./index.html", "main": "./index.html",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/workflow-core", "name": "@shumai/workflow-core",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+107 -21
View File
@@ -1,7 +1,7 @@
import { rm, mkdir, cp, writeFile, readdir } from 'node:fs/promises'
import { existsSync } from 'node:fs'
import path from 'node:path'
import tailwindPlugin from 'bun-plugin-tailwind' import tailwindPlugin from 'bun-plugin-tailwind'
import { existsSync } from 'node:fs'
import { cp, mkdir, readdir, rm, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { temporalWorkflow } from '../packages/workflow-core/src/bun-temporal-plugin' import { temporalWorkflow } from '../packages/workflow-core/src/bun-temporal-plugin'
console.log('\n🚀 Starting NPM packaging build process for all applications...\n') console.log('\n🚀 Starting NPM packaging build process for all applications...\n')
@@ -234,7 +234,7 @@ async function buildMainPackage({
import { spawn } from 'node:child_process' import { spawn } from 'node:child_process'
import { join, dirname } from 'node:path' import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { existsSync } from 'node:fs' import { existsSync, readFileSync } from 'node:fs'
const __dirname = dirname(fileURLToPath(import.meta.url)) const __dirname = dirname(fileURLToPath(import.meta.url))
const platform = process.platform const platform = process.platform
@@ -286,22 +286,93 @@ if (!binaryPath) {
const appJsPath = join(__dirname, '${appName}-app.js') const appJsPath = join(__dirname, '${appName}-app.js')
const child = spawn(binaryPath, ['run', appJsPath, ...process.argv.slice(2)], { function startApp() {
stdio: 'inherit', const child = spawn(binaryPath, ['run', appJsPath, ...process.argv.slice(2)], {
env: { stdio: 'inherit',
...process.env, env: {
BUN_BE_BUN: '1', ...process.env,
}, BUN_BE_BUN: '1',
}) },
})
child.on('close', (code) => { child.on('close', (code) => {
process.exit(code ?? 0) process.exit(code ?? 0)
}) })
child.on('error', (err) => { child.on('error', (err) => {
console.error(\`Failed to start child process:\`, err) console.error(\`Failed to start child process:\`, err)
process.exit(1) process.exit(1)
}) })
}
// Simple .env parser to load env files from process.cwd()
function loadEnv() {
const envFiles = ['.env.production.local', '.env.local', '.env.production', '.env']
for (const file of envFiles) {
const envPath = join(process.cwd(), file)
if (existsSync(envPath)) {
try {
const content = readFileSync(envPath, 'utf8')
const lines = content.split(/\\r?\\n/)
for (const line of lines) {
const trimmed = line.trim()
if (!trimmed || trimmed.startsWith('#')) continue
const match = trimmed.match(/^([^=]+)=(.*)$/)
if (match) {
const key = match[1].trim()
let value = match[2].trim()
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
value = value.substring(1, value.length - 1)
}
if (process.env[key] === undefined) {
process.env[key] = value
}
}
}
} catch (err) {
console.error('⚠️ [shumai] Error reading env file:', err)
}
}
}
}
// Load env files on startup
loadEnv()
console.log(\`ℹ️ [${appName}] Running from CWD: \${process.cwd()}\`)
console.log(\`ℹ️ [${appName}] DATABASE_URL is: \${process.env.DATABASE_URL ? '(defined)' : '(undefined)'}\`)
const prismaSchemaPath = join(__dirname, '..', 'prisma', 'schema.prisma')
if (existsSync(prismaSchemaPath)) {
console.log('🔄 Running database migrations...')
const migrationProcess = spawn(
binaryPath,
['run', 'prisma', 'migrate', 'deploy', '--schema', './prisma/schema.prisma'],
{
stdio: 'inherit',
cwd: join(__dirname, '..'),
env: {
...process.env,
BUN_BE_BUN: '1',
},
}
)
migrationProcess.on('close', (code) => {
if (code !== 0) {
console.error(\`❌ Database migration failed with code \${code}. Exiting.\`)
process.exit(code ?? 1)
}
startApp()
})
migrationProcess.on('error', (err) => {
console.error('❌ Failed to run database migrations:', err)
process.exit(1)
})
} else {
startApp()
}
` `
const wrapperPath = path.join(binOutDir, `${appName}.js`) const wrapperPath = path.join(binOutDir, `${appName}.js`)
@@ -318,6 +389,21 @@ child.on('error', (err) => {
recursive: true, recursive: true,
}) })
} }
// Generate prisma.config.ts in the package root
const localConfigContent = `import { defineConfig } from 'prisma/config'
export default defineConfig({
schema: './prisma/schema.prisma',
migrations: {
path: './prisma/migrations',
},
datasource: {
url: process.env.DATABASE_URL,
},
})
`
await writeFile(path.join(mainOutDir, 'prisma.config.ts'), localConfigContent, 'utf-8')
} }
// Generate package.json // Generate package.json
@@ -338,7 +424,7 @@ child.on('error', (err) => {
bin: { bin: {
[appName]: `./bin/${appName}.js`, [appName]: `./bin/${appName}.js`,
}, },
files: ['bin', ...(hasPrisma ? ['prisma'] : [])], files: ['bin', ...(hasPrisma ? ['prisma', 'prisma.config.ts'] : [])],
dependencies, dependencies,
optionalDependencies, optionalDependencies,
repository: rootPackageJson.repository, repository: rootPackageJson.repository,
@@ -377,7 +463,7 @@ await buildPlatformPackages('shumai-agent', dummyRunnerPath)
await buildMainPackage({ await buildMainPackage({
appName: 'shumai-agent', appName: 'shumai-agent',
description: 'AI worker agent for the shumai media workspace', description: 'AI worker agent for the shumai media workspace',
hasPrisma: false, hasPrisma: true,
entrypoint: './apps/agent/src/index.ts', entrypoint: './apps/agent/src/index.ts',
plugins: agentPlugins, plugins: agentPlugins,
}) })
@@ -392,7 +478,7 @@ await buildPlatformPackages('shumai-transcode', dummyRunnerPath)
await buildMainPackage({ await buildMainPackage({
appName: 'shumai-transcode', appName: 'shumai-transcode',
description: 'Media transcoding worker for the shumai media workspace', description: 'Media transcoding worker for the shumai media workspace',
hasPrisma: false, hasPrisma: true,
entrypoint: './apps/transcode/src/index.ts', entrypoint: './apps/transcode/src/index.ts',
plugins: transcodePlugins, plugins: transcodePlugins,
}) })