diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..d333743 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,26 @@ +name: Lint + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # tag: v3.5.3 + - name: Setup Node.js + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # tag: v3.6.0 + with: + node-version: 18.x + - name: Lint + run: | + yarn + yarn lint diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..b22688e --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +src/static/css/prismjs/** diff --git a/package.json b/package.json index 555bb62..f305343 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "scripts": { "watch": "nodemon --watch src --ext js,css,handlebars --exec \"npm run start\"", "start": "node src/index.js", + "lint": "prettier --check \"src/**/*.js\" \"src/**/*.css\"", "prettier:write": "prettier --write \"src/**/*.js\" \"src/**/*.css\"", "postinstall": "cp node_modules/prismjs/themes/*.css src/static/css/prismjs" } diff --git a/src/data.js b/src/data.js index cd545e0..f2fcae0 100644 --- a/src/data.js +++ b/src/data.js @@ -5,7 +5,6 @@ const ExpiryMap = require('expiry-map'); const pMemoize = require('p-memoize'); const semver = require('semver'); - let octokit = null; const getOctokit = async () => { if (octokit) return octokit; @@ -146,8 +145,8 @@ const getTSDefs = pMemoize( { cache: new ExpiryMap(60 * 60 * 24 * 1000), cacheKey: (version) => `ts/${version}`, - } -) + }, +); module.exports = { getGitHubRelease, diff --git a/src/routes/release.js b/src/routes/release.js index 41db4f7..71de819 100644 --- a/src/routes/release.js +++ b/src/routes/release.js @@ -44,8 +44,9 @@ Handlebars.registerHelper('markdownMergeHeaders', function (contentArr) { const groupName = headers[i]; const groupContent = headers[i + 1]; groups[groupName] = groups[groupName] || ''; - groups[groupName] += `
${version}
\n\n${groupContent.trim()}\n\n
\n`; + groups[groupName] += `
${version}
\n\n${groupContent.trim()}\n\n
\n`; } } let generatedNotes = '# Combined Release Notes\n\n'; @@ -63,9 +64,7 @@ async function getValidVersionRange(startVersion, endVersion, res) { const parsedStart = semver.parse(startVersion); const parsedEnd = semver.parse(endVersion); if (!parsedStart || !parsedEnd || parsedStart.major !== parsedEnd.major) { - res.end( - 'Sorry you can only compare Electron versions in the same major line at the moment', - ); + res.end('Sorry you can only compare Electron versions in the same major line at the moment'); return [allReleases, null]; } @@ -92,11 +91,14 @@ async function getValidVersionRange(startVersion, endVersion, res) { return [allReleases, null]; } - return [allReleases, allReleases.filter( - (r) => - semver.parse(r.version).compare(startVersion) > 0 && - semver.parse(r.version).compare(endVersion) <= 0, - )]; + return [ + allReleases, + allReleases.filter( + (r) => + semver.parse(r.version).compare(startVersion) > 0 && + semver.parse(r.version).compare(endVersion) <= 0, + ), + ]; } async function handleComparisonRequest(startVersion, endVersion, res) { @@ -112,7 +114,8 @@ async function handleComparisonRequest(startVersion, endVersion, res) { if (parsed.prerelease.length) { notes = notes.split(`@${r.tag_name.substr(1)}\`.`)[1]; } - notes = '# Release Notes\n' + notes.replace(/# Release Notes for [^\r\n]+(?:(?:\n)|(?:\r\n))/i, ''); + notes = + '# Release Notes\n' + notes.replace(/# Release Notes for [^\r\n]+(?:(?:\n)|(?:\r\n))/i, ''); return [notes, r.tag_name]; }); @@ -136,15 +139,9 @@ async function handleTypescriptComparisonRequest(startVersion, endVersion, res) const [startTypes, endTypes] = await Promise.all([ getTSDefs(startVersion), - getTSDefs(endVersion) + getTSDefs(endVersion), ]); - const tsDiff = Diff.createPatch( - 'electron.d.ts', - startTypes, - endTypes, - startVersion, - endVersion, - ); + const tsDiff = Diff.createPatch('electron.d.ts', startTypes, endTypes, startVersion, endVersion); const diff = Prism.highlight(tsDiff, Prism.languages.javascript, 'typescript'); res.render('ts-diff', { @@ -172,13 +169,10 @@ router.get( }), ); -router.get( - '/compare/:comparisonRange', - (req, res) => { - const [startVersion, endVersion] = req.params.comparisonRange.split('...'); - res.redirect(`/release/compare/${startVersion}/${endVersion}`); - }, -); +router.get('/compare/:comparisonRange', (req, res) => { + const [startVersion, endVersion] = req.params.comparisonRange.split('...'); + res.redirect(`/release/compare/${startVersion}/${endVersion}`); +}); function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string @@ -201,7 +195,9 @@ router.get( if (parsed.prerelease.length) { releaseNotes = releaseNotes.split(new RegExp(`@${escapeRegExp(version.substr(1))}\`?.`))[1]; } - releaseNotes = '# Release Notes\n' + releaseNotes.replace(/# Release Notes for [^\r\n]+(?:(?:\n)|(?:\r\n))/i, ''); + releaseNotes = + '# Release Notes\n' + + releaseNotes.replace(/# Release Notes for [^\r\n]+(?:(?:\n)|(?:\r\n))/i, ''); const lastPreRelease = allReleases.find( (r) => @@ -234,7 +230,14 @@ router.get( prerelease: parsed.prerelease[0] || '', css: 'release', compareTarget: version, - compareList: allReleases.filter(r => r.version !== version.substr(1) && semver.parse(r.version).prerelease[0] !== 'nightly' && parsed.major === semver.parse(r.version).major).map(r => r.version), + compareList: allReleases + .filter( + (r) => + r.version !== version.substr(1) && + semver.parse(r.version).prerelease[0] !== 'nightly' && + parsed.major === semver.parse(r.version).major, + ) + .map((r) => r.version), }); }), ); diff --git a/src/routes/releases.js b/src/routes/releases.js index bfad913..e152a4c 100644 --- a/src/routes/releases.js +++ b/src/routes/releases.js @@ -115,8 +115,8 @@ router.get( prev: paginate.href(req)(true), next: paginate.href(req)(false), pages: paginate.getArrayPages(req)(5, pageCount, req.query.page), - first: paginate.href(req)(false, {page: 1}), - last: paginate.href(req)(false, {page: pageCount}), + first: paginate.href(req)(false, { page: 1 }), + last: paginate.href(req)(false, { page: pageCount }), }); }), );