Skip to content

Commit

Permalink
ref(webi): complete transition from 'request' for 'fetch'
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Dec 15, 2024
1 parent ba94ad8 commit 9d0693d
Show file tree
Hide file tree
Showing 12 changed files with 465 additions and 385 deletions.
8 changes: 3 additions & 5 deletions _common/gitea.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ if (module === require.main) {
'https://git.rootprojects.org',
'',
'',
).then(
function (all) {
console.info(JSON.stringify(all, null, 2));
},
);
).then(function (all) {
console.info(JSON.stringify(all, null, 2));
});
}
4 changes: 1 addition & 3 deletions _webi/builds-cacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ let HostTargets = require('./build-classifier/host-targets.js');
let Lexver = require('./build-classifier/lexver.js');
let Triplet = require('./build-classifier/triplet.js');

let request = require('@root/request');

var ALIAS_RE = /^alias: (\w+)$/m;

var LEGACY_ARCH_MAP = {
Expand Down Expand Up @@ -153,7 +151,7 @@ async function getLatestBuilds(Releases, installersDir, cacheDir, name, date) {
}

async function getLatestBuildsInner(Releases, cacheDir, name, date) {
let data = await Releases.latest(request);
let data = await Releases.latest();

if (!date) {
date = new Date();
Expand Down
4 changes: 1 addition & 3 deletions _webi/classify-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ let Path = require('node:path');
let BuildsCacher = require('./builds-cacher.js');
let Triplet = require('./build-classifier/triplet.js');

let request = require('@root/request');

async function main() {
let projName = process.argv[2];
if (!projName) {
Expand Down Expand Up @@ -47,7 +45,7 @@ async function main() {
Releases.latest = Releases;
}

let projInfo = await Releases.latest(request);
let projInfo = await Releases.latest();

// let packages = await Builds.getPackage({ name: projName });
// console.log(packages);
Expand Down
3 changes: 1 addition & 2 deletions _webi/transform-releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var Releases = module.exports;

var path = require('path');
var request = require('@root/request');
var _normalize = require('./normalize.js');

var cache = {};
Expand All @@ -28,7 +27,7 @@ Releases.get = async function (pkgdir) {
throw err;
}

let all = await get.latest(request);
let all = await get.latest();

return _normalize(all);
};
Expand Down
39 changes: 28 additions & 11 deletions flutter/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

var FLUTTER_OSES = ['macos', 'linux', 'windows'];

// stable, beta, dev
/**
* stable, beta, dev
* @type {Object.<String, Boolean>}
*/
var channelMap = {};

// This can be spot-checked against
Expand Down Expand Up @@ -53,25 +56,39 @@ var channelMap = {};
// ]
// }

/**
* @typedef BuildInfo
* @prop {String} version
* @prop {String} [_version]
* @prop {Boolean} lts
* @prop {String} channel
* @prop {String} date
* @prop {String} download
* @prop {String} [_filename]
*/

module.exports = async function () {
let all = {
download: '',
/** @type {Array<BuildInfo>} */
releases: [],
/** @type {Array<String>} */
channels: [],
};

for (let osname of FLUTTER_OSES) {
const response = await fetch(`https://storage.googleapis.com/flutter_infra_release/releases/releases_${osname}.json`, {
method: 'GET',
headers: { Accept: 'application/json' },
});
let response = await fetch(
`https://storage.googleapis.com/flutter_infra_release/releases/releases_${osname}.json`,
{ headers: { Accept: 'application/json' } },
);
if (!response.ok) {
throw new Error(`Failed to fetch data for ${osname}: ${response.statusText}`);
throw new Error(
`Failed to fetch data for ${osname}: ${response.statusText}`,
);
}
const respBody = await response.json();

let osBaseUrl = respBody.base_url;
let osReleases = respBody.releases;
let data = await response.json();
let osBaseUrl = data.base_url;
let osReleases = data.releases;

for (let asset of osReleases) {
if (!channelMap[asset.channel]) {
Expand Down Expand Up @@ -100,7 +117,7 @@ module.exports = async function () {
};

if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
module.exports().then(function (all) {
all.releases = all.releases.slice(25);
console.info(JSON.stringify(all, null, 2));
});
Expand Down
113 changes: 68 additions & 45 deletions go/releases.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
'use strict';

/** @type {Object.<String, String>} */
var osMap = {
darwin: 'macos',
};
/** @type {Object.<String, String>} */
var archMap = {
386: 'x86',
};

let ODDITIES = ['bootstrap', '-arm6.'];

/**
* @param {String} filename
*/
function isOdd(filename) {
for (let oddity of ODDITIES) {
let isOddity = filename.includes(oddity);
Expand All @@ -18,6 +23,21 @@ function isOdd(filename) {
}
}

/**
* @typedef BuildInfo
* @prop {String} version
* @prop {String} [_version]
* @prop {String} arch
* @prop {String} channel
* @prop {String} date
* @prop {String} download
* @prop {String} ext
* @prop {String} [_filename]
* @prop {String} hash
* @prop {Boolean} lts
* @prop {String} os
*/

async function getDistributables() {
/*
{
Expand All @@ -37,60 +57,63 @@ async function getDistributables() {
]
};
*/
const response = await fetch('https://golang.org/dl/?mode=json&include=all', {
method: 'GET',
headers: { Accept: 'application/json' },
});
if (!response.ok) {
throw new Error(`Failed to fetch Go releases: ${response.statusText}`);
let response = await fetch('https://golang.org/dl/?mode=json&include=all', {
method: 'GET',
headers: { Accept: 'application/json' },
});
if (!response.ok) {
throw new Error(`Failed to fetch Go releases: ${response.statusText}`);
}

let goReleases = await response.json();
let all = {
/** @type {Array<BuildInfo>} */
releases: [],
download: '',
};

for (let release of goReleases) {
// Strip 'go' prefix, standardize version
let parts = release.version.slice(2).split('.');
while (parts.length < 3) {
parts.push('0');
}

const goReleases = await response.json();
const all = {
releases: [],
download: '',
};
let version = parts.join('.');
let fileversion = release.version.slice(2);

goReleases.forEach((release) => {
// Strip 'go' prefix and standardize version
const parts = release.version.slice(2).split('.');
while (parts.length < 3) {
parts.push('0');
for (let asset of release.files) {
if (isOdd(asset.filename)) {
return;
}
const version = parts.join('.');
const fileversion = release.version.slice(2);

release.files.forEach((asset) => {
if (isOdd(asset.filename)) {
return;
}

const filename = asset.filename;
const os = osMap[asset.os] || asset.os || '-';
const arch = archMap[asset.arch] || asset.arch || '-';
all.releases.push({
version: version,
_version: fileversion,
lts: (parts[0] > 0 && release.stable) || false,
channel: (release.stable && 'stable') || 'beta',
date: '1970-01-01', // Placeholder
os: os,
arch: arch,
ext: '', // Let normalize run the split/test/join
hash: '-', // Placeholder for hash
download: `https://dl.google.com/go/${filename}`,
});
});
});

return all;

let filename = asset.filename;
let os = osMap[asset.os] || asset.os || '-';
let arch = archMap[asset.arch] || asset.arch || '-';
let build = {
version: version,
_version: fileversion,
lts: (parts[0] > 0 && release.stable) || false,
channel: (release.stable && 'stable') || 'beta',
date: '1970-01-01', // the world may never know
os: os,
arch: arch,
ext: '', // let normalize run the split/test/join
hash: '-', // not ready to standardize this yet
download: `https://dl.google.com/go/${filename}`,
};
all.releases.push(build);
}
}

return all;
}

module.exports = getDistributables;

if (module === require.main) {
getDistributables(require('@root/request')).then(function (all) {
getDistributables().then(function (all) {
all = require('../_webi/normalize.js')(all);
//@ts-expect-error
all.releases = all.releases.slice(0, 10);
console.info(JSON.stringify(all, null, 2));
});
Expand Down
Loading

0 comments on commit 9d0693d

Please sign in to comment.