导出优化

This commit is contained in:
tianmo
2026-09-05 18:45:43 +08:00
parent 72d8daa283
commit 79ce3165c1
17 changed files with 1559 additions and 1291 deletions
+10 -6
View File
@@ -3,6 +3,7 @@ import { constants } from 'node:fs'
import { homedir, platform } from 'node:os'
import { join } from 'node:path'
import { execFile } from 'node:child_process'
import { createSpine38ImportOptions } from './spine38-project.mjs'
const SUPPORTED_VERSIONS = new Set(['3.8', '4.0', '4.1', '4.2', '4.3'])
@@ -42,9 +43,9 @@ export function normalizeSpineVersion(value) {
return match[1]
}
function run(executablePath, args, timeoutMs = 180000) {
function run(executablePath, args, { cwd, timeoutMs = 180000 } = {}) {
return new Promise((resolve, reject) => {
execFile(executablePath, args, { timeout: timeoutMs, windowsHide: true, maxBuffer: 4 * 1024 * 1024 }, (error, stdout, stderr) => {
execFile(executablePath, args, { cwd, timeout: timeoutMs, windowsHide: true, maxBuffer: 4 * 1024 * 1024 }, (error, stdout, stderr) => {
if (error) {
const details = [stdout, stderr, error.message]
.filter(Boolean)
@@ -59,15 +60,18 @@ function run(executablePath, args, timeoutMs = 180000) {
})
}
export async function importSpineProject({ executablePath, inputPath, outputPath, projectName, spineVersion }) {
export async function importSpineProject({ executablePath, inputPath, outputPath, projectName, spineVersion, workspaceRoot }) {
const version = normalizeSpineVersion(spineVersion)
const editorVersion = `${version}.xx`
const importOptions = version === '3.8'
? createSpine38ImportOptions({ workspaceRoot, inputPath, outputPath })
: { inputPath, outputPath }
const result = await run(executablePath, [
'--update', editorVersion,
'--input', inputPath,
'--output', outputPath,
'--input', importOptions.inputPath,
'--output', importOptions.outputPath,
'--import', projectName,
])
], { cwd: importOptions.cwd })
const output = await stat(outputPath).catch(() => null)
if (!output?.isFile() || output.size === 0) throw new Error('Spine 未生成有效的工程文件')
const detected = /Starting:\s+Spine\s+([0-9.]+)/i.exec(`${result.stdout}\n${result.stderr}`)?.[1] || editorVersion