Skip to content

Commit 047f0d4

Browse files
committed
feat: VS Code extension scaffolding
- Started extensions/vscode directory - Created package.json with commands (up, down, checkStatus) - Implemented extension.ts to call 'cm' binary - Added basic TreeView scaffolding for Environments and Services - Configured launch.json and tsconfig.json
1 parent fa9ac59 commit 047f0d4

3 files changed

Lines changed: 233 additions & 0 deletions

File tree

extensions/vscode/package.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"name": "container-maker-vscode",
3+
"displayName": "Container Maker",
4+
"description": "Industrial-grade Development Environment Orchestration",
5+
"version": "0.1.0",
6+
"publisher": "ContainerMaker",
7+
"engines": {
8+
"vscode": "^1.80.0"
9+
},
10+
"categories": [
11+
"Other"
12+
],
13+
"activationEvents": [
14+
"onCommand:container-maker.helloWorld",
15+
"onView:containerMaker"
16+
],
17+
"main": "./out/extension.js",
18+
"contributes": {
19+
"commands": [
20+
{
21+
"command": "container-maker.checkStatus",
22+
"title": "CM: Check Status"
23+
},
24+
{
25+
"command": "container-maker.up",
26+
"title": "CM: Workspace Up"
27+
},
28+
{
29+
"command": "container-maker.down",
30+
"title": "CM: Workspace Down"
31+
}
32+
],
33+
"viewsContainers": {
34+
"activitybar": [
35+
{
36+
"id": "container-maker",
37+
"title": "Container Maker",
38+
"icon": "resources/icon.svg"
39+
}
40+
]
41+
},
42+
"views": {
43+
"container-maker": [
44+
{
45+
"id": "cmEnvironments",
46+
"name": "Environments"
47+
},
48+
{
49+
"id": "cmServices",
50+
"name": "Workspace Services"
51+
}
52+
]
53+
},
54+
"configuration": {
55+
"title": "Container Maker",
56+
"properties": {
57+
"containerMaker.executablePath": {
58+
"type": "string",
59+
"default": "cm",
60+
"description": "Path to the cm executable"
61+
}
62+
}
63+
}
64+
},
65+
"scripts": {
66+
"vscode:prepublish": "npm run compile",
67+
"compile": "tsc -p ./",
68+
"watch": "tsc -watch -p ./",
69+
"pretest": "npm run compile && npm run lint",
70+
"lint": "eslint src --ext ts",
71+
"test": "node ./out/test/runTest.js"
72+
},
73+
"devDependencies": {
74+
"@types/vscode": "^1.80.0",
75+
"@types/glob": "^8.1.0",
76+
"@types/mocha": "^10.0.1",
77+
"@types/node": "20.2.5",
78+
"@typescript-eslint/eslint-plugin": "^5.59.8",
79+
"@typescript-eslint/parser": "^5.59.8",
80+
"eslint": "^8.41.0",
81+
"glob": "^8.1.0",
82+
"mocha": "^10.2.0",
83+
"typescript": "^5.1.3",
84+
"@vscode/test-electron": "^2.3.2"
85+
}
86+
}

