删除了数据保存中的内容项
This commit is contained in:
BIN
dsc-platform-1.6.1.vsix
Normal file
BIN
dsc-platform-1.6.1.vsix
Normal file
Binary file not shown.
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ConfigPanel = void 0;
|
||||
// src/panels/ConfigPanel.ts
|
||||
const vscode = __importStar(require("vscode"));
|
||||
const path = __importStar(require("path"));
|
||||
const ProjectView_1 = require("./views/ProjectView");
|
||||
@@ -279,8 +280,7 @@ class ConfigPanel {
|
||||
'openRepoSelectForUpload': (data) => this.openUploadRepoSelect(data.folderId, 'local'),
|
||||
'uploadLocalModuleFolder': (data) => this.uploadLocalModuleFolder(data.folderId, data.repoUrl, data.branchName),
|
||||
'openRepoSelectForGitUpload': (data) => this.openUploadRepoSelect(data.folderId, 'git'),
|
||||
// 旧的 repoSelectedForGitUpload 保留兼容的话可以转发到 handleRepoSelectedForBranches,但现在不再使用
|
||||
// 新增:上传时仓库 + 分支选择确认
|
||||
// 上传时 仓库+分支 选择确认
|
||||
'uploadRepoSelected': (data) => this.handleUploadRepoSelected(data.folderId, data.folderType, data.repoName, data.branchName)
|
||||
};
|
||||
const handler = messageHandlers[data.type];
|
||||
@@ -433,6 +433,7 @@ class ConfigPanel {
|
||||
}
|
||||
}
|
||||
async createConfig(name) {
|
||||
// 注意:真正创建文件内容的逻辑放在 ProjectService.createConfig 里处理
|
||||
const configId = await this.projectService.createConfig(name, this.currentContainerId);
|
||||
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
||||
await this.saveCurrentProjectData();
|
||||
@@ -447,7 +448,7 @@ class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 删除配置文件
|
||||
// 删除配置文件(磁盘)
|
||||
await this.projectService.deleteConfigFileFromDisk(configId);
|
||||
// 从内存中删除
|
||||
this.projectService.deleteConfig(configId);
|
||||
@@ -480,7 +481,7 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage('未找到项目路径');
|
||||
return;
|
||||
}
|
||||
// 获取选中的配置
|
||||
// 获取选中的配置(仅元信息,不含 content)
|
||||
const selectedConfigs = configIds
|
||||
.map(id => this.projectService.getConfig(id))
|
||||
.filter(Boolean);
|
||||
@@ -491,17 +492,21 @@ class ConfigPanel {
|
||||
// 创建合并文件夹
|
||||
const mergeFolderPath = path.join(projectPath, this.getAircraftName(), container.name, folderName);
|
||||
await vscode.workspace.fs.createDirectory(vscode.Uri.file(mergeFolderPath));
|
||||
// 复制文件到合并文件夹
|
||||
const fs = require('fs');
|
||||
// 复制文件到合并文件夹:完全基于磁盘文件
|
||||
for (const config of selectedConfigs) {
|
||||
if (!config)
|
||||
continue;
|
||||
const sourcePath = this.projectService.getConfigFilePath(config.id);
|
||||
const targetPath = path.join(mergeFolderPath, config.fileName);
|
||||
if (sourcePath && require('fs').existsSync(sourcePath)) {
|
||||
await require('fs').promises.copyFile(sourcePath, targetPath);
|
||||
if (sourcePath && fs.existsSync(sourcePath)) {
|
||||
await fs.promises.copyFile(sourcePath, targetPath);
|
||||
}
|
||||
else {
|
||||
await require('fs').promises.writeFile(targetPath, config.content || '');
|
||||
// 找不到源文件:写一个占位注释文件
|
||||
const placeholder = `# 原配置文件 "${config.fileName}" 未在磁盘中找到\n` +
|
||||
`# 仅保留占位文件,建议手动补充内容\n\n`;
|
||||
await fs.promises.writeFile(targetPath, placeholder, 'utf8');
|
||||
}
|
||||
}
|
||||
// 创建模块文件夹记录(使用 ProjectService 的统一 ID 生成)
|
||||
@@ -514,10 +519,10 @@ class ConfigPanel {
|
||||
containerId: this.currentContainerId
|
||||
};
|
||||
this.projectService.addModuleFolder(newFolder);
|
||||
// 删除原配置
|
||||
// 删除原配置(包括磁盘上的配置文件)
|
||||
for (const configId of configIds) {
|
||||
this.projectService.deleteConfig(configId);
|
||||
await this.projectService.deleteConfigFileFromDisk(configId);
|
||||
this.projectService.deleteConfig(configId);
|
||||
}
|
||||
await this.saveCurrentProjectData();
|
||||
vscode.window.showInformationMessage(`成功合并 ${selectedConfigs.length} 个配置文件到文件夹: ${folderName}`);
|
||||
@@ -804,14 +809,21 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage('无法获取模块文件夹路径');
|
||||
return;
|
||||
}
|
||||
const fileFullPath = path.join(fullPath, filePath);
|
||||
const content = await require('fs').promises.readFile(fileFullPath, 'utf8');
|
||||
const fs = require('fs');
|
||||
const sourceFullPath = path.join(fullPath, filePath);
|
||||
const content = await fs.promises.readFile(sourceFullPath, 'utf8');
|
||||
const fileName = path.basename(filePath);
|
||||
// 1. 先创建一个配置(ProjectService.createConfig 内部会在磁盘上生成文件)
|
||||
const configId = await this.projectService.createConfig(fileName, this.currentContainerId);
|
||||
const config = this.projectService.getConfig(configId);
|
||||
if (config) {
|
||||
config.content = content;
|
||||
// 2. 再把 Git 文件的内容写到该配置文件上,覆盖默认模板
|
||||
const targetConfigPath = this.projectService.getConfigFilePath(configId);
|
||||
if (!targetConfigPath) {
|
||||
vscode.window.showErrorMessage('无法获取新配置文件的路径');
|
||||
return;
|
||||
}
|
||||
const dirPath = path.dirname(targetConfigPath);
|
||||
await fs.promises.mkdir(dirPath, { recursive: true });
|
||||
await fs.promises.writeFile(targetConfigPath, content, 'utf8');
|
||||
await this.saveCurrentProjectData();
|
||||
vscode.window.showInformationMessage(`文件已导入: ${fileName}`);
|
||||
this.updateWebview();
|
||||
@@ -872,7 +884,8 @@ class ConfigPanel {
|
||||
}, async (progress) => {
|
||||
try {
|
||||
progress.report({ increment: 0, message: '检查目录...' });
|
||||
if (!require('fs').existsSync(fullPath)) {
|
||||
const fs = require('fs');
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
throw new Error('本地文件夹不存在');
|
||||
}
|
||||
progress.report({ increment: 10, message: '初始化 Git 仓库...' });
|
||||
@@ -899,8 +912,9 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
||||
try {
|
||||
const gitDir = path.join(fullPath, '.git');
|
||||
if (require('fs').existsSync(gitDir)) {
|
||||
await require('fs').promises.rm(gitDir, { recursive: true, force: true });
|
||||
const fs = require('fs');
|
||||
if (fs.existsSync(gitDir)) {
|
||||
await fs.promises.rm(gitDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
catch (cleanupError) {
|
||||
@@ -973,7 +987,12 @@ class ConfigPanel {
|
||||
vscode.window.showWarningMessage('配置文件不存在,将创建新文件');
|
||||
const dirPath = path.dirname(filePath);
|
||||
await fs.promises.mkdir(dirPath, { recursive: true });
|
||||
await fs.promises.writeFile(filePath, config.content || '');
|
||||
const now = new Date();
|
||||
const header = `# ${config.fileName} 配置文件\n` +
|
||||
`# 创建时间: ${now.getFullYear()}/${now.getMonth() + 1}/${now.getDate()} ` +
|
||||
`${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}\n` +
|
||||
`# 您可以在此编辑配置内容\n\n`;
|
||||
await fs.promises.writeFile(filePath, header, 'utf8');
|
||||
}
|
||||
const document = await vscode.workspace.openTextDocument(filePath);
|
||||
await vscode.window.showTextDocument(document);
|
||||
@@ -990,7 +1009,8 @@ class ConfigPanel {
|
||||
}
|
||||
try {
|
||||
const fullPath = this.projectService.getModuleFolderFullPath(folder);
|
||||
if (!fullPath || !require('fs').existsSync(fullPath)) {
|
||||
const fs = require('fs');
|
||||
if (!fullPath || !fs.existsSync(fullPath)) {
|
||||
vscode.window.showErrorMessage('模块文件夹目录不存在');
|
||||
return;
|
||||
}
|
||||
@@ -1026,7 +1046,8 @@ class ConfigPanel {
|
||||
return;
|
||||
const newFullPath = path.join(path.dirname(fullPath), newName);
|
||||
try {
|
||||
await require('fs').promises.rename(fullPath, newFullPath);
|
||||
const fs = require('fs');
|
||||
await fs.promises.rename(fullPath, newFullPath);
|
||||
this.projectService.renameModuleFolder(folderId, newName);
|
||||
await this.saveCurrentProjectData();
|
||||
vscode.window.showInformationMessage(`已重命名文件夹: ${oldName} → ${newName}`);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -181,7 +181,6 @@ class ProjectService {
|
||||
id: newId,
|
||||
name: name,
|
||||
fileName: name.toLowerCase().replace(/\s+/g, '_'),
|
||||
content: `# ${name} 配置文件\n# 创建时间: ${new Date().toLocaleString()}\n# 您可以在此编辑配置内容\n\n`,
|
||||
containerId: containerId
|
||||
};
|
||||
this.configs.push(newConfig);
|
||||
@@ -301,14 +300,12 @@ class ProjectService {
|
||||
id: this.generateUniqueId('cfg', this.configs),
|
||||
name: '配置1',
|
||||
fileName: 'dockerfile',
|
||||
content: `# ${container.name} 的 Dockerfile\nFROM ubuntu:20.04\n\n# 设置工作目录\nWORKDIR /app\n\n# 复制文件\nCOPY . .\n\n# 安装依赖\nRUN apt-get update && apt-get install -y \\\n python3 \\\n python3-pip\n\n# 暴露端口\nEXPOSE 8080\n\n# 启动命令\nCMD ["python3", "app.py"]`,
|
||||
containerId: container.id
|
||||
});
|
||||
this.configs.push({
|
||||
id: this.generateUniqueId('cfg', this.configs),
|
||||
name: '配置2',
|
||||
fileName: 'docker-compose.yml',
|
||||
content: `# ${container.name} 的 Docker Compose 配置\nversion: '3.8'\n\nservices:\n ${container.name.toLowerCase().replace(/\s+/g, '-')}:\n build: .\n container_name: ${container.name}\n ports:\n - "8080:8080"\n environment:\n - NODE_ENV=production\n volumes:\n - ./data:/app/data\n restart: unless-stopped`,
|
||||
containerId: container.id
|
||||
});
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "dsc-platform",
|
||||
"displayName": "数字卫星构建平台",
|
||||
"version": "1.5.1",
|
||||
"version": "1.6.1",
|
||||
"publisher": "njust-micro-nano-lab",
|
||||
"description": "一个用于快速构建数字卫星的平台",
|
||||
"repository": {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// src/panels/ConfigPanel.ts
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import { ProjectView } from './views/ProjectView';
|
||||
@@ -358,8 +359,8 @@ export class ConfigPanel {
|
||||
'openRepoSelectForUpload': (data) => this.openUploadRepoSelect(data.folderId, 'local'),
|
||||
'uploadLocalModuleFolder': (data) => this.uploadLocalModuleFolder(data.folderId, data.repoUrl, data.branchName),
|
||||
'openRepoSelectForGitUpload': (data) => this.openUploadRepoSelect(data.folderId, 'git'),
|
||||
// 旧的 repoSelectedForGitUpload 保留兼容的话可以转发到 handleRepoSelectedForBranches,但现在不再使用
|
||||
// 新增:上传时仓库 + 分支选择确认
|
||||
|
||||
// 上传时 仓库+分支 选择确认
|
||||
'uploadRepoSelected': (data) => this.handleUploadRepoSelected(
|
||||
data.folderId,
|
||||
data.folderType,
|
||||
@@ -544,6 +545,7 @@ export class ConfigPanel {
|
||||
}
|
||||
|
||||
private async createConfig(name: string): Promise<void> {
|
||||
// 注意:真正创建文件内容的逻辑放在 ProjectService.createConfig 里处理
|
||||
const configId = await this.projectService.createConfig(name, this.currentContainerId);
|
||||
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
||||
await this.saveCurrentProjectData();
|
||||
@@ -566,7 +568,7 @@ export class ConfigPanel {
|
||||
}
|
||||
|
||||
try {
|
||||
// 删除配置文件
|
||||
// 删除配置文件(磁盘)
|
||||
await this.projectService.deleteConfigFileFromDisk(configId);
|
||||
|
||||
// 从内存中删除
|
||||
@@ -606,7 +608,7 @@ export class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取选中的配置
|
||||
// 获取选中的配置(仅元信息,不含 content)
|
||||
const selectedConfigs = configIds
|
||||
.map(id => this.projectService.getConfig(id))
|
||||
.filter(Boolean);
|
||||
@@ -620,17 +622,23 @@ export class ConfigPanel {
|
||||
const mergeFolderPath = path.join(projectPath, this.getAircraftName(), container.name, folderName);
|
||||
await vscode.workspace.fs.createDirectory(vscode.Uri.file(mergeFolderPath));
|
||||
|
||||
// 复制文件到合并文件夹
|
||||
const fs = require('fs');
|
||||
|
||||
// 复制文件到合并文件夹:完全基于磁盘文件
|
||||
for (const config of selectedConfigs) {
|
||||
if (!config) continue;
|
||||
|
||||
const sourcePath = this.projectService.getConfigFilePath(config.id);
|
||||
const targetPath = path.join(mergeFolderPath, config.fileName);
|
||||
|
||||
if (sourcePath && require('fs').existsSync(sourcePath)) {
|
||||
await require('fs').promises.copyFile(sourcePath, targetPath);
|
||||
if (sourcePath && fs.existsSync(sourcePath)) {
|
||||
await fs.promises.copyFile(sourcePath, targetPath);
|
||||
} else {
|
||||
await require('fs').promises.writeFile(targetPath, config.content || '');
|
||||
// 找不到源文件:写一个占位注释文件
|
||||
const placeholder =
|
||||
`# 原配置文件 "${config.fileName}" 未在磁盘中找到\n` +
|
||||
`# 仅保留占位文件,建议手动补充内容\n\n`;
|
||||
await fs.promises.writeFile(targetPath, placeholder, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,10 +654,10 @@ export class ConfigPanel {
|
||||
|
||||
this.projectService.addModuleFolder(newFolder);
|
||||
|
||||
// 删除原配置
|
||||
// 删除原配置(包括磁盘上的配置文件)
|
||||
for (const configId of configIds) {
|
||||
this.projectService.deleteConfig(configId);
|
||||
await this.projectService.deleteConfigFileFromDisk(configId);
|
||||
this.projectService.deleteConfig(configId);
|
||||
}
|
||||
|
||||
await this.saveCurrentProjectData();
|
||||
@@ -1017,17 +1025,25 @@ export class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFullPath = path.join(fullPath, filePath);
|
||||
const content = await require('fs').promises.readFile(fileFullPath, 'utf8');
|
||||
const fs = require('fs');
|
||||
const sourceFullPath = path.join(fullPath, filePath);
|
||||
const content = await fs.promises.readFile(sourceFullPath, 'utf8');
|
||||
const fileName = path.basename(filePath);
|
||||
|
||||
// 1. 先创建一个配置(ProjectService.createConfig 内部会在磁盘上生成文件)
|
||||
const configId = await this.projectService.createConfig(fileName, this.currentContainerId);
|
||||
const config = this.projectService.getConfig(configId);
|
||||
|
||||
if (config) {
|
||||
config.content = content;
|
||||
|
||||
// 2. 再把 Git 文件的内容写到该配置文件上,覆盖默认模板
|
||||
const targetConfigPath = this.projectService.getConfigFilePath(configId);
|
||||
if (!targetConfigPath) {
|
||||
vscode.window.showErrorMessage('无法获取新配置文件的路径');
|
||||
return;
|
||||
}
|
||||
|
||||
const dirPath = path.dirname(targetConfigPath);
|
||||
await fs.promises.mkdir(dirPath, { recursive: true });
|
||||
await fs.promises.writeFile(targetConfigPath, content, 'utf8');
|
||||
|
||||
await this.saveCurrentProjectData();
|
||||
|
||||
vscode.window.showInformationMessage(`文件已导入: ${fileName}`);
|
||||
@@ -1107,7 +1123,8 @@ export class ConfigPanel {
|
||||
try {
|
||||
progress.report({ increment: 0, message: '检查目录...' });
|
||||
|
||||
if (!require('fs').existsSync(fullPath)) {
|
||||
const fs = require('fs');
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
throw new Error('本地文件夹不存在');
|
||||
}
|
||||
|
||||
@@ -1143,8 +1160,9 @@ export class ConfigPanel {
|
||||
|
||||
try {
|
||||
const gitDir = path.join(fullPath, '.git');
|
||||
if (require('fs').existsSync(gitDir)) {
|
||||
await require('fs').promises.rm(gitDir, { recursive: true, force: true });
|
||||
const fs = require('fs');
|
||||
if (fs.existsSync(gitDir)) {
|
||||
await fs.promises.rm(gitDir, { recursive: true, force: true });
|
||||
}
|
||||
} catch (cleanupError) {
|
||||
console.error('清理 .git 文件夹失败:', cleanupError);
|
||||
@@ -1224,7 +1242,15 @@ export class ConfigPanel {
|
||||
vscode.window.showWarningMessage('配置文件不存在,将创建新文件');
|
||||
const dirPath = path.dirname(filePath);
|
||||
await fs.promises.mkdir(dirPath, { recursive: true });
|
||||
await fs.promises.writeFile(filePath, config.content || '');
|
||||
|
||||
const now = new Date();
|
||||
const header =
|
||||
`# ${config.fileName} 配置文件\n` +
|
||||
`# 创建时间: ${now.getFullYear()}/${now.getMonth() + 1}/${now.getDate()} ` +
|
||||
`${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}\n` +
|
||||
`# 您可以在此编辑配置内容\n\n`;
|
||||
|
||||
await fs.promises.writeFile(filePath, header, 'utf8');
|
||||
}
|
||||
|
||||
const document = await vscode.workspace.openTextDocument(filePath);
|
||||
@@ -1244,7 +1270,8 @@ export class ConfigPanel {
|
||||
|
||||
try {
|
||||
const fullPath = this.projectService.getModuleFolderFullPath(folder);
|
||||
if (!fullPath || !require('fs').existsSync(fullPath)) {
|
||||
const fs = require('fs');
|
||||
if (!fullPath || !fs.existsSync(fullPath)) {
|
||||
vscode.window.showErrorMessage('模块文件夹目录不存在');
|
||||
return;
|
||||
}
|
||||
@@ -1285,7 +1312,8 @@ export class ConfigPanel {
|
||||
const newFullPath = path.join(path.dirname(fullPath), newName);
|
||||
|
||||
try {
|
||||
await require('fs').promises.rename(fullPath, newFullPath);
|
||||
const fs = require('fs');
|
||||
await fs.promises.rename(fullPath, newFullPath);
|
||||
|
||||
this.projectService.renameModuleFolder(folderId, newName);
|
||||
await this.saveCurrentProjectData();
|
||||
|
||||
@@ -195,7 +195,6 @@ export class ProjectService {
|
||||
id: newId,
|
||||
name: name,
|
||||
fileName: name.toLowerCase().replace(/\s+/g, '_'),
|
||||
content: `# ${name} 配置文件\n# 创建时间: ${new Date().toLocaleString()}\n# 您可以在此编辑配置内容\n\n`,
|
||||
containerId: containerId
|
||||
};
|
||||
this.configs.push(newConfig);
|
||||
@@ -335,7 +334,6 @@ export class ProjectService {
|
||||
id: this.generateUniqueId('cfg', this.configs),
|
||||
name: '配置1',
|
||||
fileName: 'dockerfile',
|
||||
content: `# ${container.name} 的 Dockerfile\nFROM ubuntu:20.04\n\n# 设置工作目录\nWORKDIR /app\n\n# 复制文件\nCOPY . .\n\n# 安装依赖\nRUN apt-get update && apt-get install -y \\\n python3 \\\n python3-pip\n\n# 暴露端口\nEXPOSE 8080\n\n# 启动命令\nCMD ["python3", "app.py"]`,
|
||||
containerId: container.id
|
||||
});
|
||||
|
||||
@@ -343,7 +341,6 @@ export class ProjectService {
|
||||
id: this.generateUniqueId('cfg', this.configs),
|
||||
name: '配置2',
|
||||
fileName: 'docker-compose.yml',
|
||||
content: `# ${container.name} 的 Docker Compose 配置\nversion: '3.8'\n\nservices:\n ${container.name.toLowerCase().replace(/\s+/g, '-')}:\n build: .\n container_name: ${container.name}\n ports:\n - "8080:8080"\n environment:\n - NODE_ENV=production\n volumes:\n - ./data:/app/data\n restart: unless-stopped`,
|
||||
containerId: container.id
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ export interface Config {
|
||||
id: string;
|
||||
name: string;
|
||||
fileName: string;
|
||||
content: string;
|
||||
containerId: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ export interface ConfigViewData {
|
||||
id: string;
|
||||
name: string;
|
||||
fileName: string;
|
||||
content: string;
|
||||
containerId: string;
|
||||
}
|
||||
|
||||
|
||||
1
src/panels/types/WebviewMessage.ts
Normal file → Executable file
1
src/panels/types/WebviewMessage.ts
Normal file → Executable file
@@ -17,5 +17,4 @@ export interface ContainerMessage extends WebviewMessage {
|
||||
export interface ConfigMessage extends WebviewMessage {
|
||||
configId: string;
|
||||
name?: string;
|
||||
content?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user