1 | const request = require('request');
|
2 |
|
3 | const canConnect = require('./can-connect');
|
4 | const configstore = require('./configstore');
|
5 |
|
6 | async function fetchLatestVersion() {
|
7 | const canConnectToNPM = await canConnect('registry.npm.org');
|
8 |
|
9 | if (!canConnectToNPM) {
|
10 | return;
|
11 | }
|
12 |
|
13 | request(
|
14 | {
|
15 | url: 'https://registry.npmjs.org/@creuna/cli',
|
16 | headers: {
|
17 | Accept: 'application/vnd.npm.install-v1+json'
|
18 | }
|
19 | },
|
20 | (error, response, body) => {
|
21 | if (error || response.statusCode < 200 || response.statuscode >= 400) {
|
22 |
|
23 | return;
|
24 | }
|
25 |
|
26 | try {
|
27 | configstore.set('latestVersion', JSON.parse(body)['dist-tags'].latest);
|
28 | } catch (error) {
|
29 |
|
30 | }
|
31 | }
|
32 | );
|
33 | }
|
34 |
|
35 | module.exports = fetchLatestVersion;
|