extensions/vscode/src/extension.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import * as vscode from 'vscode';
2+
import * as cp from 'child_process';
3+
import * as path from 'path';
4+
5+
// Output channel for logging
6+
let outputChannel: vscode.OutputChannel;
7+
8+
export function activate(context: vscode.ExtensionContext) {
9+
outputChannel = vscode.window.createOutputChannel("Container Maker");
10+
outputChannel.appendLine('Container Maker extension is now active!');
11+
12+
// Register commands
13+
context.subscriptions.push(
14+
vscode.commands.registerCommand('container-maker.checkStatus', checkStatus),
15+
vscode.commands.registerCommand('container-maker.up', workspaceUp),
16+
vscode.commands.registerCommand('container-maker.down', workspaceDown)
17+
);
18+
19+
// Register Tree Data Providers (Scaffolding)
20+
const envProvider = new EnvironmentProvider();
21+
vscode.window.registerTreeDataProvider('cmEnvironments', envProvider);
22+
23+
const svcProvider = new ServiceProvider();
24+
vscode.window.registerTreeDataProvider('cmServices', svcProvider);
25+
}
26+
27+
export function deactivate() { }
28+
29+
// --- Commands ---
30+
31+
async function checkStatus() {
32+
const result = await runCMCommand('env status');
33+
if (result) {
34+
outputChannel.show(true);
35+
outputChannel.appendLine(result);
36+
}
37+
}
38+
39+
async function workspaceUp() {
40+
vscode.window.withProgress({
41+
location: vscode.ProgressLocation.Notification,
42+
title: "Starting Workspace...",
43+
cancellable: false
44+
}, async (progress) => {
45+
try {
46+
const result = await runCMCommand('up -d');
47+
vscode.window.showInformationMessage('Workspace started successfully');
48+
outputChannel.appendLine(result || '');
49+
} catch (error) {
50+
vscode.window.showErrorMessage(`Failed to start workspace: ${error}`);
51+
}
52+
});
53+
}
54+
55+
async function workspaceDown() {
56+
const answer = await vscode.window.showWarningMessage(
57+
"Are you sure you want to stop the workspace?",
58+
"Yes", "No"
59+
);
60+
61+
if (answer === "Yes") {
62+
await runCMCommand('down');
63+
vscode.window.showInformationMessage('Workspace stopped');
64+
}
65+
}
66+
67+
// --- Helper Functions ---
68+
69+
function getCMPath(): string {
70+
const config = vscode.workspace.getConfiguration('containerMaker');
71+
return config.get('executablePath') || 'cm';
72+
}
73+
74+
function runCMCommand(args: string): Promise<string> {
75+
return new Promise((resolve, reject) => {
76+
const cmPath = getCMPath();
77+
const rootPath = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
78+
const cwd = rootPath || process.cwd();
79+
80+
const cmd = `"${cmPath}" ${args}`;
81+
outputChannel.appendLine(`> Executing: ${cmd} in ${cwd}`);
82+
83+
cp.exec(cmd, { cwd }, (err, stdout, stderr) => {
84+
if (err) {
85+
outputChannel.appendLine(`Error: ${err.message}`);
86+
outputChannel.appendLine(`Stderr: ${stderr}`);
87+
reject(stderr || err.message);
88+
return;
89+
}
90+
resolve(stdout);
91+
});
92+
});
93+
}
94+
95+
// --- Tree View Scaffolding ---
96+
97+
class EnvironmentProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
98+
getTreeItem(element: vscode.TreeItem): vscode.TreeItem {
99+
return element;
100+
}
101+
102+
getChildren(element?: vscode.TreeItem): Thenable<vscode.TreeItem[]> {
103+
// Mock data for scaffolding
104+
if (!element) {
105+
return Promise.resolve([
106+
new vscode.TreeItem("Dev Environment", vscode.TreeItemCollapsibleState.None),
107+
new vscode.TreeItem("Staging Environment", vscode.TreeItemCollapsibleState.None)
108+
]);
109+
}
110+
return Promise.resolve([]);
111+
}
112+
}
113+
114+
class ServiceProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
115+
getTreeItem(element: vscode.TreeItem): vscode.TreeItem {
116+
return element;
117+
}
118+
119+
getChildren(element?: vscode.TreeItem): Thenable<vscode.TreeItem[]> {
120+
// Mock data for scaffolding
121+
if (!element) {
122+
return Promise.resolve([
123+
new vscode.TreeItem("frontend (Node.js)", vscode.TreeItemCollapsibleState.None),
124+
new vscode.TreeItem("backend (Go)", vscode.TreeItemCollapsibleState.None),
125+
new vscode.TreeItem("database (Postgres)", vscode.TreeItemCollapsibleState.None)
126+
]);
127+
}
128+
return Promise.resolve([]);
129+
}
130+
}

extensions/vscode/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"outDir": "out",
6+
"lib": [
7+
"es6"
8+
],
9+
"sourceMap": true,
10+
"rootDir": "src",
11+
"strict": true
12+
},
13+
"exclude": [
14+
"node_modules",
15+
".vscode-test"
16+
]
17+
}

0 commit comments

Comments
 (0)