Skip to content

Commit 912a1b2

Browse files
committed
Init
1 parent 98d898f commit 912a1b2

6 files changed

Lines changed: 182 additions & 0 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "Node.js 22 & TypeScript ESM",
3+
"containerEnv": {
4+
"NODE_ENV": "development"
5+
},
6+
"image": "node:22",
7+
8+
"mounts": [
9+
{
10+
"type": "volume",
11+
"target": "${containerWorkspaceFolder}/node_modules"
12+
},
13+
{
14+
"type": "volume",
15+
"target": "${containerWorkspaceFolder}/build"
16+
}
17+
],
18+
"customizations": {
19+
"vscode": {
20+
"extensions": [
21+
"dbaeumer.vscode-eslint",
22+
"esbenp.prettier-vscode"
23+
]
24+
}
25+
},
26+
"postCreateCommand": "npm install"
27+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vscode/
2+
node_modules/
3+
4+
build/

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "vs-code-new-package-extension",
3+
"displayName": "VS-Code New Package Extension",
4+
"description": "Adds a 'New Package...' option to the VS Code Explorer context menu to create a folder with an index.ts file.",
5+
"version": "0.0.1",
6+
"type": "module",
7+
"engines": {
8+
"vscode": "^1.85.0"
9+
},
10+
"categories": [
11+
"Other"
12+
],
13+
"main": "./build/extension.js",
14+
"contributes": {
15+
"commands": [
16+
{
17+
"command": "new-package-extension.createPackage",
18+
"title": "New Package..."
19+
}
20+
],
21+
"menus": {
22+
"explorer/context": [
23+
{
24+
"command": "new-package-extension.createPackage",
25+
"group": "navigation@2",
26+
"when": "explorerResourceIsFolder"
27+
}
28+
]
29+
}
30+
},
31+
"scripts": {
32+
"vscode:prepublish": "npm run compile",
33+
"compile": "tsc -p ./",
34+
"watch": "tsc -watch -p ./"
35+
},
36+
"devDependencies": {
37+
"@types/node": "^22.7.4",
38+
"@types/vscode": "^1.85.0",
39+
"typescript": "^5.6.3"
40+
}
41+
}

src/extension.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
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'
14+
});
15+
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);
39+
}
40+
41+
export function deactivate() {}

tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2020",
4+
"target": "es2020",
5+
"outDir": "build",
6+
"rootDir": "src",
7+
"sourceMap": true,
8+
"strict": true,
9+
"moduleResolution": "node"
10+
}
11+
}

0 commit comments

Comments
 (0)