matanlurey
matanlurey

Reputation: 8614

Resolve a version from stable/dev channel of the Dart SDK

Is there some shared/simple logic to implement something like:

Future<Version> getLatestStable();

Future<Version> getLatestDev();

Just curious. I'd rather not parse the download page. I guess another option would be releasing either a feed.json or feed.xml as part of the website to make it easier for tools.

Upvotes: 1

Views: 129

Answers (2)

Danny Tuppeny
Danny Tuppeny

Reputation: 42333

In Dart Code I pull the version from storage.googleapis.com:

https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION https://storage.googleapis.com/dart-archive/channels/stable/dev/latest/VERSION

I think I took this from the source of the Dart downloads page and it's been stable since I implemented it, so should be good to use!

Here's my (TypeScript) code that pulls it:

export function getLatestSdkVersion(): PromiseLike<string> {
    return new Promise<string>((resolve, reject) => {
        const options: https.RequestOptions = {
            hostname: "storage.googleapis.com",
            port: 443,
            path: "/dart-archive/channels/stable/release/latest/VERSION",
            method: "GET",
        };

        let req = https.request(options, resp => {
            if (resp.statusCode < 200 || resp.statusCode > 300) {
                reject({ message: `Failed to get Dart SDK Version ${resp.statusCode}: ${resp.statusMessage}` });
            } else {
                resp.on('data', (d) => {
                    resolve(JSON.parse(d.toString()).version);
                });
            }
        });
        req.end();
    });
}

Upvotes: 2

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657268

Get the VERSION file of the latest directory

http://gsdview.appspot.com/dart-archive/channels/dev/release/latest/

Available channels are listed in

http://gsdview.appspot.com/dart-archive/channels/

Some code that makes use of it can be found in https://pub.dartlang.org/packages/bwu_dart_archive_downloader

Upvotes: 2

Related Questions