Skip to content

Commit

Permalink
build: better fetch releases (#782)
Browse files Browse the repository at this point in the history
* build: in fetch-releases, use electronjs.org

The old version of the script missed a *lot* of versions.
old code: 'Updating local releases.json with 560 versions.'
new code: 'Updating local releases.json with 1049 versions.'
  • Loading branch information
ckerr authored Jul 16, 2021
1 parent e892d9f commit 3ee5a37
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"less": "^4.1.1",
"lint-staged": "^10.5.4",
"log-symbols": "^4.0.0",
"node-fetch": "^2.6.1",
"npm-run-all": "^4.1.5",
"parcel-bundler": "^1.12.4",
"prettier": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion static/releases.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions tests/fixtures/releases-metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"expectedVersionCount": 556,
"lastElectronVersion": "12.0.14"
"expectedVersionCount": 1049
}
35 changes: 9 additions & 26 deletions tools/fetch-releases.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
const path = require('path');
const fs = require('fs-extra');
const https = require('https');
const fetch = require('node-fetch');

const file = path.join(__dirname, '..', 'static', 'releases.json');

function getReleases() {
return new Promise((resolve) => {
https.get(
{
host: 'registry.npmjs.org',
path: '/electron',
headers: {
'User-Agent': 'Electron Fiddle',
},
},
(res) => {
res.setEncoding('utf8');
let body = '';

res.on('data', (data) => {
body += data;
});

res.on('end', () => {
resolve(JSON.parse(body));
});
},
);
async function getReleases() {
const url = 'https://releases.electronjs.org/releases.json';
const response = await fetch(url, {
headers: {
'User-Agent': 'Electron Fiddle',
},
});
return await response.json();
}

async function main() {
const data = await getReleases();
const releases = Object.keys(data.versions).map((version) => ({ version }));
const releases = data.map(({ version }) => ({ version }));

console.log(`Updating local releases.json with ${releases.length} versions.`);

Expand All @@ -43,7 +27,6 @@ async function main() {

const metadata = {
expectedVersionCount: releases.length,
lastElectronVersion: releases[releases.length - 1].version,
};
const releasesMetadataPath = path.resolve(
__dirname,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4677,7 +4677,7 @@ electron-winstaller@^5.0.0:
lodash.template "^4.2.2"
temp "^0.9.0"

electron@^12.0.14:
[email protected]:
version "12.0.14"
resolved "https://registry.yarnpkg.com/electron/-/electron-12.0.14.tgz#7c5547f8248633a4bbbba89c88c57aa9e6410892"
integrity sha512-RcU++BiL+DlwhP62sUTasjAOwXOloWQS3oLk4PE0s2eERNs7hr2LoKqbUpbShw9nY+aqNw4mgd+ojyBJsOE2fg==
Expand Down

0 comments on commit 3ee5a37

Please sign in to comment.