3 // this may need customizations between packages
5 macos: /\b(apple|mac|darwin|iPhone|iOS|iPad)/i,
7 windows: /\b(win|microsoft|msft)/i,
12 // evaluation order matters
13 // (i.e. otherwise x86 and x64 can cross match)
15 'amd64', // first and most likely match
25 amd64: /(amd.?64|x64|[_\-]64)/i,
27 ppc64le: /\b(ppc64le)/i,
28 ppc64: /\b(ppc64)\b/i,
29 arm64: /\b(arm64|arm)/i,
30 armv7l: /\b(armv?7l)/i,
31 armv6l: /\b(armv?6l)/i,
46 * Gets the releases for 'ripgrep'. This function could be trimmed down and made
47 * for use with any github release.
50 * @param {string} owner
51 * @param {string} repo
52 * @returns {PromiseLike<any> | Promise<any>}
54 function getAllReleases(request, owner = 'BurntSushi', repo = 'ripgrep') {
56 return Promise.reject('missing owner for repo');
59 return Promise.reject('missing repo name');
62 url: `https://api.github.com/repos/${owner}/${repo}/releases`,
65 const gHubResp = resp.body;
71 gHubResp.forEach((release) => {
72 release['assets'].forEach((asset) => {
73 // set the primary download to the first of the releases
74 if (all.download === '') {
75 all.download = asset['browser_download_url'];
78 const name = asset['name'];
80 Object.keys(osMap).find(function (regKey) {
81 //console.log('github release os:', name, regKey, osMap[regKey]);
82 return osMap[regKey].test(name);
85 archArr.some(function (regKey) {
86 //console.log('github release arch:', name, regKey, archMap[regKey]);
87 arch = name.match(archMap[regKey]) && regKey;
94 Object.keys(fileExtMap).find((regKey) => {
95 const match = name.match(fileExtMap[regKey]);
104 download: asset['browser_download_url'],
105 date: (release['published_at'] || '').replace(/T.*/, ''),
106 version: release['tag_name'], // TODO tags aren't always semver / sensical
107 lts: /\b(lts)\b/.test(release['tag_name']),
108 channel: !release['prerelease'] ? 'stable' : 'beta',
109 ext: fileExt.slice(1),
120 module.exports = getAllReleases;
122 if (module === require.main) {
123 getAllReleases(require('@root/request'), 'BurntSushi', 'ripgrep').then(
125 console.log(JSON.stringify(all, null, 2));