-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from jimmywarting/esm
Simplify build script
- Loading branch information
Showing
3 changed files
with
27 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,30 @@ | ||
const http = require('https'); | ||
const fs = require('fs/promises'); | ||
const path = require('path'); | ||
const semver = require('semver'); | ||
import fs from 'node:fs'; | ||
import semver from 'semver'; | ||
|
||
function loadJSON (url) { | ||
return new Promise((resolve, reject) => { | ||
http.get(url, (response) => { | ||
let data = ''; | ||
response.on('data', (chunk) => { | ||
data += chunk; | ||
}) | ||
response.on('end', () => { | ||
resolve(JSON.parse(data)); | ||
}) | ||
}).on('error', (error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
async function writeJSON(file, data) { | ||
await fs.writeFile(path.join(__dirname, '..', file), JSON.stringify(data)); | ||
function writeJSON(file, data) { | ||
fs.writeFileSync(new URL(file, import.meta.url), JSON.stringify(data)); | ||
} | ||
|
||
async function processVersions() { | ||
const origin = await loadJSON('https://nodejs.org/dist/index.json'); | ||
const processed = origin | ||
.filter(function (env) { | ||
return semver.patch(env.version) === 0; | ||
}) | ||
.map(function (env) { | ||
return { | ||
name: 'nodejs', | ||
version: env.version.substr(1), | ||
date: env.date, | ||
lts: env.lts, | ||
security: env.security | ||
}; | ||
}) | ||
.sort((a, b) => { | ||
if (semver.gt(a.version, b.version)) return 1; | ||
if (semver.lt(a.version, b.version)) return -1; | ||
return 0; | ||
}); | ||
await writeJSON('data/processed/envs.json', processed); | ||
} | ||
const [ dist, schedule ] = await Promise.all([ | ||
'https://nodejs.org/dist/index.json', | ||
'https://raw.githubusercontent.com/nodejs/Release/master/schedule.json' | ||
].map(url => fetch(url).then(res => res.json()))); | ||
|
||
async function processSchedule() { | ||
const origin = await loadJSON( | ||
'https://raw.githubusercontent.com/nodejs/Release/master/schedule.json' | ||
); | ||
await writeJSON('data/release-schedule/release-schedule.json', origin); | ||
} | ||
// Process Versions | ||
const processed = dist | ||
.filter(env => semver.patch(env.version) === 0) | ||
.map(env => ({ | ||
name: 'nodejs', | ||
version: env.version.substr(1), | ||
date: env.date, | ||
lts: env.lts, | ||
security: env.security | ||
})) | ||
.sort((a, b) => { | ||
if (semver.gt(a.version, b.version)) return 1; | ||
if (semver.lt(a.version, b.version)) return -1; | ||
return 0; | ||
}); | ||
|
||
processVersions(); | ||
processSchedule(); | ||
writeJSON('../data/processed/envs.json', processed); | ||
writeJSON('../data/release-schedule/release-schedule.json', schedule); |