GithubHelp home page GithubHelp logo

vikramais / vscode-extension-updater Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jan-dolejsi/vscode-extension-updater

0.0 0.0 0.0 421 KB

Visual Studio Code custom extension updater for private extension marketplaces

JavaScript 4.16% TypeScript 95.84%

vscode-extension-updater's Introduction

Visual Studio Code custom extension updater for private extension marketplaces

CI npm Gitpod Ready-to-Code

For context and motivation, please look at the Private extension market a.k.a side loading.

This package does not provide the extension marketplace (with the ability to pick an extension and install it), but assuming you point your VS Code user population to download and install the extension manually, as long as your extension starts this updater at its activation, this takes care of the usual workflow:

  1. Checks whether new version is available
  2. Asks user, whether they want to download and install now
  3. Downloads the new version .vsix to a local temp file
  4. Installs the new version
  5. Offers to re-load the window to load the new version

This package purpose is to:

  • Provide a base class for extension update abstracting from the type of the private repository
  • Provider specific implementations (please contribute, if you see fit). So far there is support for
    • Confluence wiki

Here is a demo:

Extension auto-update from Confluence wiki attachment

Get Started

Fetch the package using

npm install vscode-extension-updater

Using the Confluence wiki based private extension repository

Assuming you have a Confluence wiki. Package your extension using package that looks like this:

vsce package \
    --out=<package.name>.vsix \
    --baseContentUrl=https://your-confluence-wiki.com/download/attachments/123456/ \
    --baseImagesUrl=https://your-confluence-wiki.com/download/attachments/123456/

Where <package.name> is the name of your extension as defined in your package.json. The 123456 stands for the page ID, where this extension's .vsix is uploaded as attachment.

This means you can setup one page per extension and thus create a catalog (just hort of marketplace) of your private extensions.

Put this to your extension.ts (or .js if you insist) activate function:

import { ConfluenceExtensionUpdater } from 'vscode-extension-updater';

export function activate(context: ExtensionContext): void {

    // ... your extension activation code...

    setTimeout(() => {
        checkNewVersion(context, false);
    }, 30000); // give it 30sec before checking
}

async function checkNewVersion(context: ExtensionContext, showUpToDateConfirmation: boolean): Promise<void> {
    try {
        await new ConfluenceExtensionUpdater(context, {
            confluenceHost: 'your-confluence-wiki.com',
            confluencePageId: 123456
            showUpToDateConfirmation: showUpToDateConfirmation
        }).getNewVersionAndInstall();
    }
    catch (err) {
        showErrorMessage('Failed to check for new version of the the extension: ', err);
    }
}

Adding manual check for new version

VS Code supports extension-specific commands. They show in the menu that displays when you click on the cogwheel button of your extension in the Extensions view. Add this to your package.json:

{
    "contributes": {
        "commands": [
            {
                "command": "yourExt.checkForExtensionUpdate",
                "title": "yourExt: Check for new extension version..."
            },
        ],
        "menus": {
            "extension/context": [
                {
                    "command": "yourExt.checkForExtensionUpdate",
                    "when": "extension == publisherId.extensionId && extensionStatus == installed"
                }
            ]
...
}

... where publisherId, extensionId and yourExt must be replaced with the corresponding values from your package.json.

Add this to your extension.ts activate() method:

    context.subscriptions.push(commands.registerCommand("yourExt.checkForExtensionUpdate", () =>
        checkNewVersion(context, true).catch(showError)));

In this case, we pass true to the showUpToDateConfirmation argument, which will show notification even if there is no new version.

Implementing your own adapter to other custom back-end

Look at the ConfluenceExtensionUpdater class as an example of implementation. Essentially, the only thing you may need to do is to implement this abstract method:

import { ExtensionUpdater, ExtensionVersion } from './ExtensionUpdater';

export class YourExtensionUpdater extends ExtensionUpdater {

    constructor(context: ExtensionContext, options: YourMarketplaceOptions) {
        super(context);
        this.url = options.url;
        // ...
    }

    protected async getVersion(): Promise<ExtensionVersion> {
        // download
    }
}

And the base class would do the same if you integrate it into your extension's activate function.

vscode-extension-updater's People

Contributors

jan-dolejsi avatar dependabot[bot] avatar jorgenpt avatar jfthuong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.