Skip to content

Commit c5942a5

Browse files
committed
Refactor build output to dist and update extension logic
Changed build output directory from 'build' to 'dist' across configuration files and .gitignore. Updated extension command registration, improved package creation logic with async/await and error handling, and added a keybinding. Updated TypeScript configuration for NodeNext modules and ES2022 target.
1 parent 232951b commit c5942a5

File tree

5 files changed

+78
-60
lines changed

5 files changed

+78
-60
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
{
1414
"type": "volume",
15-
"target": "${containerWorkspaceFolder}/build"
15+
"target": "${containerWorkspaceFolder}/dist"
1616
}
1717
],
1818
"customizations": {

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.vscode/
22
node_modules/
33

4-
build/
4+
dist/
55

66
*.vsix

package.json

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,47 @@
55
"version": "0.0.1",
66
"publisher": "Mqxx",
77
"repository": "https://github.com/TypeScriptPlayground/vs-code-new-package-extension",
8-
"type": "module",
98
"engines": {
109
"vscode": "^1.85.0"
1110
},
1211
"categories": [
1312
"Other"
1413
],
15-
"main": "./build/extension.js",
14+
"main": "./dist/extension.js",
15+
"scripts": {
16+
"build": "tsc -p .",
17+
"package": "npm run build && vsce package"
18+
},
1619
"contributes": {
1720
"commands": [
1821
{
19-
"command": "vs-code-new-package-extension.createPackage",
20-
"title": "New Package..."
22+
"command": "extension.newPackage",
23+
"title": "New Package...",
24+
"category": "Explorer"
2125
}
2226
],
2327
"menus": {
2428
"explorer/context": [
2529
{
26-
"command": "vs-code-new-package-extension.createPackage",
27-
"group": "navigation@2",
28-
"when": "explorerResourceIsFolder"
30+
"command": "extension.newPackage",
31+
"when": "explorerResourceIsFolder || explorerViewletVisible",
32+
"group": "navigation@2"
2933
}
3034
]
31-
}
32-
},
33-
"scripts": {
34-
"vscode:prepublish": "npm run compile",
35-
"compile": "tsc -p ./",
36-
"watch": "tsc -watch -p ./",
37-
"package": "vsce package"
35+
},
36+
"keybindings": [
37+
{
38+
"command": "extension.newPackage",
39+
"key": "shift+p",
40+
"when": "explorerViewletVisible"
41+
}
42+
]
3843
},
44+
"type": "module",
3945
"devDependencies": {
40-
"@types/node": "^22.7.4",
46+
"@types/node": "^22.0.0",
4147
"@types/vscode": "^1.85.0",
42-
"typescript": "^5.6.3",
48+
"typescript": "^5.5.4",
4349
"@vscode/vsce": "^2.15.0"
4450
}
4551
}

src/extension.ts

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
11
import * as vscode from 'vscode';
2-
import * as fs from 'fs';
3-
import * as path from 'path';
4-
5-
export function activate(context: vscode.ExtensionContext) {
6-
let disposable = vscode.commands.registerCommand('new-package-extension.createPackage', async (uri: vscode.Uri) => {
7-
// Get the folder path where the context menu was triggered
8-
const folderPath = uri.fsPath;
9-
10-
// Prompt user for the new package folder name
11-
const folderName = await vscode.window.showInputBox({
12-
prompt: 'Enter the name of the new package folder',
13-
placeHolder: 'Package name'
2+
import { mkdir, writeFile } from 'node:fs/promises';
3+
import { join } from 'node:path';
4+
5+
export async function activate(context: vscode.ExtensionContext) {
6+
const disposable = vscode.commands.registerCommand('extension.newPackage', async (uri: vscode.Uri) => {
7+
try {
8+
// Falls kein Ziel gewählt wurde → Arbeitsbereich
9+
let targetDir: string;
10+
if (uri && uri.fsPath) {
11+
targetDir = uri.fsPath;
12+
} else if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
13+
targetDir = vscode.workspace.workspaceFolders[0].uri.fsPath;
14+
} else {
15+
vscode.window.showErrorMessage('No workspace folder open.');
16+
return;
17+
}
18+
19+
// Ordnername erfragen
20+
const folderName = await vscode.window.showInputBox({
21+
prompt: 'Enter the new package name',
22+
placeHolder: 'my-package'
23+
});
24+
25+
if (!folderName) {
26+
return;
27+
}
28+
29+
const packagePath = join(targetDir, folderName);
30+
31+
// Ordner anlegen
32+
await mkdir(packagePath, { recursive: true });
33+
34+
// index.ts anlegen
35+
const indexFilePath = join(packagePath, 'index.ts');
36+
await writeFile(indexFilePath, '', { encoding: 'utf8' });
37+
38+
// Datei im Editor öffnen
39+
const doc = await vscode.workspace.openTextDocument(indexFilePath);
40+
await vscode.window.showTextDocument(doc);
41+
42+
} catch (error) {
43+
vscode.window.showErrorMessage(`Failed to create package: ${String(error)}`);
44+
}
1445
});
1546

16-
if (!folderName) {
17-
vscode.window.showErrorMessage('No folder name provided.');
18-
return;
19-
}
20-
21-
// Create the full path for the new folder
22-
const newFolderPath = path.join(folderPath, folderName);
23-
24-
try {
25-
// Create the new folder
26-
await fs.promises.mkdir(newFolderPath, { recursive: true });
27-
28-
// Create the index.ts file inside the new folder
29-
const indexFilePath = path.join(newFolderPath, 'index.ts');
30-
await fs.promises.writeFile(indexFilePath, '// Index file for the package\n');
31-
32-
vscode.window.showInformationMessage(`Package '${folderName}' created successfully with index.ts`);
33-
} catch (error: any) {
34-
vscode.window.showErrorMessage(`Failed to create package: ${error.message}`);
35-
}
36-
});
37-
38-
context.subscriptions.push(disposable);
47+
context.subscriptions.push(disposable);
3948
}
4049

4150
export function deactivate() {}

tsconfig.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"compilerOptions": {
3-
"module": "es2020",
4-
"target": "es2020",
5-
"outDir": "build",
6-
"rootDir": "src",
7-
"sourceMap": true,
3+
"target": "ES2022",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"outDir": "dist",
7+
"lib": ["ES2022"],
8+
"types": ["node", "vscode"],
89
"strict": true,
9-
"moduleResolution": "node"
10-
}
10+
"esModuleInterop": true,
11+
"skipLibCheck": true
12+
},
13+
"include": ["src"]
1114
}

0 commit comments

Comments
 (0)