|
1 |
| -// The module 'vscode' contains the VS Code extensibility API |
2 |
| -// Import the module and reference it with the alias vscode in your code below |
3 | 1 | import * as vscode from 'vscode';
|
| 2 | +import * as cp from 'child_process'; |
| 3 | +import * as fs from 'fs'; |
| 4 | +import { IValidationProvider } from './validationProvider/validationProvider'; |
| 5 | +import { TomlValidationProvider } from './validationProvider/tomlValidationProvider'; |
| 6 | +import { ICodexProvider } from './CodexProvider/codexProvider'; |
| 7 | +import { GithubCodexProvider } from './CodexProvider/GithubCodexProvider'; |
| 8 | +import { ENARX_TOML_EXAMPLE } from './EnarxTomlExample'; |
4 | 9 |
|
5 |
| -// this method is called when your extension is activated |
6 |
| -// your extension is activated the very first time the command is executed |
7 |
| -export function activate(context: vscode.ExtensionContext) { |
8 |
| - |
9 |
| - // Use the console to output diagnostic information (console.log) and errors (console.error) |
10 |
| - // This line of code will only be executed once when your extension is activated |
11 |
| - console.log('Congratulations, your extension "vscode-enarx" is now active!'); |
12 | 10 |
|
13 |
| - // The command has been defined in the package.json file |
14 |
| - // Now provide the implementation of the command with registerCommand |
15 |
| - // The commandId parameter must match the command field in package.json |
16 |
| - let disposable = vscode.commands.registerCommand('vscode-enarx.helloWorld', () => { |
17 |
| - // The code you place here will be executed every time your command is executed |
18 |
| - // Display a message box to the user |
19 |
| - vscode.window.showInformationMessage('Hello World from vscode-enarx!'); |
| 11 | +export function activate(context: vscode.ExtensionContext) { |
| 12 | + let scafoldEnarxToml = vscode.commands.registerCommand('vscode-enarx.scafoldEnarxToml', () => { |
| 13 | + if (vscode.workspace.workspaceFolders) { |
| 14 | + try { |
| 15 | + fs.writeFileSync(`${vscode.workspace.workspaceFolders[0].uri.fsPath}/Enarx.toml`, ENARX_TOML_EXAMPLE); |
| 16 | + } catch (e) { |
| 17 | + vscode.window.showErrorMessage("We couldn't create an Enarx.toml file at the workspace location", "Ok"); |
| 18 | + } |
| 19 | + } else { |
| 20 | + vscode.window.showErrorMessage('We couldn\'t create a Enarx.toml since you are working outside any workspace.'); |
| 21 | + } |
20 | 22 | });
|
21 |
| - |
22 |
| - context.subscriptions.push(disposable); |
| 23 | + let enarxTomlValidation = vscode.commands.registerCommand('vscode-enarx.enarxTomlValidation', () => { |
| 24 | + if (vscode.workspace.workspaceFolders) { |
| 25 | + let workspacePath = vscode.workspace.workspaceFolders[0].uri.path; |
| 26 | + let exarxTomlPath = `${workspacePath}/Enarx.toml`; |
| 27 | + let validationProvider: IValidationProvider = new TomlValidationProvider(); |
| 28 | + let result = validationProvider.validate(exarxTomlPath); |
| 29 | + if (result[0] && result[1] === null) { |
| 30 | + vscode.window.showInformationMessage(`Enarx.toml is correct!`); |
| 31 | + } else { |
| 32 | + result[1]?.forEach(err => { |
| 33 | + vscode.window.showErrorMessage(`Enarx.toml Validation error: ${err}`); |
| 34 | + }); |
| 35 | + } |
| 36 | + } |
| 37 | + }); |
| 38 | + let enarxCodex = vscode.commands.registerCommand('vscode-enarx.codexPull', async () => { |
| 39 | + let codex: ICodexProvider = new GithubCodexProvider(); |
| 40 | + let s = await codex.getCodexRepos(); |
| 41 | + let selectedRepo = await vscode.window.showQuickPick(s.map(v => ({ label: v } as vscode.QuickPickItem))); |
| 42 | + if (selectedRepo) { |
| 43 | + if (vscode.workspace.workspaceFolders && (process.platform === 'linux' || process.platform === 'darwin')) { |
| 44 | + vscode.window.showInformationMessage("Pulling code for: " + selectedRepo.label); |
| 45 | + try { |
| 46 | + const commandToExtract = `curl https://codeload.github.com/enarx/codex/tar.gz/refs/heads/main | tar -zx --directory ${vscode.workspace.workspaceFolders[0].uri.fsPath} ./codex-main/${selectedRepo.label}`; |
| 47 | + cp.execSync(commandToExtract); |
| 48 | + cp.execSync(`mv ${vscode.workspace.workspaceFolders[0].uri.fsPath}/codex-main/${selectedRepo.label}/* ${vscode.workspace.workspaceFolders[0].uri.fsPath}`); |
| 49 | + cp.execSync(`rm -rf ${vscode.workspace.workspaceFolders[0].uri.fsPath}/codex-main`); |
| 50 | + vscode.window.showInformationMessage(`Workspace ready with ${selectedRepo.label}`); |
| 51 | + } catch (e) { |
| 52 | + vscode.window.showInformationMessage("Oops! we can't automatically setup the workspace for you.", "Configure Manually", "Do it later").then(select => { |
| 53 | + if (select === 'Configure Manually') { |
| 54 | + vscode.env.openExternal(vscode.Uri.parse(`https://github.com/enarx/codex/tree/main/${selectedRepo?.label}`)); |
| 55 | + } |
| 56 | + }); |
| 57 | + } |
| 58 | + } else { |
| 59 | + vscode.window.showInformationMessage("Oops! we can't automatically setup the workspace for you.", "Configure Manually", "Do it later").then(select => { |
| 60 | + if (select === 'Configure Manually') { |
| 61 | + vscode.env.openExternal(vscode.Uri.parse(`https://github.com/enarx/codex/tree/main/${selectedRepo?.label}`)); |
| 62 | + } |
| 63 | + }); |
| 64 | + } |
| 65 | + } |
| 66 | + }); |
| 67 | + context.subscriptions.push(scafoldEnarxToml, enarxCodex, enarxTomlValidation); |
23 | 68 | }
|
24 | 69 |
|
25 | 70 | // this method is called when your extension is deactivated
|
26 |
| -export function deactivate() {} |
| 71 | +export function deactivate() { } |
0 commit comments