diff --git a/src/main/IPCs.ts b/src/main/IPCs.ts index 70f8fa4..f2a28e4 100644 --- a/src/main/IPCs.ts +++ b/src/main/IPCs.ts @@ -6,9 +6,11 @@ import { readFileSync, existsSync, ensureDirSync, - copyFileSync + copyFileSync, + readdirSync } from 'fs-extra' import { autoUpdater } from 'electron-updater' +import { Template, TreeNode } from '../types' /* * IPC Communications @@ -182,7 +184,7 @@ export default class IPCs { const userDataPath = join(Constants.APP_DATA_PATH, 'data') const filePath = join(userDataPath, 'templates.json') - let templates = [] + let templates: Template[] = [] if (existsSync(filePath)) { const templatesData = readFileSync(filePath, 'utf-8') templates = JSON.parse(templatesData) @@ -203,11 +205,14 @@ export default class IPCs { ensureDirSync(baseDirPath) // Helper function to traverse the tree and collect all nodes - const collectAllNodes = (nodes, allNodes = []) => { + const collectAllNodes = (nodes: TreeNode[], allNodes: TreeNode[] = [], parent?: TreeNode) => { for (const node of nodes) { - allNodes.push(node); + allNodes.push({ + ...node, + path: join(parent?.path || '', node.path) + }); if (node.children) { - collectAllNodes(node.children, allNodes); + collectAllNodes(node.children, allNodes, node); } } return allNodes; @@ -227,13 +232,17 @@ export default class IPCs { const fileDir = dirname(nodePath); ensureDirSync(fileDir); - if (node.sourceFilePath) { - // Copy from source file - const sourceContent = readFileSync(node.sourceFilePath); - writeFileSync(nodePath, sourceContent); - } else if (node.content) { + if (node.sourceType === 'file') { + copyFileSync(node.sourcePath, nodePath); + } else { // Write content directly - writeFileSync(nodePath, node.content, 'utf-8'); + const files = readdirSync(node.sourcePath, { withFileTypes: true }) + for (const file of files) { + if (file.isFile() && file.name.startsWith(baseDirName)) { + const filePath = join(node.sourcePath, file.name); + copyFileSync(filePath, nodePath); + } + } } } } diff --git a/src/renderer/components/DirectoryDialog.vue b/src/renderer/components/DirectoryDialog.vue index 6bdd79a..a6e49a0 100644 --- a/src/renderer/components/DirectoryDialog.vue +++ b/src/renderer/components/DirectoryDialog.vue @@ -39,7 +39,7 @@