forked from imbytecat/fullstack-starter
feat: 添加目录存在性检查并优化复制逻辑
- 添加目录存在性检查功能并更新复制逻辑以使用该功能
This commit is contained in:
@@ -159,6 +159,9 @@ class FileSystemService extends Context.Tag('FileSystemService')<
|
||||
readonly fileExists: (
|
||||
filePath: string,
|
||||
) => Effect.Effect<boolean, FileSystemError>
|
||||
readonly dirExists: (
|
||||
dirPath: string,
|
||||
) => Effect.Effect<boolean, FileSystemError>
|
||||
readonly copyFile: (
|
||||
source: string,
|
||||
target: string,
|
||||
@@ -193,6 +196,25 @@ class FileSystemService extends Context.Tag('FileSystemService')<
|
||||
}),
|
||||
}),
|
||||
|
||||
dirExists: (dirPath: string) =>
|
||||
Effect.tryPromise({
|
||||
try: async () => {
|
||||
const { default: fs } = await import('node:fs/promises')
|
||||
try {
|
||||
const stat = await fs.stat(dirPath)
|
||||
return stat.isDirectory()
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
catch: (cause: unknown) =>
|
||||
new FileSystemError({
|
||||
operation: 'dirExists',
|
||||
path: dirPath,
|
||||
cause,
|
||||
}),
|
||||
}),
|
||||
|
||||
copyFile: (source: string, target: string) =>
|
||||
Effect.tryPromise({
|
||||
try: async () => {
|
||||
@@ -381,7 +403,7 @@ const program = Effect.gen(function* () {
|
||||
yield* Console.log('📦 开始复制二进制文件到 Tauri sidecar 目录...\n')
|
||||
|
||||
// 1. 检查源目录
|
||||
const sourceExists = yield* fs.fileExists(config.sourceDir)
|
||||
const sourceExists = yield* fs.dirExists(config.sourceDir)
|
||||
if (!sourceExists) {
|
||||
yield* Console.error(`❌ 源目录不存在: ${config.sourceDir}`)
|
||||
yield* Console.log(
|
||||
|
||||
Reference in New Issue
Block a user