Last active
June 28, 2023 07:40
-
-
Save jayu/6d8b32da0f13e0f53e89a9eb73ebaa94 to your computer and use it in GitHub Desktop.
Install vscode extension from vsix file hosted in the internet. It's useful for distributing private, maybe paid version of your free extension.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Uri } from 'vscode' | |
import * as vscode from 'vscode' | |
import fetch from 'node-fetch' | |
export function activate(context: vscode.ExtensionContext) { | |
const installPrivateVersionOfExtension = () => { | |
const fileBlob = await ( | |
// Most likely you want to authenticate user to execute that request | |
await fetch('https://your.server.com/extension.vsix') | |
).blob() | |
const buffer = await fileBlob.arrayBuffer() | |
const storagePath = context.storageUri?.fsPath | |
const fileUri = Uri.file(`${storagePath}/extension.vsix`) | |
await vscode.workspace.fs.writeFile(fileUri, Buffer.from(buffer)) | |
await vscode.commands.executeCommand( | |
'workbench.extensions.installExtension', | |
fileUri, | |
) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment