2025-12-02 12:52:41 +08:00
|
|
|
|
// src/panels/ConfigPanel.ts
|
2025-11-18 09:10:47 +08:00
|
|
|
|
import * as vscode from 'vscode';
|
2025-11-24 17:53:48 +08:00
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
|
import git from 'isomorphic-git';
|
|
|
|
|
|
import http from 'isomorphic-git/http/node';
|
2025-11-18 18:45:30 +08:00
|
|
|
|
import { ProjectView } from './views/ProjectView';
|
|
|
|
|
|
import { AircraftView } from './views/AircraftView';
|
|
|
|
|
|
import { ContainerView } from './views/ContainerView';
|
|
|
|
|
|
import { ConfigView } from './views/ConfigView';
|
2025-11-28 14:58:18 +08:00
|
|
|
|
import { ModuleFolder } from './types/CommonTypes';
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-12-02 14:48:30 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
2025-11-18 09:10:47 +08:00
|
|
|
|
// 数据模型接口
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
|
2025-11-18 09:10:47 +08:00
|
|
|
|
interface Project {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface Aircraft {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
projectId: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface Container {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
aircraftId: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface Config {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
fileName: string;
|
|
|
|
|
|
content: string;
|
|
|
|
|
|
containerId: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-24 17:53:48 +08:00
|
|
|
|
interface GitFileTree {
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
type: 'file' | 'folder';
|
|
|
|
|
|
path: string;
|
|
|
|
|
|
children?: GitFileTree[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface GitBranch {
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
isCurrent: boolean;
|
|
|
|
|
|
selected?: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-27 20:10:09 +08:00
|
|
|
|
interface ProjectData {
|
|
|
|
|
|
projects: Project[];
|
|
|
|
|
|
aircrafts: Aircraft[];
|
|
|
|
|
|
containers: Container[];
|
|
|
|
|
|
configs: Config[];
|
2025-11-28 19:42:59 +08:00
|
|
|
|
moduleFolders: ModuleFolder[];
|
2025-11-27 20:10:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
// 仓库配置项
|
|
|
|
|
|
interface RepoConfigItem {
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
url: string;
|
|
|
|
|
|
username?: string;
|
|
|
|
|
|
password?: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 主面板类
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
2025-11-18 09:10:47 +08:00
|
|
|
|
export class ConfigPanel {
|
2025-11-24 17:53:48 +08:00
|
|
|
|
public static currentPanel: ConfigPanel | undefined;
|
|
|
|
|
|
public readonly panel: vscode.WebviewPanel;
|
2025-11-18 09:10:47 +08:00
|
|
|
|
private readonly extensionUri: vscode.Uri;
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// 视图状态管理
|
2025-11-18 18:45:30 +08:00
|
|
|
|
private currentView: 'projects' | 'aircrafts' | 'containers' | 'configs' = 'projects';
|
2025-11-18 09:10:47 +08:00
|
|
|
|
private currentProjectId: string = '';
|
|
|
|
|
|
private currentAircraftId: string = '';
|
|
|
|
|
|
private currentContainerId: string = '';
|
2025-11-27 22:04:32 +08:00
|
|
|
|
private currentModuleFolderId: string = '';
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
|
|
|
|
|
// 数据存储
|
2025-11-18 18:45:30 +08:00
|
|
|
|
private projects: Project[] = [];
|
|
|
|
|
|
private aircrafts: Aircraft[] = [];
|
|
|
|
|
|
private containers: Container[] = [];
|
|
|
|
|
|
private configs: Config[] = [];
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private moduleFolders: ModuleFolder[] = [];
|
2025-11-27 22:04:32 +08:00
|
|
|
|
private currentModuleFolderFileTree: GitFileTree[] = [];
|
2025-11-18 14:03:22 +08:00
|
|
|
|
private projectPaths: Map<string, string> = new Map();
|
2025-12-02 14:48:30 +08:00
|
|
|
|
private pendingUploadFolderId: string | null = null;
|
2025-11-18 14:03:22 +08:00
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
// 仓库配置
|
|
|
|
|
|
private repoConfigs: RepoConfigItem[] = [];
|
|
|
|
|
|
private currentRepoForBranches: RepoConfigItem | undefined;
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// 状态管理
|
2025-11-25 14:30:54 +08:00
|
|
|
|
private isWebviewDisposed: boolean = false;
|
|
|
|
|
|
|
2025-11-18 09:10:47 +08:00
|
|
|
|
// 视图实例
|
2025-11-18 18:45:30 +08:00
|
|
|
|
private readonly projectView: ProjectView;
|
|
|
|
|
|
private readonly aircraftView: AircraftView;
|
|
|
|
|
|
private readonly containerView: ContainerView;
|
|
|
|
|
|
private readonly configView: ConfigView;
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 公共方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
2025-11-18 09:10:47 +08:00
|
|
|
|
public static createOrShow(extensionUri: vscode.Uri) {
|
|
|
|
|
|
const column = vscode.window.activeTextEditor?.viewColumn || vscode.ViewColumn.One;
|
|
|
|
|
|
|
|
|
|
|
|
if (ConfigPanel.currentPanel) {
|
|
|
|
|
|
ConfigPanel.currentPanel.panel.reveal(column);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const panel = vscode.window.createWebviewPanel(
|
2025-11-18 18:45:30 +08:00
|
|
|
|
'DCSP',
|
|
|
|
|
|
'数字卫星构建平台',
|
2025-11-18 09:10:47 +08:00
|
|
|
|
column,
|
|
|
|
|
|
{
|
|
|
|
|
|
enableScripts: true,
|
|
|
|
|
|
localResourceRoots: [extensionUri],
|
|
|
|
|
|
retainContextWhenHidden: true
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
ConfigPanel.currentPanel = new ConfigPanel(panel, extensionUri);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-24 17:53:48 +08:00
|
|
|
|
public constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
|
2025-11-18 09:10:47 +08:00
|
|
|
|
this.panel = panel;
|
|
|
|
|
|
this.extensionUri = extensionUri;
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.isWebviewDisposed = false;
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// 初始化视图
|
2025-11-18 18:45:30 +08:00
|
|
|
|
this.projectView = new ProjectView(extensionUri);
|
|
|
|
|
|
this.aircraftView = new AircraftView(extensionUri);
|
|
|
|
|
|
this.containerView = new ContainerView(extensionUri);
|
|
|
|
|
|
this.configView = new ConfigView(extensionUri);
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
// 尝试加载仓库配置
|
|
|
|
|
|
void this.loadRepoConfigs();
|
|
|
|
|
|
|
2025-11-18 09:10:47 +08:00
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
this.setupMessageListener();
|
|
|
|
|
|
|
|
|
|
|
|
this.panel.onDidDispose(() => {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.isWebviewDisposed = true;
|
2025-11-18 09:10:47 +08:00
|
|
|
|
ConfigPanel.currentPanel = undefined;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 工具方法 - ID 生成
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private generateUniqueId(prefix: string, existingItems: any[]): string {
|
|
|
|
|
|
let idNumber = 1;
|
|
|
|
|
|
|
|
|
|
|
|
// 先找到当前最大的数字
|
|
|
|
|
|
const existingIds = existingItems.map(item => item.id);
|
|
|
|
|
|
const numberPattern = /\d+$/;
|
|
|
|
|
|
|
|
|
|
|
|
for (const id of existingIds) {
|
|
|
|
|
|
const match = id.match(numberPattern);
|
|
|
|
|
|
if (match) {
|
|
|
|
|
|
const num = parseInt(match[0]);
|
|
|
|
|
|
if (num >= idNumber) {
|
|
|
|
|
|
idNumber = num + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return `${prefix}${idNumber}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 仓库配置相关
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private getRepoConfigPath(): string {
|
|
|
|
|
|
// 按你的需求:配置文件保存在插件安装位置
|
|
|
|
|
|
return path.join(this.extensionUri.fsPath, 'dcsp-repos.json');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async loadRepoConfigs(): Promise<void> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const configPath = this.getRepoConfigPath();
|
|
|
|
|
|
if (!fs.existsSync(configPath)) {
|
|
|
|
|
|
this.repoConfigs = [];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const content = await fs.promises.readFile(configPath, 'utf8');
|
|
|
|
|
|
if (!content.trim()) {
|
|
|
|
|
|
this.repoConfigs = [];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const parsed = JSON.parse(content);
|
|
|
|
|
|
if (Array.isArray(parsed)) {
|
|
|
|
|
|
// 兼容老格式:直接是数组
|
|
|
|
|
|
this.repoConfigs = parsed;
|
|
|
|
|
|
} else if (parsed && Array.isArray(parsed.repos)) {
|
|
|
|
|
|
this.repoConfigs = parsed.repos;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.repoConfigs = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('加载仓库配置失败:', error);
|
|
|
|
|
|
vscode.window.showErrorMessage('读取仓库配置文件失败(dcsp-repos.json),请检查文件格式。');
|
|
|
|
|
|
this.repoConfigs = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async ensureRepoConfigFileExists(): Promise<void> {
|
|
|
|
|
|
const configPath = this.getRepoConfigPath();
|
|
|
|
|
|
if (!fs.existsSync(configPath)) {
|
|
|
|
|
|
const defaultContent = JSON.stringify(
|
|
|
|
|
|
{
|
|
|
|
|
|
repos: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'example-repo',
|
|
|
|
|
|
url: 'https://github.com/username/repo.git',
|
|
|
|
|
|
username: '',
|
|
|
|
|
|
password: ''
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
null,
|
|
|
|
|
|
2
|
|
|
|
|
|
);
|
|
|
|
|
|
await fs.promises.writeFile(configPath, defaultContent, 'utf8');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async openRepoConfig(): Promise<void> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await this.ensureRepoConfigFileExists();
|
|
|
|
|
|
const configPath = this.getRepoConfigPath();
|
|
|
|
|
|
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(configPath));
|
|
|
|
|
|
await vscode.window.showTextDocument(doc);
|
|
|
|
|
|
await this.loadRepoConfigs();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`打开仓库配置文件失败: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async openRepoSelect(): Promise<void> {
|
|
|
|
|
|
await this.loadRepoConfigs();
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.repoConfigs || this.repoConfigs.length === 0) {
|
|
|
|
|
|
vscode.window.showWarningMessage('尚未配置任何仓库,请先点击右上角 “仓库配置” 按钮编辑 dcsp-repos.json。');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.isWebviewDisposed) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 仅传递仓库名给前端,用于下拉选择
|
|
|
|
|
|
this.panel.webview.postMessage({
|
|
|
|
|
|
type: 'showRepoSelect',
|
|
|
|
|
|
repos: this.repoConfigs.map(r => ({ name: r.name }))
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async handleRepoSelectedForBranches(repoName: string): Promise<void> {
|
2025-12-02 14:48:30 +08:00
|
|
|
|
await this.loadRepoConfigs();
|
|
|
|
|
|
const repo = this.repoConfigs.find(r => r.name === repoName);
|
|
|
|
|
|
|
|
|
|
|
|
if (!repo) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`在仓库配置中未找到名为 "${repoName}" 的仓库,请检查 dcsp-repos.json。`);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
|
// 1️⃣ 新逻辑:Local 上传(pendingUploadFolderId 不为空)
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
|
if (this.pendingUploadFolderId) {
|
|
|
|
|
|
const localFolderId = this.pendingUploadFolderId;
|
|
|
|
|
|
this.pendingUploadFolderId = null; // 必须清空,避免影响其他操作
|
|
|
|
|
|
|
|
|
|
|
|
console.log("🚀 Local 上传流程:repo =", repoName, "folderId =", localFolderId);
|
|
|
|
|
|
|
|
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === localFolderId);
|
|
|
|
|
|
if (!folder) {
|
|
|
|
|
|
vscode.window.showErrorMessage("未找到要上传的本地模块文件夹");
|
2025-12-02 12:52:41 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 14:48:30 +08:00
|
|
|
|
// 生成本地路径
|
|
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (!fullPath) {
|
|
|
|
|
|
vscode.window.showErrorMessage("无法确定本地模块文件夹路径");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 自动从本地文件夹名生成分支名
|
|
|
|
|
|
const branchName = path.basename(fullPath);
|
|
|
|
|
|
console.log("🌿 自动生成分支名:", branchName);
|
|
|
|
|
|
|
|
|
|
|
|
// 正式执行上传
|
|
|
|
|
|
await this.uploadLocalModuleFolder(localFolderId, repo.url, branchName);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
2025-12-02 12:52:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 14:48:30 +08:00
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
|
// 2️⃣ 旧逻辑:获取分支
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
|
this.currentRepoForBranches = repo;
|
|
|
|
|
|
await this.fetchBranchesForRepo(repo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// Webview 消息处理
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
2025-11-18 09:10:47 +08:00
|
|
|
|
private setupMessageListener() {
|
2025-11-21 16:07:48 +08:00
|
|
|
|
this.panel.webview.onDidReceiveMessage(async (data) => {
|
2025-11-24 17:53:48 +08:00
|
|
|
|
console.log('📨 收到Webview消息:', data);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
|
|
|
|
|
if (this.isWebviewDisposed) {
|
|
|
|
|
|
console.log('⚠️ Webview 已被销毁,忽略消息');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await this.handleWebviewMessage(data);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('处理 Webview 消息时出错:', error);
|
|
|
|
|
|
if (!this.isWebviewDisposed) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`处理操作时出错: ${error}`);
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleWebviewMessage(data: any): Promise<void> {
|
|
|
|
|
|
const messageHandlers: { [key: string]: (data: any) => Promise<void> } = {
|
|
|
|
|
|
// 导航相关
|
|
|
|
|
|
'openExistingProject': () => this.openExistingProject(),
|
|
|
|
|
|
'configureProject': (data) => this.handleConfigureProject(data),
|
|
|
|
|
|
'openProject': (data) => this.handleOpenProject(data),
|
|
|
|
|
|
'openAircraftConfig': (data) => this.handleOpenAircraftConfig(data),
|
|
|
|
|
|
'openContainerConfig': (data) => this.handleOpenContainerConfig(data),
|
|
|
|
|
|
'goBackToProjects': () => this.handleGoBackToProjects(),
|
|
|
|
|
|
'goBackToAircrafts': () => this.handleGoBackToAircrafts(),
|
|
|
|
|
|
'goBackToContainers': () => this.handleGoBackToContainers(),
|
|
|
|
|
|
|
|
|
|
|
|
// 项目管理
|
|
|
|
|
|
'updateProjectName': (data) => this.updateProjectName(data.projectId, data.name),
|
|
|
|
|
|
'createProject': (data) => this.createProject(data.name),
|
|
|
|
|
|
'deleteProject': (data) => this.deleteProject(data.projectId),
|
|
|
|
|
|
|
|
|
|
|
|
// 飞行器管理
|
|
|
|
|
|
'updateAircraftName': (data) => this.updateAircraftName(data.aircraftId, data.name),
|
|
|
|
|
|
'createAircraft': (data) => this.createAircraft(data.name),
|
|
|
|
|
|
'deleteAircraft': (data) => this.deleteAircraft(data.aircraftId),
|
|
|
|
|
|
|
|
|
|
|
|
// 容器管理
|
|
|
|
|
|
'updateContainerName': (data) => this.updateContainerName(data.containerId, data.name),
|
|
|
|
|
|
'createContainer': (data) => this.createContainer(data.name),
|
|
|
|
|
|
'deleteContainer': (data) => this.deleteContainer(data.containerId),
|
|
|
|
|
|
|
|
|
|
|
|
// 配置管理
|
|
|
|
|
|
'updateConfigName': (data) => this.updateConfigName(data.configId, data.name),
|
|
|
|
|
|
'createConfig': (data) => this.createConfig(data.name),
|
|
|
|
|
|
'deleteConfig': (data) => this.deleteConfig(data.configId),
|
|
|
|
|
|
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
|
|
|
|
|
'mergeConfigs': (data) => this.mergeConfigs(data.configIds, data.displayName, data.folderName),
|
|
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
// Git 仓库管理(新:基于配置)
|
|
|
|
|
|
'openRepoConfig': () => this.openRepoConfig(),
|
|
|
|
|
|
'openRepoSelect': () => this.openRepoSelect(),
|
|
|
|
|
|
'repoSelectedForBranches': (data) => this.handleRepoSelectedForBranches(data.repoName),
|
|
|
|
|
|
|
|
|
|
|
|
// Git 仓库管理(老接口:为了兼容,仍然保留)
|
2025-11-28 19:42:59 +08:00
|
|
|
|
'fetchBranches': (data) => this.fetchBranches(data.url),
|
2025-12-02 12:52:41 +08:00
|
|
|
|
'cloneBranches': (data) => this.cloneBranches(data.branches),
|
2025-11-28 19:42:59 +08:00
|
|
|
|
'cancelBranchSelection': () => this.handleCancelBranchSelection(),
|
|
|
|
|
|
|
|
|
|
|
|
// 模块文件夹管理
|
|
|
|
|
|
'loadModuleFolder': (data) => this.loadModuleFolder(data.folderId),
|
|
|
|
|
|
'syncGitModuleFolder': (data) => this.syncGitModuleFolder(data.folderId),
|
|
|
|
|
|
'deleteModuleFolder': (data) => this.deleteModuleFolder(data.folderId),
|
|
|
|
|
|
'importGitFile': (data) => this.importGitFile(data.filePath),
|
|
|
|
|
|
'openTheModuleFolder': (data) => this.openTheModuleFolder(data.moduleType, data.id),
|
2025-12-02 14:48:30 +08:00
|
|
|
|
'renameModuleFolder': (data) => this.renameModuleFolder(data.folderId, data.newName),
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
|
|
|
|
|
// 上传功能
|
|
|
|
|
|
'uploadGitModuleFolder': (data) => this.uploadGitModuleFolder(data.folderId, data.username, data.password),
|
2025-12-02 14:48:30 +08:00
|
|
|
|
'openRepoSelectForUpload': (data) => this.handleOpenRepoSelectForUpload(data.folderId),
|
2025-11-28 19:42:59 +08:00
|
|
|
|
'uploadLocalModuleFolder': (data) => this.uploadLocalModuleFolder(data.folderId, data.repoUrl, data.branchName)
|
|
|
|
|
|
};
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const handler = messageHandlers[data.type];
|
|
|
|
|
|
if (handler) {
|
|
|
|
|
|
await handler(data);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.warn(`未知的消息类型: ${data.type}`);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 导航处理方法
|
|
|
|
|
|
// =============================================
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleConfigureProject(data: any): Promise<void> {
|
|
|
|
|
|
const selectedPath = await this.selectProjectPath(data.projectId, data.projectName);
|
|
|
|
|
|
if (selectedPath) {
|
|
|
|
|
|
this.currentView = 'aircrafts';
|
|
|
|
|
|
this.currentProjectId = data.projectId;
|
|
|
|
|
|
this.updateWebview();
|
2025-11-24 17:53:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleOpenProject(data: any): Promise<void> {
|
|
|
|
|
|
this.currentView = 'aircrafts';
|
|
|
|
|
|
this.currentProjectId = data.projectId;
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleOpenAircraftConfig(data: any): Promise<void> {
|
|
|
|
|
|
this.currentView = 'containers';
|
|
|
|
|
|
this.currentProjectId = data.projectId;
|
|
|
|
|
|
this.currentAircraftId = data.aircraftId;
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleOpenContainerConfig(data: any): Promise<void> {
|
|
|
|
|
|
this.currentView = 'configs';
|
|
|
|
|
|
this.currentContainerId = data.containerId;
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleGoBackToProjects(): Promise<void> {
|
|
|
|
|
|
this.currentView = 'projects';
|
|
|
|
|
|
this.currentProjectId = '';
|
|
|
|
|
|
this.currentAircraftId = '';
|
|
|
|
|
|
this.currentContainerId = '';
|
|
|
|
|
|
this.currentModuleFolderId = '';
|
|
|
|
|
|
this.updateWebview();
|
2025-11-24 17:53:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleGoBackToAircrafts(): Promise<void> {
|
|
|
|
|
|
this.currentView = 'aircrafts';
|
|
|
|
|
|
this.currentAircraftId = '';
|
|
|
|
|
|
this.currentContainerId = '';
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleGoBackToContainers(): Promise<void> {
|
|
|
|
|
|
this.currentView = 'containers';
|
|
|
|
|
|
this.currentContainerId = '';
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async handleCancelBranchSelection(): Promise<void> {
|
|
|
|
|
|
console.log('❌ 取消分支选择');
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 项目管理方法
|
|
|
|
|
|
// =============================================
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async updateProjectName(projectId: string, newName: string): Promise<void> {
|
|
|
|
|
|
const project = this.projects.find(p => p.id === projectId);
|
|
|
|
|
|
if (project) {
|
|
|
|
|
|
project.name = newName;
|
|
|
|
|
|
vscode.window.showInformationMessage(`项目名称更新: ${newName}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
2025-11-28 14:16:19 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async createProject(name: string): Promise<void> {
|
|
|
|
|
|
const newId = this.generateUniqueId('p', this.projects);
|
|
|
|
|
|
const newProject: Project = {
|
|
|
|
|
|
id: newId,
|
|
|
|
|
|
name: name
|
|
|
|
|
|
};
|
|
|
|
|
|
this.projects.push(newProject);
|
|
|
|
|
|
|
|
|
|
|
|
this.currentProjectId = newId;
|
|
|
|
|
|
|
|
|
|
|
|
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async deleteProject(projectId: string): Promise<void> {
|
|
|
|
|
|
const project = this.projects.find(p => p.id === projectId);
|
|
|
|
|
|
if (!project) return;
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.projects = this.projects.filter(p => p.id !== projectId);
|
|
|
|
|
|
|
|
|
|
|
|
const relatedAircrafts = this.aircrafts.filter(a => a.projectId === projectId);
|
|
|
|
|
|
const aircraftIds = relatedAircrafts.map(a => a.id);
|
2025-11-28 14:16:19 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
|
|
|
|
|
this.containers = this.containers.filter(c => !aircraftIds.includes(c.aircraftId));
|
|
|
|
|
|
|
|
|
|
|
|
const containerIds = this.containers.filter(c => aircraftIds.includes(c.aircraftId)).map(c => c.id);
|
|
|
|
|
|
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
|
|
|
|
|
this.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
2025-11-28 14:16:19 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.projectPaths.delete(projectId);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
vscode.window.showInformationMessage(`删除项目: ${project.name}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
// 飞行器管理方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private async updateAircraftName(aircraftId: string, newName: string): Promise<void> {
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
|
|
|
|
|
if (aircraft) {
|
|
|
|
|
|
aircraft.name = newName;
|
|
|
|
|
|
vscode.window.showInformationMessage(`飞行器名称更新: ${newName}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async createAircraft(name: string): Promise<void> {
|
|
|
|
|
|
if (!this.currentProjectId) {
|
|
|
|
|
|
vscode.window.showErrorMessage('无法创建飞行器:未找到当前项目');
|
2025-11-28 14:16:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const newId = this.generateUniqueId('a', this.aircrafts);
|
|
|
|
|
|
const newAircraft: Aircraft = {
|
|
|
|
|
|
id: newId,
|
|
|
|
|
|
name: name,
|
|
|
|
|
|
projectId: this.currentProjectId
|
2025-11-28 14:16:19 +08:00
|
|
|
|
};
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.aircrafts.push(newAircraft);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await this.createAircraftDirectory(newAircraft);
|
|
|
|
|
|
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async deleteAircraft(aircraftId: string): Promise<void> {
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
|
|
|
|
|
|
if (!aircraft) return;
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.aircrafts = this.aircrafts.filter(a => a.id !== aircraftId);
|
|
|
|
|
|
this.containers = this.containers.filter(c => c.aircraftId !== aircraftId);
|
|
|
|
|
|
|
|
|
|
|
|
const containerIds = this.containers.filter(c => c.aircraftId === aircraftId).map(c => c.id);
|
|
|
|
|
|
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
|
|
|
|
|
this.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
vscode.window.showInformationMessage(`删除飞行器: ${aircraft.name}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 容器管理方法
|
|
|
|
|
|
// =============================================
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async updateContainerName(containerId: string, newName: string): Promise<void> {
|
|
|
|
|
|
const container = this.containers.find(c => c.id === containerId);
|
|
|
|
|
|
if (container) {
|
|
|
|
|
|
container.name = newName;
|
|
|
|
|
|
vscode.window.showInformationMessage(`容器名称更新: ${newName}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-28 14:16:19 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async createContainer(name: string): Promise<void> {
|
|
|
|
|
|
if (!this.currentAircraftId) {
|
|
|
|
|
|
vscode.window.showErrorMessage('无法创建容器:未找到当前飞行器');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const newId = this.generateUniqueId('c', this.containers);
|
|
|
|
|
|
const newContainer: Container = {
|
|
|
|
|
|
id: newId,
|
|
|
|
|
|
name: name,
|
|
|
|
|
|
aircraftId: this.currentAircraftId
|
|
|
|
|
|
};
|
|
|
|
|
|
this.containers.push(newContainer);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await this.createContainerDirectory(newContainer);
|
|
|
|
|
|
await this.createDefaultConfigs(newContainer);
|
|
|
|
|
|
|
|
|
|
|
|
vscode.window.showInformationMessage(`新建容器: ${name} (包含2个默认配置文件)`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
2025-11-25 21:13:41 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async deleteContainer(containerId: string): Promise<void> {
|
|
|
|
|
|
const container = this.containers.find(c => c.id === containerId);
|
|
|
|
|
|
if (!container) return;
|
2025-11-28 14:16:19 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.containers = this.containers.filter(c => c.id !== containerId);
|
|
|
|
|
|
this.configs = this.configs.filter(cfg => cfg.containerId !== containerId);
|
|
|
|
|
|
this.moduleFolders = this.moduleFolders.filter(folder => folder.containerId !== containerId);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
vscode.window.showInformationMessage(`删除容器: ${container.name}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
2025-11-24 17:53:48 +08:00
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 配置管理方法
|
|
|
|
|
|
// =============================================
|
2025-11-27 22:04:32 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async updateConfigName(configId: string, newName: string): Promise<void> {
|
|
|
|
|
|
const config = this.configs.find(c => c.id === configId);
|
|
|
|
|
|
if (config) {
|
|
|
|
|
|
config.name = newName;
|
|
|
|
|
|
vscode.window.showInformationMessage(`配置名称更新: ${newName}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
2025-11-24 17:53:48 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async createConfig(name: string): Promise<void> {
|
|
|
|
|
|
const newId = this.generateUniqueId('cfg', this.configs);
|
|
|
|
|
|
const newConfig: Config = {
|
|
|
|
|
|
id: newId,
|
|
|
|
|
|
name: name,
|
|
|
|
|
|
fileName: name.toLowerCase().replace(/\s+/g, '_'),
|
|
|
|
|
|
content: `# ${name} 配置文件\n# 创建时间: ${new Date().toLocaleString()}\n# 您可以在此编辑配置内容\n\n`,
|
|
|
|
|
|
containerId: this.currentContainerId
|
|
|
|
|
|
};
|
|
|
|
|
|
this.configs.push(newConfig);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await this.ensureContainerDirectoryExists(this.currentContainerId);
|
|
|
|
|
|
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
2025-11-18 09:10:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 14:48:30 +08:00
|
|
|
|
private async handleOpenRepoSelectForUpload(folderId: string): Promise<void> {
|
|
|
|
|
|
console.log("📌 Local 上传:收到 openRepoSelectForUpload,folderId =", folderId);
|
|
|
|
|
|
this.pendingUploadFolderId = folderId;
|
|
|
|
|
|
|
|
|
|
|
|
// 复用你现有的仓库选择弹窗
|
|
|
|
|
|
await this.openRepoSelect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async deleteConfig(configId: string): Promise<void> {
|
|
|
|
|
|
const config = this.configs.find(c => c.id === configId);
|
|
|
|
|
|
if (!config) return;
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-25 21:13:41 +08:00
|
|
|
|
const confirm = await vscode.window.showWarningMessage(
|
2025-11-28 19:42:59 +08:00
|
|
|
|
`确定要删除配置文件 "${config.name}" 吗?这将同时删除磁盘上的文件。`,
|
2025-11-25 21:13:41 +08:00
|
|
|
|
{ modal: true },
|
|
|
|
|
|
'确定删除',
|
|
|
|
|
|
'取消'
|
|
|
|
|
|
);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (confirm !== '确定删除') {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-25 21:13:41 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
try {
|
|
|
|
|
|
this.configs = this.configs.filter(c => c.id !== configId);
|
|
|
|
|
|
await this.deleteConfigFileFromDisk(config);
|
|
|
|
|
|
|
|
|
|
|
|
vscode.window.showInformationMessage(`删除配置: ${config.name}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
this.updateWebview();
|
2025-11-25 21:13:41 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`删除配置文件失败: ${error}`);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async mergeConfigs(configIds: string[], displayName: string, folderName: string): Promise<void> {
|
|
|
|
|
|
if (!this.currentContainerId) {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到当前容器');
|
2025-11-25 14:30:54 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (configIds.length < 2) {
|
|
|
|
|
|
vscode.window.showErrorMessage('请至少选择两个配置文件进行合并');
|
2025-11-25 14:30:54 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const container = this.containers.find(c => c.id === this.currentContainerId);
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container!.aircraftId);
|
|
|
|
|
|
const projectPath = this.projectPaths.get(aircraft!.projectId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!container || !aircraft || !projectPath) {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到相关项目数据');
|
|
|
|
|
|
return;
|
2025-11-27 22:04:32 +08:00
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const selectedConfigs = this.configs.filter(config => configIds.includes(config.id));
|
|
|
|
|
|
if (selectedConfigs.length !== configIds.length) {
|
|
|
|
|
|
vscode.window.showErrorMessage('部分配置文件未找到');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const mergeFolderPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
|
|
|
|
|
await fs.promises.mkdir(mergeFolderPath, { recursive: true });
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
for (const config of selectedConfigs) {
|
|
|
|
|
|
const sourcePath = path.join(projectPath, aircraft.name, container.name, config.fileName);
|
|
|
|
|
|
const targetPath = path.join(mergeFolderPath, config.fileName);
|
|
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(sourcePath)) {
|
|
|
|
|
|
await fs.promises.copyFile(sourcePath, targetPath);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
await fs.promises.writeFile(targetPath, config.content || '');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
|
|
|
|
|
const newId = this.generateUniqueId('local-', this.moduleFolders);
|
|
|
|
|
|
const newFolder: ModuleFolder = {
|
|
|
|
|
|
id: newId,
|
|
|
|
|
|
name: displayName,
|
|
|
|
|
|
type: 'local',
|
|
|
|
|
|
localPath: relativePath,
|
|
|
|
|
|
containerId: this.currentContainerId
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.moduleFolders.push(newFolder);
|
|
|
|
|
|
|
|
|
|
|
|
for (const configId of configIds) {
|
|
|
|
|
|
await this.deleteConfigInternal(configId);
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
vscode.window.showInformationMessage(`成功合并 ${selectedConfigs.length} 个配置文件到文件夹: ${folderName}`);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
this.updateWebview();
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
2025-11-25 14:30:54 +08:00
|
|
|
|
} catch (error) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error('❌ 合并配置文件失败:', error);
|
|
|
|
|
|
vscode.window.showErrorMessage(`合并配置文件失败: ${error}`);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// Git 分支管理方法
|
|
|
|
|
|
// =============================================
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
private async fetchBranchesForRepo(repo: RepoConfigItem): Promise<void> {
|
|
|
|
|
|
await this.fetchBranches(repo.url, repo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async fetchBranches(url: string, repo?: RepoConfigItem): Promise<void> {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
try {
|
|
|
|
|
|
console.log('🌿 开始获取分支列表:', url);
|
|
|
|
|
|
|
|
|
|
|
|
await vscode.window.withProgress({
|
|
|
|
|
|
location: vscode.ProgressLocation.Notification,
|
|
|
|
|
|
title: '正在获取分支信息',
|
|
|
|
|
|
cancellable: false
|
|
|
|
|
|
}, async (progress) => {
|
|
|
|
|
|
progress.report({ increment: 0, message: '连接远程仓库...' });
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
try {
|
|
|
|
|
|
progress.report({ increment: 30, message: '获取远程引用...' });
|
2025-12-02 12:52:41 +08:00
|
|
|
|
|
|
|
|
|
|
const options: any = {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
http: http,
|
|
|
|
|
|
url: url
|
2025-12-02 12:52:41 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (repo && (repo.username || repo.password)) {
|
|
|
|
|
|
options.onAuth = () => ({
|
|
|
|
|
|
username: repo.username || '',
|
|
|
|
|
|
password: repo.password || ''
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const refs = await git.listServerRefs(options);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.log('📋 获取到的引用:', refs);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
const branchRefs = refs.filter((ref: any) =>
|
2025-11-28 19:42:59 +08:00
|
|
|
|
ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/')
|
|
|
|
|
|
);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
const branches: GitBranch[] = branchRefs.map((ref: any) => {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
let branchName: string;
|
|
|
|
|
|
|
|
|
|
|
|
if (ref.ref.startsWith('refs/remotes/')) {
|
|
|
|
|
|
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
branchName = ref.ref.replace('refs/heads/', '');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
name: branchName,
|
|
|
|
|
|
isCurrent: branchName === 'main' || branchName === 'master',
|
|
|
|
|
|
selected: false
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (branches.length === 0) {
|
|
|
|
|
|
throw new Error('未找到任何分支');
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
progress.report({ increment: 80, message: '处理分支数据...' });
|
2025-11-27 22:04:32 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const branchTree = this.buildBranchTree(branches);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!this.isWebviewDisposed) {
|
|
|
|
|
|
this.panel.webview.postMessage({
|
|
|
|
|
|
type: 'branchesFetched',
|
|
|
|
|
|
branches: branches,
|
|
|
|
|
|
branchTree: branchTree,
|
2025-12-02 12:52:41 +08:00
|
|
|
|
repoUrl: url,
|
|
|
|
|
|
repoName: repo?.name
|
2025-11-28 19:42:59 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
progress.report({ increment: 100, message: '完成' });
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('❌ 使用 listServerRefs 获取分支失败:', error);
|
|
|
|
|
|
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error('❌ 获取分支失败:', error);
|
|
|
|
|
|
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
private async cloneBranches(branches: string[]): Promise<void> {
|
|
|
|
|
|
if (!this.currentRepoForBranches) {
|
|
|
|
|
|
vscode.window.showErrorMessage('请先通过“获取仓库”选择一个仓库');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const url = this.currentRepoForBranches.url;
|
|
|
|
|
|
const repoDisplayName = this.currentRepoForBranches.name;
|
|
|
|
|
|
|
2025-11-18 21:14:10 +08:00
|
|
|
|
try {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.log('🚀 开始克隆分支:', { url, branches });
|
|
|
|
|
|
|
|
|
|
|
|
let successCount = 0;
|
|
|
|
|
|
let failCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
await vscode.window.withProgress({
|
|
|
|
|
|
location: vscode.ProgressLocation.Notification,
|
|
|
|
|
|
title: `正在克隆 ${branches.length} 个分支`,
|
|
|
|
|
|
cancellable: false
|
|
|
|
|
|
}, async (progress) => {
|
|
|
|
|
|
for (let i = 0; i < branches.length; i++) {
|
|
|
|
|
|
const branch = branches[i];
|
|
|
|
|
|
const progressPercent = (i / branches.length) * 100;
|
|
|
|
|
|
progress.report({
|
|
|
|
|
|
increment: progressPercent,
|
|
|
|
|
|
message: `克隆分支: ${branch} (${i + 1}/${branches.length})`
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`📥 开始克隆分支: ${branch}`);
|
|
|
|
|
|
try {
|
|
|
|
|
|
const folderNames = this.generateModuleFolderName(url, branch);
|
2025-12-02 12:52:41 +08:00
|
|
|
|
await this.addGitModuleFolder(url, repoDisplayName, folderNames.folderName, branch);
|
2025-11-28 19:42:59 +08:00
|
|
|
|
successCount++;
|
|
|
|
|
|
console.log(`✅ 分支克隆成功: ${branch}`);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
failCount++;
|
|
|
|
|
|
console.error(`❌ 分支克隆失败: ${branch}`, error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-18 21:14:10 +08:00
|
|
|
|
});
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
|
|
|
|
|
if (failCount === 0) {
|
|
|
|
|
|
vscode.window.showInformationMessage(`成功克隆 ${successCount} 个分支`);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
vscode.window.showWarningMessage(`克隆完成: ${successCount} 个成功, ${failCount} 个失败`);
|
2025-11-18 21:14:10 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
2025-11-18 21:14:10 +08:00
|
|
|
|
} catch (error) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error('❌ 克隆分支失败:', error);
|
|
|
|
|
|
vscode.window.showErrorMessage(`克隆分支失败: ${error}`);
|
2025-11-18 21:14:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 模块文件夹管理方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private async addGitModuleFolder(url: string, displayName: string, folderName: string, branch?: string): Promise<void> {
|
2025-11-27 22:04:32 +08:00
|
|
|
|
try {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!url || !url.startsWith('http')) {
|
|
|
|
|
|
vscode.window.showErrorMessage('请输入有效的 Git 仓库 URL');
|
2025-11-27 22:04:32 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-21 16:07:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!this.currentContainerId) {
|
|
|
|
|
|
vscode.window.showErrorMessage('请先选择容器');
|
2025-11-27 22:04:32 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const container = this.containers.find(c => c.id === this.currentContainerId);
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container!.aircraftId);
|
|
|
|
|
|
const projectPath = this.projectPaths.get(aircraft!.projectId);
|
2025-11-21 16:07:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!container || !aircraft || !projectPath) {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到相关项目数据');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const folderId = this.generateUniqueId('git-', this.moduleFolders);
|
|
|
|
|
|
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
|
|
|
|
|
const localPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
2025-11-27 22:04:32 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.log(`📁 准备克隆仓库: ${displayName}, 分支: ${branch}, 路径: ${localPath}`);
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const existingFolder = this.moduleFolders.find(folder =>
|
|
|
|
|
|
folder.localPath === relativePath && folder.containerId === this.currentContainerId
|
|
|
|
|
|
);
|
|
|
|
|
|
if (existingFolder) {
|
|
|
|
|
|
vscode.window.showWarningMessage(`该路径的模块文件夹已存在: ${folderName}`);
|
|
|
|
|
|
return;
|
2025-11-27 22:04:32 +08:00
|
|
|
|
}
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const newFolder: ModuleFolder = {
|
|
|
|
|
|
id: folderId,
|
|
|
|
|
|
name: displayName,
|
|
|
|
|
|
type: 'git',
|
|
|
|
|
|
localPath: relativePath,
|
|
|
|
|
|
containerId: this.currentContainerId
|
|
|
|
|
|
};
|
2025-11-27 22:04:32 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await vscode.window.withProgress({
|
|
|
|
|
|
location: vscode.ProgressLocation.Notification,
|
|
|
|
|
|
title: `正在克隆仓库: ${displayName}`,
|
|
|
|
|
|
cancellable: false
|
|
|
|
|
|
}, async (progress) => {
|
|
|
|
|
|
progress.report({ increment: 0 });
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const parentDir = path.dirname(localPath);
|
|
|
|
|
|
await fs.promises.mkdir(parentDir, { recursive: true });
|
2025-11-27 20:10:09 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
let dirExists = false;
|
|
|
|
|
|
try {
|
|
|
|
|
|
await fs.promises.access(localPath);
|
|
|
|
|
|
dirExists = true;
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
dirExists = false;
|
|
|
|
|
|
}
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (dirExists) {
|
|
|
|
|
|
const dirContents = await fs.promises.readdir(localPath);
|
|
|
|
|
|
if (dirContents.length > 0) {
|
|
|
|
|
|
const confirm = await vscode.window.showWarningMessage(
|
|
|
|
|
|
`目标目录 "${folderName}" 不为空,确定要覆盖吗?`,
|
|
|
|
|
|
{ modal: true },
|
|
|
|
|
|
'确定覆盖',
|
|
|
|
|
|
'取消'
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (confirm !== '确定覆盖') {
|
|
|
|
|
|
vscode.window.showInformationMessage('克隆操作已取消');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
for (const item of dirContents) {
|
|
|
|
|
|
const itemPath = path.join(localPath, item);
|
|
|
|
|
|
if (item !== '.git') {
|
|
|
|
|
|
await fs.promises.rm(itemPath, { recursive: true, force: true });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-18 14:03:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.log(`🚀 开始克隆: ${url} -> ${localPath}, 分支: ${branch}`);
|
2025-11-18 14:03:22 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await git.clone({
|
|
|
|
|
|
fs: fs,
|
|
|
|
|
|
http: http,
|
|
|
|
|
|
dir: localPath,
|
|
|
|
|
|
url: url,
|
|
|
|
|
|
singleBranch: true,
|
|
|
|
|
|
depth: 1,
|
|
|
|
|
|
ref: branch || 'main',
|
|
|
|
|
|
onProgress: (event: any) => {
|
|
|
|
|
|
console.log(`📊 克隆进度: ${event.phase} - ${event.loaded}/${event.total}`);
|
|
|
|
|
|
if (event.total) {
|
|
|
|
|
|
const percent = (event.loaded / event.total) * 100;
|
|
|
|
|
|
progress.report({
|
|
|
|
|
|
increment: percent,
|
|
|
|
|
|
message: `${event.phase}... (${Math.round(percent)}%)`
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
progress.report({ message: `${event.phase}...` });
|
2025-11-18 21:14:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
});
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.log('✅ Git克隆成功完成');
|
|
|
|
|
|
|
|
|
|
|
|
const clonedContents = await fs.promises.readdir(localPath);
|
|
|
|
|
|
console.log(`📁 克隆后的目录内容:`, clonedContents);
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (clonedContents.length === 0) {
|
|
|
|
|
|
throw new Error('克隆后目录为空,可能克隆失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.moduleFolders.push(newFolder);
|
2025-11-21 16:07:48 +08:00
|
|
|
|
await this.saveCurrentProjectData();
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.log('✅ Git模块文件夹数据已保存到项目文件');
|
|
|
|
|
|
|
|
|
|
|
|
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${displayName}`);
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!this.isWebviewDisposed) {
|
|
|
|
|
|
console.log('🌳 开始加载模块文件夹文件树...');
|
|
|
|
|
|
this.currentModuleFolderId = folderId;
|
|
|
|
|
|
await this.loadModuleFolderFileTree(folderId);
|
|
|
|
|
|
console.log('✅ 模块文件夹文件树加载完成');
|
2025-11-18 14:03:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('❌ 在克隆过程中捕获错误:', error);
|
|
|
|
|
|
|
2025-11-18 14:03:22 +08:00
|
|
|
|
try {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (fs.existsSync(localPath)) {
|
|
|
|
|
|
await fs.promises.rm(localPath, { recursive: true, force: true });
|
|
|
|
|
|
console.log('🧹 已清理克隆失败的目录');
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (cleanupError) {
|
|
|
|
|
|
console.error('清理失败目录时出错:', cleanupError);
|
2025-11-18 14:03:22 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
|
|
|
|
|
vscode.window.showErrorMessage(`克隆仓库失败: ${error}`);
|
|
|
|
|
|
throw error;
|
2025-11-18 14:03:22 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-18 14:03:22 +08:00
|
|
|
|
} catch (error) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error('❌ 在addGitModuleFolder外部捕获错误:', error);
|
|
|
|
|
|
vscode.window.showErrorMessage(`添加 Git 模块文件夹失败: ${error}`);
|
2025-11-18 14:03:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async loadModuleFolder(folderId: string): Promise<void> {
|
|
|
|
|
|
this.currentModuleFolderId = folderId;
|
|
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
|
|
|
|
|
if (folder && folder.type === 'git') {
|
|
|
|
|
|
await this.loadModuleFolderFileTree(folderId);
|
2025-11-18 09:10:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async syncGitModuleFolder(folderId: string): Promise<void> {
|
|
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
|
|
|
|
|
if (!folder || folder.type !== 'git') {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到指定的 Git 模块文件夹');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 18:45:30 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (!fullPath) {
|
|
|
|
|
|
vscode.window.showErrorMessage('无法获取模块文件夹的完整路径');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 14:03:22 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await vscode.window.withProgress({
|
|
|
|
|
|
location: vscode.ProgressLocation.Notification,
|
|
|
|
|
|
title: `正在同步仓库: ${folder.name}`,
|
|
|
|
|
|
cancellable: false
|
|
|
|
|
|
}, async (progress) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
progress.report({ increment: 0, message: '拉取最新更改...' });
|
|
|
|
|
|
|
|
|
|
|
|
await git.pull({
|
|
|
|
|
|
fs: fs,
|
|
|
|
|
|
http: http,
|
|
|
|
|
|
dir: fullPath,
|
|
|
|
|
|
author: { name: 'DCSP User', email: 'user@dcsp.local' },
|
|
|
|
|
|
fastForward: true
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await this.loadModuleFolderFileTree(folderId);
|
|
|
|
|
|
vscode.window.showInformationMessage(`Git 仓库同步成功: ${folder.name}`);
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`同步 Git 仓库失败: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-11-18 09:10:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async deleteModuleFolder(folderId: string): Promise<void> {
|
|
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
|
|
|
|
|
if (!folder) return;
|
|
|
|
|
|
|
|
|
|
|
|
const confirm = await vscode.window.showWarningMessage(
|
|
|
|
|
|
`确定要删除模块文件夹 "${folder.name}" 吗?这将删除本地文件。`,
|
|
|
|
|
|
{ modal: true },
|
|
|
|
|
|
'确定删除',
|
|
|
|
|
|
'取消'
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (confirm === '确定删除') {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (fullPath) {
|
|
|
|
|
|
await fs.promises.rm(fullPath, { recursive: true, force: true });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.moduleFolders = this.moduleFolders.filter(f => f.id !== folderId);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
|
|
|
|
|
|
if (this.currentModuleFolderId === folderId) {
|
|
|
|
|
|
this.currentModuleFolderId = '';
|
|
|
|
|
|
this.currentModuleFolderFileTree = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vscode.window.showInformationMessage(`模块文件夹已删除: ${folder.name}`);
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`删除模块文件夹失败: ${error}`);
|
|
|
|
|
|
}
|
2025-11-18 18:45:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async importGitFile(filePath: string): Promise<void> {
|
|
|
|
|
|
if (!this.currentModuleFolderId || !this.currentContainerId) {
|
|
|
|
|
|
vscode.window.showErrorMessage('请先选择模块文件夹和容器');
|
2025-11-18 18:45:30 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === this.currentModuleFolderId);
|
|
|
|
|
|
if (!folder || folder.type !== 'git') {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到当前 Git 模块文件夹');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-25 09:24:31 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const container = this.containers.find(c => c.id === this.currentContainerId);
|
|
|
|
|
|
if (!container) {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到当前容器');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 18:45:30 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (!fullPath) {
|
|
|
|
|
|
vscode.window.showErrorMessage('无法获取模块文件夹路径');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 18:45:30 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const fileFullPath = path.join(fullPath, filePath);
|
|
|
|
|
|
const content = await fs.promises.readFile(fileFullPath, 'utf8');
|
|
|
|
|
|
const fileName = path.basename(filePath);
|
2025-11-18 18:45:30 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const newId = this.generateUniqueId('cfg', this.configs);
|
|
|
|
|
|
const newConfig: Config = {
|
|
|
|
|
|
id: newId,
|
|
|
|
|
|
name: fileName,
|
|
|
|
|
|
fileName: fileName,
|
|
|
|
|
|
content: content,
|
|
|
|
|
|
containerId: this.currentContainerId
|
|
|
|
|
|
};
|
2025-11-18 18:45:30 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.configs.push(newConfig);
|
2025-11-21 16:07:48 +08:00
|
|
|
|
await this.saveCurrentProjectData();
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
|
|
|
|
|
vscode.window.showInformationMessage(`文件已导入到容器 ${container.name}: ${fileName}`);
|
2025-11-18 09:10:47 +08:00
|
|
|
|
this.updateWebview();
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`导入文件失败: ${error}`);
|
2025-11-18 09:10:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 上传功能方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
private async uploadGitModuleFolder(folderId: string, username?: string, password?: string): Promise<void> {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
|
|
|
|
|
if (!folder || folder.type !== 'git') {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到指定的 Git 模块文件夹');
|
2025-11-25 09:24:31 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (!fullPath) {
|
|
|
|
|
|
vscode.window.showErrorMessage('无法获取模块文件夹的完整路径');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await vscode.window.withProgress({
|
|
|
|
|
|
location: vscode.ProgressLocation.Notification,
|
|
|
|
|
|
title: `正在上传 Git 仓库: ${folder.name}`,
|
|
|
|
|
|
cancellable: false
|
|
|
|
|
|
}, async (progress) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
progress.report({ increment: 0, message: '检查更改...' });
|
2025-11-25 09:24:31 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await this.commitAndPushUsingCommandLine(fullPath);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
progress.report({ increment: 100, message: '完成' });
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
folder.uploaded = true;
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
vscode.window.showInformationMessage(`✅ Git 仓库上传成功: ${folder.name}`);
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
} catch (error: any) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error('❌ Git 上传失败:', error);
|
2025-12-02 12:52:41 +08:00
|
|
|
|
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
2025-11-28 19:42:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-11-18 09:10:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async uploadLocalModuleFolder(folderId: string, repoUrl: string, branchName: string): Promise<void> {
|
|
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
|
|
|
|
|
if (!folder || folder.type !== 'local') {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到指定的本地模块文件夹');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 18:45:30 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (!fullPath) {
|
|
|
|
|
|
vscode.window.showErrorMessage('无法获取模块文件夹的完整路径');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await vscode.window.withProgress({
|
|
|
|
|
|
location: vscode.ProgressLocation.Notification,
|
|
|
|
|
|
title: `正在上传本地文件夹到 Git 仓库: ${folder.name}`,
|
|
|
|
|
|
cancellable: false
|
|
|
|
|
|
}, async (progress) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
progress.report({ increment: 0, message: '检查目录...' });
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!fs.existsSync(fullPath)) {
|
|
|
|
|
|
throw new Error('本地文件夹不存在');
|
|
|
|
|
|
}
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
progress.report({ increment: 10, message: '初始化 Git 仓库...' });
|
|
|
|
|
|
await this.initGitRepository(fullPath, branchName);
|
2025-11-25 09:24:31 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
progress.report({ increment: 20, message: '添加远程仓库...' });
|
|
|
|
|
|
await this.addGitRemote(fullPath, repoUrl);
|
2025-11-25 09:24:31 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
progress.report({ increment: 40, message: '提交初始文件...' });
|
|
|
|
|
|
await this.commitInitialFiles(fullPath);
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
progress.report({ increment: 60, message: '推送到远程仓库...' });
|
|
|
|
|
|
await this.pushToRemoteWithForce(fullPath, branchName);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
progress.report({ increment: 100, message: '完成' });
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
folder.type = 'git';
|
|
|
|
|
|
folder.uploaded = true;
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
vscode.window.showInformationMessage(`本地文件夹成功上传到 Git 仓库: ${folder.name} -> ${branchName}`);
|
|
|
|
|
|
this.updateWebview();
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-12-02 12:52:41 +08:00
|
|
|
|
} catch (error: any) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error('❌ 本地文件夹上传失败:', error);
|
2025-12-02 12:52:41 +08:00
|
|
|
|
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const gitDir = path.join(fullPath, '.git');
|
|
|
|
|
|
if (fs.existsSync(gitDir)) {
|
|
|
|
|
|
await fs.promises.rm(gitDir, { recursive: true, force: true });
|
2025-11-25 14:30:54 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
} catch (cleanupError) {
|
|
|
|
|
|
console.error('清理 .git 文件夹失败:', cleanupError);
|
2025-11-25 14:30:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// Git 命令行工具方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private async commitAndPushUsingCommandLine(fullPath: string): Promise<void> {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
|
|
|
|
console.log('🚀 使用命令行 Git 提交并推送...');
|
|
|
|
|
|
console.log(`📁 工作目录: ${fullPath}`);
|
|
|
|
|
|
|
|
|
|
|
|
exec('git status --porcelain', {
|
|
|
|
|
|
cwd: fullPath,
|
|
|
|
|
|
encoding: 'utf8'
|
2025-12-02 12:52:41 +08:00
|
|
|
|
}, (statusError: any, statusStdout: string, statusStderr: string) => {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (statusError) {
|
|
|
|
|
|
console.error('❌ 检查 Git 状态失败:', statusError);
|
|
|
|
|
|
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!statusStdout.trim()) {
|
|
|
|
|
|
console.log('ℹ️ 没有需要提交的更改');
|
|
|
|
|
|
reject(new Error('没有需要提交的更改'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('📋 检测到更改:', statusStdout);
|
|
|
|
|
|
|
|
|
|
|
|
const commands = [
|
|
|
|
|
|
'git add .',
|
|
|
|
|
|
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
|
|
|
|
|
|
'git push'
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
exec(commands.join(' && '), {
|
|
|
|
|
|
cwd: fullPath,
|
|
|
|
|
|
encoding: 'utf8'
|
2025-12-02 12:52:41 +08:00
|
|
|
|
}, (error: any, stdout: string, stderr: string) => {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.log('📋 Git 命令输出:', stdout);
|
|
|
|
|
|
console.log('📋 Git 命令错误:', stderr);
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
console.error('❌ Git 提交/推送失败:', error);
|
|
|
|
|
|
reject(new Error(stderr || error.message));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('✅ Git 提交并推送成功');
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async initGitRepository(fullPath: string, branchName: string): Promise<void> {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
|
|
|
|
console.log('📁 初始化 Git 仓库...');
|
|
|
|
|
|
|
|
|
|
|
|
exec(`git init && git checkout -b ${branchName}`, {
|
|
|
|
|
|
cwd: fullPath,
|
|
|
|
|
|
encoding: 'utf8'
|
2025-12-02 12:52:41 +08:00
|
|
|
|
}, (error: any, stdout: string, stderr: string) => {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (error) {
|
|
|
|
|
|
console.error('❌ Git 初始化失败:', error);
|
|
|
|
|
|
reject(new Error(stderr || error.message));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('✅ Git 初始化成功');
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async addGitRemote(fullPath: string, repoUrl: string): Promise<void> {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
|
|
|
|
console.log('📡 添加远程仓库...');
|
|
|
|
|
|
|
|
|
|
|
|
exec(`git remote add origin ${repoUrl}`, {
|
|
|
|
|
|
cwd: fullPath,
|
|
|
|
|
|
encoding: 'utf8'
|
2025-12-02 12:52:41 +08:00
|
|
|
|
}, (error: any, stdout: string, stderr: string) => {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (error) {
|
|
|
|
|
|
console.error('❌ 添加远程仓库失败:', error);
|
|
|
|
|
|
reject(new Error(stderr || error.message));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('✅ 远程仓库添加成功');
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async commitInitialFiles(fullPath: string): Promise<void> {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
|
|
|
|
console.log('💾 提交初始文件...');
|
|
|
|
|
|
|
|
|
|
|
|
const commands = [
|
|
|
|
|
|
'git add .',
|
2025-12-02 12:52:41 +08:00
|
|
|
|
`git commit -m "Initial commit from DCSP - ${new Date().toLocaleString()}"`,
|
2025-11-28 19:42:59 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
exec(commands.join(' && '), {
|
|
|
|
|
|
cwd: fullPath,
|
|
|
|
|
|
encoding: 'utf8'
|
2025-12-02 12:52:41 +08:00
|
|
|
|
}, (error: any, stdout: string, stderr: string) => {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (error) {
|
|
|
|
|
|
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
|
|
|
|
|
|
console.log('ℹ️ 没有需要提交的更改');
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.error('❌ Git 提交失败:', error);
|
|
|
|
|
|
reject(new Error(stderr || error.message));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('✅ 初始文件提交成功');
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async pushToRemoteWithForce(fullPath: string, branchName: string): Promise<void> {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
|
|
|
|
console.log('🚀 强制推送到远程仓库...');
|
|
|
|
|
|
|
|
|
|
|
|
exec(`git push -u origin ${branchName} --force`, {
|
|
|
|
|
|
cwd: fullPath,
|
|
|
|
|
|
encoding: 'utf8'
|
2025-12-02 12:52:41 +08:00
|
|
|
|
}, (error: any, stdout: string, stderr: string) => {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.log('📋 Git push stdout:', stdout);
|
|
|
|
|
|
console.log('📋 Git push stderr:', stderr);
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
console.error('❌ Git 推送失败:', error);
|
|
|
|
|
|
reject(new Error(stderr || error.message));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('✅ Git 推送成功');
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
// 文件系统操作方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private async createAircraftDirectory(aircraft: Aircraft): Promise<void> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const projectPath = this.projectPaths.get(aircraft.projectId);
|
|
|
|
|
|
if (!projectPath) {
|
|
|
|
|
|
console.warn('未找到项目路径,跳过创建飞行器目录');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
|
|
|
|
|
|
await vscode.workspace.fs.createDirectory(aircraftDir);
|
|
|
|
|
|
console.log(`✅ 创建飞行器目录: ${aircraftDir.fsPath}`);
|
|
|
|
|
|
|
2025-11-25 14:30:54 +08:00
|
|
|
|
} catch (error) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error(`创建飞行器目录失败: ${error}`);
|
2025-11-18 09:10:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async createContainerDirectory(container: Container): Promise<void> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
|
|
|
|
|
if (!aircraft) {
|
|
|
|
|
|
console.warn('未找到对应的飞行器,跳过创建容器目录');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const projectPath = this.projectPaths.get(aircraft.projectId);
|
|
|
|
|
|
if (!projectPath) {
|
|
|
|
|
|
console.warn('未找到项目路径,跳过创建容器目录');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-18 14:03:22 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
|
|
|
|
|
|
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
|
|
|
|
|
|
|
|
|
|
|
|
await vscode.workspace.fs.createDirectory(aircraftDir);
|
|
|
|
|
|
await vscode.workspace.fs.createDirectory(containerDir);
|
|
|
|
|
|
console.log(`✅ 创建容器目录: ${containerDir.fsPath}`);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(`创建容器目录失败: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async ensureContainerDirectoryExists(containerId: string): Promise<void> {
|
2025-11-27 22:04:32 +08:00
|
|
|
|
try {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const container = this.containers.find(c => c.id === containerId);
|
|
|
|
|
|
if (!container) return;
|
|
|
|
|
|
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
|
|
|
|
|
if (!aircraft) return;
|
|
|
|
|
|
|
|
|
|
|
|
const projectPath = this.projectPaths.get(aircraft.projectId);
|
|
|
|
|
|
if (!projectPath) return;
|
|
|
|
|
|
|
|
|
|
|
|
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
|
|
|
|
|
|
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
|
2025-11-27 22:04:32 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
await vscode.workspace.fs.createDirectory(aircraftDir);
|
|
|
|
|
|
await vscode.workspace.fs.createDirectory(containerDir);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(`确保容器目录存在失败: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-18 21:14:10 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async createDefaultConfigs(container: Container): Promise<void> {
|
|
|
|
|
|
this.configs.push({
|
|
|
|
|
|
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
|
|
|
|
|
|
});
|
2025-11-25 14:30:54 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.configs.push({
|
|
|
|
|
|
id: this.generateUniqueId('cfg', this.configs),
|
|
|
|
|
|
name: '配置2',
|
|
|
|
|
|
fileName: 'docker-compose.yml',
|
2025-12-02 12:52:41 +08:00
|
|
|
|
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`,
|
2025-11-28 19:42:59 +08:00
|
|
|
|
containerId: container.id
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-11-18 09:10:47 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async deleteConfigFileFromDisk(config: Config): Promise<void> {
|
|
|
|
|
|
const container = this.containers.find(c => c.id === config.containerId);
|
|
|
|
|
|
if (!container) return;
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
|
|
|
|
|
if (!aircraft) return;
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const projectPath = this.projectPaths.get(aircraft.projectId);
|
|
|
|
|
|
if (!projectPath) return;
|
|
|
|
|
|
|
|
|
|
|
|
const filePath = path.join(projectPath, aircraft.name, container.name, config.fileName);
|
|
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(filePath)) {
|
|
|
|
|
|
await fs.promises.unlink(filePath);
|
|
|
|
|
|
console.log(`✅ 已删除配置文件: ${filePath}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async deleteConfigInternal(configId: string): Promise<void> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const config = this.configs.find(c => c.id === configId);
|
|
|
|
|
|
if (!config) return;
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.configs = this.configs.filter(c => c.id !== configId);
|
|
|
|
|
|
await this.deleteConfigFileFromDisk(config);
|
|
|
|
|
|
console.log(`✅ 内部删除配置: ${config.name}`);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(`删除配置文件失败: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
// 项目数据持久化方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private async saveCurrentProjectData(): Promise<void> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (!this.currentProjectId) {
|
|
|
|
|
|
console.warn('未找到当前项目,数据将不会保存');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const projectPath = this.projectPaths.get(this.currentProjectId);
|
|
|
|
|
|
if (!projectPath) {
|
|
|
|
|
|
console.warn('未找到项目存储路径,数据将不会保存');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
|
|
|
|
|
|
|
|
|
|
|
const data: ProjectData = {
|
2025-12-02 12:52:41 +08:00
|
|
|
|
projects: [this.projects.find(p => p.id === this.currentProjectId)!],
|
2025-11-28 19:42:59 +08:00
|
|
|
|
aircrafts: this.aircrafts.filter(a => a.projectId === this.currentProjectId),
|
|
|
|
|
|
containers: this.containers.filter(c => {
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === c.aircraftId);
|
|
|
|
|
|
return aircraft && aircraft.projectId === this.currentProjectId;
|
|
|
|
|
|
}),
|
|
|
|
|
|
configs: this.configs.filter(cfg => {
|
|
|
|
|
|
const container = this.containers.find(c => c.id === cfg.containerId);
|
|
|
|
|
|
if (!container) return false;
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
|
|
|
|
|
return aircraft && aircraft.projectId === this.currentProjectId;
|
|
|
|
|
|
}),
|
|
|
|
|
|
moduleFolders: this.moduleFolders.filter(folder => {
|
|
|
|
|
|
const container = this.containers.find(c => c.id === folder.containerId);
|
|
|
|
|
|
if (!container) return false;
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
|
|
|
|
|
return aircraft && aircraft.projectId === this.currentProjectId;
|
|
|
|
|
|
})
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
|
|
|
|
|
|
await vscode.workspace.fs.writeFile(dataUri, uint8Array);
|
|
|
|
|
|
|
|
|
|
|
|
console.log('✅ 当前项目数据已保存,包含', data.moduleFolders.length, '个模块文件夹');
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`保存项目数据失败: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async loadProjectData(projectPath: string): Promise<boolean> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
await vscode.workspace.fs.stat(dataUri);
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
vscode.window.showErrorMessage('选择的文件夹中没有找到项目数据文件 (.dcsp-data.json)');
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fileData = await vscode.workspace.fs.readFile(dataUri);
|
|
|
|
|
|
const dataStr = new TextDecoder().decode(fileData);
|
|
|
|
|
|
const data: ProjectData = JSON.parse(dataStr);
|
|
|
|
|
|
|
|
|
|
|
|
const projectId = data.projects[0]?.id;
|
|
|
|
|
|
if (projectId) {
|
|
|
|
|
|
this.projects = this.projects.filter(p => p.id !== projectId);
|
|
|
|
|
|
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
|
|
|
|
|
|
|
|
|
|
|
const aircraftIds = this.aircrafts.filter(a => a.projectId === projectId).map(a => a.id);
|
|
|
|
|
|
this.containers = this.containers.filter(c => !aircraftIds.includes(c.aircraftId));
|
|
|
|
|
|
|
|
|
|
|
|
const containerIds = this.containers.filter(c => aircraftIds.includes(c.aircraftId)).map(c => c.id);
|
|
|
|
|
|
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
|
|
|
|
|
this.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
|
|
|
|
|
|
|
|
|
|
|
this.projects.push(...data.projects);
|
|
|
|
|
|
this.aircrafts.push(...data.aircrafts);
|
|
|
|
|
|
this.containers.push(...data.containers);
|
|
|
|
|
|
this.configs.push(...data.configs);
|
|
|
|
|
|
this.moduleFolders.push(...data.moduleFolders);
|
|
|
|
|
|
|
|
|
|
|
|
this.currentProjectId = projectId;
|
|
|
|
|
|
this.projectPaths.set(projectId, projectPath);
|
|
|
|
|
|
this.currentView = 'aircrafts';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${data.moduleFolders.length} 个模块文件夹`);
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`加载项目数据失败: ${error}`);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async checkProjectPathHasData(projectPath: string): Promise<boolean> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
|
|
|
|
|
await vscode.workspace.fs.stat(dataUri);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
// 项目路径选择方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private async openExistingProject(): Promise<void> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const result = await vscode.window.showOpenDialog({
|
|
|
|
|
|
canSelectFiles: false,
|
|
|
|
|
|
canSelectFolders: true,
|
|
|
|
|
|
canSelectMany: false,
|
|
|
|
|
|
openLabel: '选择项目文件夹',
|
|
|
|
|
|
title: '选择包含项目数据的文件夹'
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (result && result.length > 0) {
|
|
|
|
|
|
const selectedPath = result[0].fsPath;
|
|
|
|
|
|
await this.loadProjectData(selectedPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`打开项目时出错: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async selectProjectPath(projectId: string, projectName: string): Promise<string | null> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const choice = await vscode.window.showQuickPick(
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '$(folder) 选择现有文件夹',
|
|
|
|
|
|
description: '从文件系统中选择已存在的文件夹',
|
|
|
|
|
|
value: 'select'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '$(new-folder) 创建新文件夹',
|
|
|
|
|
|
description: '输入新文件夹路径(将自动创建)',
|
|
|
|
|
|
value: 'create'
|
2025-11-27 22:04:32 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
],
|
|
|
|
|
|
{
|
|
|
|
|
|
placeHolder: '选择项目存储方式'
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!choice) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (choice.value === 'select') {
|
|
|
|
|
|
return await this.selectExistingProjectPath(projectId, projectName);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return await this.createNewProjectPath(projectId, projectName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`选择存储路径时出错: ${error}`);
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-27 18:34:57 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async selectExistingProjectPath(projectId: string, projectName: string): Promise<string | null> {
|
|
|
|
|
|
const result = await vscode.window.showOpenDialog({
|
|
|
|
|
|
canSelectFiles: false,
|
|
|
|
|
|
canSelectFolders: true,
|
|
|
|
|
|
canSelectMany: false,
|
|
|
|
|
|
openLabel: `选择 ${projectName} 的存储位置`,
|
|
|
|
|
|
title: `为项目 "${projectName}" 选择存储文件夹`
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (result && result.length > 0) {
|
|
|
|
|
|
const selectedPath = result[0].fsPath;
|
|
|
|
|
|
|
|
|
|
|
|
const hasExistingData = await this.checkProjectPathHasData(selectedPath);
|
|
|
|
|
|
if (hasExistingData) {
|
|
|
|
|
|
const loadChoice = await vscode.window.showWarningMessage(
|
|
|
|
|
|
`在路径 ${selectedPath} 中检测到现有项目数据,是否加载?`,
|
|
|
|
|
|
{ modal: true },
|
|
|
|
|
|
'是,加载现有数据',
|
|
|
|
|
|
'否,创建新项目'
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (loadChoice === '是,加载现有数据') {
|
|
|
|
|
|
const success = await this.loadProjectData(selectedPath);
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
this.projectPaths.set(projectId, selectedPath);
|
|
|
|
|
|
this.currentView = 'aircrafts';
|
|
|
|
|
|
this.currentProjectId = projectId;
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
vscode.window.showInformationMessage(`项目数据已从 ${selectedPath} 加载`);
|
|
|
|
|
|
return selectedPath;
|
2025-11-27 22:04:32 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.projectPaths.set(projectId, selectedPath);
|
|
|
|
|
|
vscode.window.showInformationMessage(`项目存储位置已设置: ${selectedPath}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
return selectedPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2025-11-27 18:34:57 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async createNewProjectPath(projectId: string, projectName: string): Promise<string | null> {
|
|
|
|
|
|
const pathInput = await vscode.window.showInputBox({
|
|
|
|
|
|
prompt: '请输入项目存储路径(绝对路径)',
|
|
|
|
|
|
placeHolder: `/path/to/your/project/${projectName}`,
|
|
|
|
|
|
validateInput: (value) => {
|
|
|
|
|
|
if (!value) {
|
|
|
|
|
|
return '路径不能为空';
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (pathInput) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const dirUri = vscode.Uri.file(pathInput);
|
|
|
|
|
|
await vscode.workspace.fs.createDirectory(dirUri);
|
|
|
|
|
|
|
|
|
|
|
|
this.projectPaths.set(projectId, pathInput);
|
|
|
|
|
|
vscode.window.showInformationMessage(`项目存储位置已创建: ${pathInput}`);
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
return pathInput;
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage(`创建目录失败: ${error}`);
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
// 文件树和模块文件夹方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
|
|
|
|
|
private async loadModuleFolderFileTree(folderId: string): Promise<void> {
|
|
|
|
|
|
if (this.isWebviewDisposed) {
|
|
|
|
|
|
console.log('⚠️ Webview 已被销毁,跳过文件树加载');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
|
|
|
|
|
if (!folder) return;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
this.panel.webview.postMessage({
|
|
|
|
|
|
type: 'moduleFolderLoading',
|
|
|
|
|
|
loading: true
|
|
|
|
|
|
});
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.log('⚠️ 无法发送加载消息,Webview 可能已被销毁');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (fullPath) {
|
|
|
|
|
|
const fileTree = await this.buildFileTree(fullPath);
|
|
|
|
|
|
this.currentModuleFolderFileTree = fileTree;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('加载模块文件夹文件树失败:', error);
|
|
|
|
|
|
this.currentModuleFolderFileTree = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.isWebviewDisposed) {
|
|
|
|
|
|
console.log('⚠️ Webview 已被销毁,跳过完成通知');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
this.panel.webview.postMessage({
|
|
|
|
|
|
type: 'moduleFolderLoading',
|
|
|
|
|
|
loading: false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.log('⚠️ 无法发送完成消息,Webview 可能已被销毁');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async buildFileTree(dir: string, relativePath: string = ''): Promise<GitFileTree[]> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const files = await fs.promises.readdir(dir);
|
|
|
|
|
|
const tree: GitFileTree[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (const file of files) {
|
|
|
|
|
|
if (file.startsWith('.') && file !== '.git') continue;
|
|
|
|
|
|
if (file === '.dcsp-data.json') continue;
|
|
|
|
|
|
|
|
|
|
|
|
const filePath = path.join(dir, file);
|
|
|
|
|
|
const stats = await fs.promises.stat(filePath);
|
|
|
|
|
|
const currentRelativePath = path.join(relativePath, file);
|
|
|
|
|
|
|
|
|
|
|
|
if (stats.isDirectory()) {
|
|
|
|
|
|
const children = await this.buildFileTree(filePath, currentRelativePath);
|
|
|
|
|
|
tree.push({
|
|
|
|
|
|
name: file,
|
|
|
|
|
|
type: 'folder',
|
|
|
|
|
|
path: currentRelativePath,
|
|
|
|
|
|
children: children
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tree.push({
|
|
|
|
|
|
name: file,
|
|
|
|
|
|
type: 'file',
|
|
|
|
|
|
path: currentRelativePath
|
|
|
|
|
|
});
|
2025-11-27 22:04:32 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
}
|
2025-11-27 18:34:57 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
return tree;
|
2025-11-27 22:04:32 +08:00
|
|
|
|
} catch (error) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error('构建文件树失败:', error);
|
|
|
|
|
|
return [];
|
2025-11-27 22:04:32 +08:00
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
}
|
2025-11-27 18:34:57 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// 工具方法
|
|
|
|
|
|
// =============================================
|
|
|
|
|
|
|
2025-11-27 22:04:32 +08:00
|
|
|
|
private buildBranchTree(branches: GitBranch[]): any[] {
|
|
|
|
|
|
const root: any[] = [];
|
2025-11-27 18:34:57 +08:00
|
|
|
|
|
2025-11-27 22:04:32 +08:00
|
|
|
|
branches.forEach(branch => {
|
|
|
|
|
|
const parts = branch.name.split('/');
|
|
|
|
|
|
let currentLevel = root;
|
2025-11-27 18:34:57 +08:00
|
|
|
|
|
2025-11-27 22:04:32 +08:00
|
|
|
|
for (let i = 0; i < parts.length; i++) {
|
|
|
|
|
|
const part = parts[i];
|
|
|
|
|
|
const isLeaf = i === parts.length - 1;
|
|
|
|
|
|
const fullName = parts.slice(0, i + 1).join('/');
|
|
|
|
|
|
|
|
|
|
|
|
let node = currentLevel.find((n: any) => n.name === part);
|
|
|
|
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
|
|
node = {
|
|
|
|
|
|
name: part,
|
|
|
|
|
|
fullName: fullName,
|
|
|
|
|
|
isLeaf: isLeaf,
|
|
|
|
|
|
children: [],
|
|
|
|
|
|
level: i,
|
2025-11-28 19:42:59 +08:00
|
|
|
|
expanded: true
|
2025-11-27 22:04:32 +08:00
|
|
|
|
};
|
|
|
|
|
|
currentLevel.push(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isLeaf) {
|
|
|
|
|
|
node.branch = branch;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
currentLevel = node.children;
|
2025-11-27 18:34:57 +08:00
|
|
|
|
}
|
2025-11-27 22:04:32 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return root;
|
|
|
|
|
|
}
|
2025-11-24 17:53:48 +08:00
|
|
|
|
|
2025-11-28 14:16:19 +08:00
|
|
|
|
private generateModuleFolderName(url: string, branch: string): { displayName: string; folderName: string } {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const repoName = url.split('/').pop()?.replace('.git', '') || 'unknown-repo';
|
|
|
|
|
|
const branchSafeName = branch.replace(/[^a-zA-Z0-9-_]/g, '-');
|
2025-11-27 22:04:32 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
return {
|
|
|
|
|
|
displayName: repoName,
|
|
|
|
|
|
folderName: branchSafeName
|
|
|
|
|
|
};
|
2025-11-25 16:32:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private getModuleFolderFullPath(folder: ModuleFolder): string | null {
|
|
|
|
|
|
const container = this.containers.find(c => c.id === folder.containerId);
|
|
|
|
|
|
if (!container) return null;
|
2025-11-25 16:32:06 +08:00
|
|
|
|
|
2025-11-25 21:13:41 +08:00
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!aircraft) return null;
|
2025-11-27 20:10:09 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const projectPath = this.projectPaths.get(aircraft.projectId);
|
|
|
|
|
|
if (!projectPath) return null;
|
2025-11-27 20:10:09 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const pathParts = folder.localPath.split('/').filter(part => part);
|
|
|
|
|
|
if (pathParts.length < 4) return null;
|
2025-11-27 20:10:09 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const folderName = pathParts[pathParts.length - 1];
|
|
|
|
|
|
return path.join(projectPath, aircraft.name, container.name, folderName);
|
2025-11-27 20:10:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private async openConfigFileInVSCode(configId: string): Promise<void> {
|
|
|
|
|
|
const config = this.configs.find(c => c.id === configId);
|
|
|
|
|
|
if (!config) {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到配置文件');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const container = this.containers.find(c => c.id === config.containerId);
|
|
|
|
|
|
const aircraft = this.aircrafts.find(a => a.id === container!.aircraftId);
|
|
|
|
|
|
const projectPath = this.projectPaths.get(aircraft!.projectId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!container || !aircraft || !projectPath) {
|
|
|
|
|
|
vscode.window.showErrorMessage('未设置项目存储路径');
|
2025-11-27 20:10:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const filePath = path.join(projectPath, aircraft.name, container.name, config.fileName);
|
|
|
|
|
|
|
2025-11-27 22:04:32 +08:00
|
|
|
|
try {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
if (!fs.existsSync(filePath)) {
|
|
|
|
|
|
vscode.window.showWarningMessage('配置文件不存在,将创建新文件');
|
|
|
|
|
|
const dirPath = path.dirname(filePath);
|
|
|
|
|
|
await fs.promises.mkdir(dirPath, { recursive: true });
|
|
|
|
|
|
await fs.promises.writeFile(filePath, config.content || '');
|
2025-11-27 22:04:32 +08:00
|
|
|
|
}
|
2025-11-27 20:10:09 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const document = await vscode.workspace.openTextDocument(filePath);
|
|
|
|
|
|
await vscode.window.showTextDocument(document);
|
|
|
|
|
|
|
2025-11-27 22:04:32 +08:00
|
|
|
|
} catch (error) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
vscode.window.showErrorMessage(`打开配置文件失败: ${error}`);
|
2025-11-27 22:04:32 +08:00
|
|
|
|
}
|
2025-11-27 20:10:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 14:16:19 +08:00
|
|
|
|
private async openTheModuleFolder(type: 'git' | 'local', id: string): Promise<void> {
|
2025-11-27 22:04:32 +08:00
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === id);
|
|
|
|
|
|
if (!folder) {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到指定的模块文件夹');
|
2025-11-27 20:10:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-27 20:22:29 +08:00
|
|
|
|
try {
|
2025-11-27 22:04:32 +08:00
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (!fullPath || !fs.existsSync(fullPath)) {
|
|
|
|
|
|
vscode.window.showErrorMessage('模块文件夹目录不存在');
|
2025-11-27 20:22:29 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-27 20:10:09 +08:00
|
|
|
|
|
2025-11-27 20:22:29 +08:00
|
|
|
|
const fileUri = await vscode.window.showOpenDialog({
|
2025-11-27 22:04:32 +08:00
|
|
|
|
defaultUri: vscode.Uri.file(fullPath),
|
2025-11-27 20:22:29 +08:00
|
|
|
|
canSelectFiles: true,
|
|
|
|
|
|
canSelectFolders: false,
|
|
|
|
|
|
canSelectMany: false,
|
|
|
|
|
|
openLabel: '选择要打开的文件',
|
2025-11-27 22:04:32 +08:00
|
|
|
|
title: `在 ${folder.name} 中选择文件`
|
2025-11-27 20:22:29 +08:00
|
|
|
|
});
|
2025-11-27 20:10:09 +08:00
|
|
|
|
|
2025-11-27 20:22:29 +08:00
|
|
|
|
if (fileUri && fileUri.length > 0) {
|
|
|
|
|
|
const document = await vscode.workspace.openTextDocument(fileUri[0]);
|
|
|
|
|
|
await vscode.window.showTextDocument(document);
|
|
|
|
|
|
vscode.window.showInformationMessage(`已打开文件: ${path.basename(fileUri[0].fsPath)}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2025-11-27 22:04:32 +08:00
|
|
|
|
vscode.window.showErrorMessage(`打开模块文件夹文件失败: ${error}`);
|
2025-11-27 20:22:29 +08:00
|
|
|
|
}
|
2025-11-27 20:10:09 +08:00
|
|
|
|
}
|
2025-11-27 22:04:32 +08:00
|
|
|
|
|
2025-12-02 14:48:30 +08:00
|
|
|
|
private async renameModuleFolder(folderId: string, newName: string): Promise<void> {
|
|
|
|
|
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
|
|
|
|
|
if (!folder) {
|
|
|
|
|
|
vscode.window.showErrorMessage('未找到模块文件夹');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const oldName = folder.localPath.split('/').pop();
|
|
|
|
|
|
if (!oldName) return;
|
|
|
|
|
|
|
|
|
|
|
|
const fullPath = this.getModuleFolderFullPath(folder);
|
|
|
|
|
|
if (!fullPath) return;
|
|
|
|
|
|
|
|
|
|
|
|
const newFullPath = path.join(path.dirname(fullPath), newName);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
await fs.promises.rename(fullPath, newFullPath);
|
|
|
|
|
|
|
|
|
|
|
|
// 更新 localPath
|
|
|
|
|
|
folder.localPath = folder.localPath.replace(/\/[^/]+$/, '/' + newName);
|
|
|
|
|
|
|
|
|
|
|
|
await this.saveCurrentProjectData();
|
|
|
|
|
|
|
|
|
|
|
|
vscode.window.showInformationMessage(`已重命名文件夹: ${oldName} → ${newName}`);
|
|
|
|
|
|
|
|
|
|
|
|
this.updateWebview();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
vscode.window.showErrorMessage('重命名失败: ' + error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
// =============================================
|
|
|
|
|
|
// Webview 更新方法
|
|
|
|
|
|
// =============================================
|
2025-11-28 16:54:23 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private updateWebview() {
|
|
|
|
|
|
if (this.isWebviewDisposed) {
|
|
|
|
|
|
console.log('⚠️ Webview 已被销毁,跳过更新');
|
|
|
|
|
|
return;
|
2025-11-28 16:21:12 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
|
2025-11-28 16:21:12 +08:00
|
|
|
|
try {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
this.panel.webview.html = this.getWebviewContent();
|
2025-11-28 16:21:12 +08:00
|
|
|
|
} catch (error) {
|
2025-11-28 19:42:59 +08:00
|
|
|
|
console.error('更新 Webview 失败:', error);
|
2025-11-28 16:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
private getWebviewContent(): string {
|
|
|
|
|
|
switch (this.currentView) {
|
|
|
|
|
|
case 'projects':
|
|
|
|
|
|
return this.projectView.render({
|
|
|
|
|
|
projects: this.projects,
|
|
|
|
|
|
projectPaths: this.projectPaths
|
|
|
|
|
|
});
|
|
|
|
|
|
case 'aircrafts':
|
|
|
|
|
|
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
|
|
|
|
|
return this.aircraftView.render({
|
|
|
|
|
|
aircrafts: projectAircrafts
|
|
|
|
|
|
});
|
|
|
|
|
|
case 'containers':
|
|
|
|
|
|
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
|
|
|
|
|
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
|
|
|
|
|
|
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
2025-11-28 16:21:12 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
return this.containerView.render({
|
|
|
|
|
|
project: currentProject,
|
|
|
|
|
|
aircraft: currentAircraft,
|
|
|
|
|
|
containers: projectContainers
|
|
|
|
|
|
});
|
|
|
|
|
|
case 'configs':
|
|
|
|
|
|
const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
|
|
|
|
|
|
const currentModuleFolder = this.moduleFolders.find(f => f.id === this.currentModuleFolderId);
|
2025-12-02 12:52:41 +08:00
|
|
|
|
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
2025-11-28 19:42:59 +08:00
|
|
|
|
const containerModuleFolders = this.moduleFolders.filter(folder => folder.containerId === this.currentContainerId);
|
2025-11-28 16:54:23 +08:00
|
|
|
|
|
2025-11-28 19:42:59 +08:00
|
|
|
|
return this.configView.render({
|
|
|
|
|
|
container: currentContainer,
|
|
|
|
|
|
configs: containerConfigs,
|
|
|
|
|
|
moduleFolders: containerModuleFolders,
|
|
|
|
|
|
currentModuleFolder: currentModuleFolder,
|
|
|
|
|
|
moduleFolderFileTree: this.currentModuleFolderFileTree,
|
|
|
|
|
|
moduleFolderLoading: false
|
|
|
|
|
|
});
|
|
|
|
|
|
default:
|
|
|
|
|
|
return this.projectView.render({
|
|
|
|
|
|
projects: this.projects,
|
|
|
|
|
|
projectPaths: this.projectPaths
|
|
|
|
|
|
});
|
2025-11-28 16:54:23 +08:00
|
|
|
|
}
|
2025-11-28 19:42:59 +08:00
|
|
|
|
}
|
2025-12-02 12:52:41 +08:00
|
|
|
|
}
|