瀏覽代碼

Fix: make public dir before copy

SukkaW 1 年之前
父節點
當前提交
1509fef647
共有 1 個文件被更改,包括 13 次插入1 次删除
  1. 13 1
      Build/build-public.ts

+ 13 - 1
Build/build-public.ts

@@ -1,4 +1,5 @@
 import path from 'path';
+import fs from 'fs';
 import fsp from 'fs/promises';
 import { task } from './trace';
 import { treeDir } from './lib/tree-dir';
@@ -23,6 +24,8 @@ const folderAndFilesToBeDeployed = [
 ];
 
 export const buildPublic = task(typeof Bun !== 'undefined' ? Bun.main === __filename : require.main === module, __filename)(async (span) => {
+  fs.mkdirSync(publicPath, { recursive: true });
+
   await span
     .traceChild('copy public files')
     .traceAsyncFn(async () => {
@@ -43,7 +46,16 @@ export const buildPublic = task(typeof Bun !== 'undefined' ? Bun.main === __file
         const src = path.join(rootPath, file);
         const dest = path.join(publicPath, file);
 
-        return fsp.copyFile(src, dest);
+        const destParen = path.dirname(dest);
+        if (!fs.existsSync(destParen)) {
+          fs.mkdirSync(destParen, { recursive: true });
+        }
+
+        return fsp.copyFile(
+          src,
+          dest,
+          fs.constants.COPYFILE_FICLONE
+        );
       }));
     });