|
| 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() {} |
0 commit comments