fix: 重构新建项目逻辑,选定文件夹即项目
- 移除 prompt() 及 InputDialog 组件依赖 - 选定文件夹直接创建 .web2app 项目结构 - 默认以文件夹名作为项目名称 - 在编辑器中可自由修改名称、版本、图标、入口等配置 - 增强导入资源入口的文案提示
This commit is contained in:
@@ -111,8 +111,8 @@ ipcMain.handle('dir:readTree', async (_event, dirPath) => {
|
||||
return readDirectoryTree(dirPath)
|
||||
})
|
||||
|
||||
ipcMain.handle('project:create', async (_event, name, dir) => {
|
||||
return createProject(name, dir)
|
||||
ipcMain.handle('project:create', async (_event, projectPath) => {
|
||||
return createProject(projectPath)
|
||||
})
|
||||
|
||||
ipcMain.handle('project:load', async (_event, projectPath) => {
|
||||
|
||||
@@ -13,7 +13,7 @@ contextBridge.exposeInMainWorld('api', {
|
||||
readTree: (dirPath) => ipcRenderer.invoke('dir:readTree', dirPath)
|
||||
},
|
||||
project: {
|
||||
create: (name, dir) => ipcRenderer.invoke('project:create', name, dir),
|
||||
create: (projectPath) => ipcRenderer.invoke('project:create', projectPath),
|
||||
load: (projectPath) => ipcRenderer.invoke('project:load', projectPath),
|
||||
save: (projectPath, data) => ipcRenderer.invoke('project:save', projectPath, data),
|
||||
importFiles: (projectPath, files) => ipcRenderer.invoke('project:importFiles', projectPath, files),
|
||||
|
||||
@@ -21,16 +21,21 @@ function getDistDir(projectPath) {
|
||||
return dir
|
||||
}
|
||||
|
||||
function createProject(name, dir) {
|
||||
const projectPath = path.join(dir, name)
|
||||
if (fs.existsSync(projectPath)) {
|
||||
throw new Error(`目录 ${projectPath} 已存在`)
|
||||
function createProject(projectPath) {
|
||||
if (!fs.existsSync(projectPath)) {
|
||||
fs.mkdirSync(projectPath, { recursive: true })
|
||||
}
|
||||
|
||||
const configPath = getConfigPath(projectPath)
|
||||
if (fs.existsSync(configPath)) {
|
||||
throw new Error(`该目录已是 Web2App 项目`)
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.join(projectPath, '.web2app', 'src'), { recursive: true })
|
||||
fs.mkdirSync(path.join(projectPath, '.web2app', 'dist'), { recursive: true })
|
||||
|
||||
const config = {
|
||||
name,
|
||||
name: path.basename(projectPath),
|
||||
version: '1.0.0',
|
||||
description: '',
|
||||
author: '',
|
||||
@@ -47,7 +52,7 @@ function createProject(name, dir) {
|
||||
updatedAt: new Date().toISOString()
|
||||
}
|
||||
|
||||
fs.writeFileSync(getConfigPath(projectPath), JSON.stringify(config, null, 2))
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
|
||||
return { projectPath, config }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user