فهرست منبع

fix: 修复创建项目时复制模板文件夹问题

jiaxing.liao 1 هفته پیش
والد
کامیت
27d66098a1
4فایلهای تغییر یافته به همراه25 افزوده شده و 4 حذف شده
  1. 5 0
      electron-builder.yml
  2. 1 0
      resources/template/src/assets/images/.gitkeep
  3. 1 0
      resources/template/src/assets/others/.gitkeep
  4. 18 4
      src/main/files.ts

+ 5 - 0
electron-builder.yml

@@ -18,6 +18,11 @@ extraResources:
     to: pipe
     filter:
       - '**/*'
+  - from: resources/template
+    to: template
+    filter:
+      - '**/*'
+      - '**/.*'
 
 win:
   executableName: sunmicro-designer

+ 1 - 0
resources/template/src/assets/images/.gitkeep

@@ -0,0 +1 @@
+

+ 1 - 0
resources/template/src/assets/others/.gitkeep

@@ -0,0 +1 @@
+

+ 18 - 4
src/main/files.ts

@@ -156,11 +156,25 @@ export const unlockProjectFolder = () => {
 }
 
 export const copyTemplate = async (_e: Event, targetPath: string) => {
-  const templatePath = app.isPackaged
-    ? path.join(process.resourcesPath, 'template/src')
-    : path.join(process.cwd(), 'resources/template/src')
+  const templatePaths = app.isPackaged
+    ? [
+        path.join(process.resourcesPath, 'template/src'),
+        path.join(process.resourcesPath, 'app.asar.unpacked/resources/template/src')
+      ]
+    : [path.join(process.cwd(), 'resources/template/src')]
+  const templatePath = templatePaths.find((item) => fs.existsSync(item))
+
+  await fs.ensureDir(targetPath)
+  if (templatePath) {
+    await fs.copy(templatePath, targetPath)
+  }
 
-  await fs.cpSync(templatePath, targetPath, { recursive: true })
+  await fs.ensureDir(path.join(targetPath, 'assets/images'))
+  await fs.ensureDir(path.join(targetPath, 'assets/fonts'))
+  await fs.ensureDir(path.join(targetPath, 'assets/others'))
+  // .gitkeep占位文件 创建后移除
+  await fs.remove(path.join(targetPath, 'assets/images/.gitkeep'))
+  await fs.remove(path.join(targetPath, 'assets/others/.gitkeep'))
 }
 
 export function handleFile() {