Sha256: 5af18e90b7c37be5f626904ff21ceb0d09264c556ad1d9953010aa0871675783

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

import { execSync } from 'child_process'
import { cmp, maxSatisfying } from 'semver'
import { asyncExec } from './utils'

interface CheckResult {
    shouldUpdate: boolean
    localVersion: string
    remoteVersion: string
}

export async function checkVersions(): Promise<CheckResult> {
    const { stdout } = await asyncExec("gem list --both --exact yoda-language-server")
    const [localVersion, remoteVersion] = parseGemList(stdout)

    return {
        shouldUpdate: shouldUpdate(localVersion, remoteVersion),
        localVersion: localVersion,
        remoteVersion: remoteVersion,
    }
}

function shouldUpdate(localVersion: string, remoteVersion: string): boolean {
    if (!localVersion) {
        return true
    }

    if (!remoteVersion) {
        return false
    }

    return cmp(localVersion, "<", remoteVersion)
}

function parseGemList(stdout: string): [string, string] {
    const [local, remote] = stdout.split("*** REMOTE GEMS ***")

    const localVersion = extractVersion(local)
    const remoteVersion = extractVersion(remote)

    return [localVersion, remoteVersion]
}

function extractVersion(text: string): string {
    const lines = text.split("\n")
    for (const line of lines) {
        const matchData = line.match(/^yoda-language-server\s*\((.+)\)/);
        if (matchData) {
            const versions = matchData[1].split(/,\s*/)
            return maxSatisfying(versions, '*')
        }
    }

    return null
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yoda-language-server-0.9.0 client/vscode/src/check-versions.ts