fix: use Vite API directly for global CLI
Spawn-based approach fails on global install because node_modules is hoisted. Use programmatic Vite API instead. Move vite, plugin-vue, and sass to dependencies so they're available at runtime. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+22
-8
@@ -1,22 +1,36 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import { spawn } from 'child_process'
|
|
||||||
import { resolve, dirname } from 'path'
|
import { resolve, dirname } from 'path'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||||
const projectRoot = resolve(__dirname, '..')
|
const projectRoot = resolve(__dirname, '..')
|
||||||
|
|
||||||
const args = process.argv.slice(2)
|
const command = process.argv[2]
|
||||||
const command = args[0]
|
|
||||||
|
|
||||||
if (!command || command === 'start' || command === 'dev') {
|
if (!command || command === 'start' || command === 'dev') {
|
||||||
const viteBin = resolve(projectRoot, 'node_modules/.bin/vite')
|
const { createServer } = await import('vite')
|
||||||
spawn(viteBin, ['--host', '--port', '8648'], { stdio: 'inherit', cwd: projectRoot })
|
const vue = await import('@vitejs/plugin-vue')
|
||||||
|
const server = await createServer({
|
||||||
|
root: projectRoot,
|
||||||
|
configFile: resolve(projectRoot, 'vite.config.ts'),
|
||||||
|
server: {
|
||||||
|
host: true,
|
||||||
|
port: 8648,
|
||||||
|
},
|
||||||
|
plugins: [vue.default()],
|
||||||
|
})
|
||||||
|
await server.listen()
|
||||||
|
server.printUrls()
|
||||||
} else if (command === 'build') {
|
} else if (command === 'build') {
|
||||||
const viteBin = resolve(projectRoot, 'node_modules/.bin/vite')
|
const { build } = await import('vite')
|
||||||
spawn(viteBin, ['build'], { stdio: 'inherit', cwd: projectRoot })
|
const vue = await import('@vitejs/plugin-vue')
|
||||||
|
await build({
|
||||||
|
root: projectRoot,
|
||||||
|
configFile: resolve(projectRoot, 'vite.config.ts'),
|
||||||
|
plugins: [vue.default()],
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log(`Usage: hermes-web-ui [command]`)
|
console.log('Usage: hermes-web-ui [command]')
|
||||||
console.log()
|
console.log()
|
||||||
console.log('Commands:')
|
console.log('Commands:')
|
||||||
console.log(' start Start dev server (default)')
|
console.log(' start Start dev server (default)')
|
||||||
|
|||||||
+3
-3
@@ -24,21 +24,21 @@
|
|||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@vitejs/plugin-vue": "^6.0.5",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
"markdown-it": "^14.1.1",
|
"markdown-it": "^14.1.1",
|
||||||
"naive-ui": "^2.44.1",
|
"naive-ui": "^2.44.1",
|
||||||
"pinia": "^3.0.4",
|
"pinia": "^3.0.4",
|
||||||
|
"sass": "^1.99.0",
|
||||||
|
"vite": "^8.0.4",
|
||||||
"vue": "^3.5.32",
|
"vue": "^3.5.32",
|
||||||
"vue-router": "^4.6.4"
|
"vue-router": "^4.6.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/markdown-it": "^14.1.2",
|
"@types/markdown-it": "^14.1.2",
|
||||||
"@types/node": "^24.12.2",
|
"@types/node": "^24.12.2",
|
||||||
"@vitejs/plugin-vue": "^6.0.5",
|
|
||||||
"@vue/tsconfig": "^0.9.1",
|
"@vue/tsconfig": "^0.9.1",
|
||||||
"sass": "^1.99.0",
|
|
||||||
"typescript": "~6.0.2",
|
"typescript": "~6.0.2",
|
||||||
"vite": "^8.0.4",
|
|
||||||
"vue-tsc": "^3.2.6"
|
"vue-tsc": "^3.2.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user