从Dart SDK的stable / dev通道解析版本

时间:2017-05-19 15:45:22

标签: dart

是否有一些共享/简单的逻辑来实现类似的东西:

Future<Version> getLatestStable();

Future<Version> getLatestDev();

好奇。我宁愿不解析the download page。我想另一种选择是将feed.json或feed.xml作为网站的一部分发布,以便更轻松地使用工具。

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:2)

来自storage.googleapis.com的Dart Code I pull the version

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

我想我从Dart下载页面的源代码中获取了它,并且自从我实现它以来它一直很稳定,所以应该很好用!

这是我的(TypeScript)代码:

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();
    });
}