mirror of
https://github.com/danog/sass-site.git
synced 2024-11-26 12:04:40 +01:00
Add "releases" data file
This commit is contained in:
parent
9b544fb710
commit
1363847bfa
5
.gitignore
vendored
5
.gitignore
vendored
@ -3,15 +3,12 @@
|
||||
/.bundle
|
||||
bundle
|
||||
/.cache
|
||||
/data/version.yml
|
||||
/source/_data/versionCache.json
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
/Icon
|
||||
"Icon\r"
|
||||
.ruby-version
|
||||
/.dart-sass
|
||||
/.libsass
|
||||
/.language
|
||||
/.sass-cache
|
||||
*.scssc
|
||||
Thumbs.db
|
||||
|
@ -10,3 +10,4 @@ services:
|
||||
- /app/node_modules
|
||||
ports:
|
||||
- '8080:8080'
|
||||
tty: true
|
||||
|
@ -68,6 +68,7 @@
|
||||
"prettier": "^2.8.3",
|
||||
"rollup": "^3.12.0",
|
||||
"sass": "^1.57.1",
|
||||
"semver-parser": "^4.0.1",
|
||||
"stylelint": "^14.16.1",
|
||||
"stylelint-config-prettier": "^9.0.4",
|
||||
"stylelint-config-standard-scss": "^6.1.0",
|
||||
|
90
source/_data/releases.cjs
Normal file
90
source/_data/releases.cjs
Normal file
@ -0,0 +1,90 @@
|
||||
const { spawn: nodeSpawn } = require('node:child_process');
|
||||
const fs = require('node:fs/promises');
|
||||
|
||||
const VERSION_CACHE_PATH = './source/_data/versionCache.json';
|
||||
|
||||
// Promise version of `spawn` to avoid blocking the main thread while waiting
|
||||
// for the child processes
|
||||
function spawn(cmd, args, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = nodeSpawn(cmd, args, options);
|
||||
const stderr = [];
|
||||
const stdout = [];
|
||||
child.stdout.on('data', (data) => {
|
||||
stdout.push(data.toString());
|
||||
});
|
||||
child.on('error', (e) => {
|
||||
stderr.push(e.toString());
|
||||
});
|
||||
child.on('close', () => {
|
||||
if (stderr.length) reject(stderr.join(''));
|
||||
else resolve(stdout.join(''));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Retrieve the highest stable version of `repo`, based on its git tags
|
||||
// Store results in `VERSION_CACHE_PATH` for faster future runs
|
||||
async function getLatestVersion(repo) {
|
||||
let versionCache;
|
||||
try {
|
||||
versionCache = JSON.parse(await fs.readFile(VERSION_CACHE_PATH));
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
versionCache = {}; // Cache is missing and needs to be created
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
let latestVersion = versionCache[repo];
|
||||
if (latestVersion !== undefined) return latestVersion;
|
||||
|
||||
console.log(`Fetching version information for ${repo}`);
|
||||
const { parseSemVer, compareSemVer } = await import('semver-parser');
|
||||
let stdout;
|
||||
try {
|
||||
stdout = await spawn(
|
||||
'git',
|
||||
['ls-remote', '--tags', '--refs', `https://github.com/${repo}`],
|
||||
{ env: { ...process.env, GIT_TERMINAL_PROMPT: 0 } },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(`Failed to fetch git tags for ${repo}`);
|
||||
throw err;
|
||||
}
|
||||
const isNotPreRelease = (version) => {
|
||||
const parsed = parseSemVer(version);
|
||||
return parsed.matches && !parsed.pre;
|
||||
};
|
||||
latestVersion = stdout
|
||||
.split('\n')
|
||||
.map((line) => line.split('refs/tags/').slice(-1).at(0))
|
||||
.filter(isNotPreRelease)
|
||||
.sort(compareSemVer)
|
||||
.slice(-1)
|
||||
.at(0);
|
||||
|
||||
versionCache[repo] = latestVersion;
|
||||
await fs.writeFile(VERSION_CACHE_PATH, JSON.stringify(versionCache));
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
function getReleaseUrl(repo, version = null) {
|
||||
if (repo === 'ruby/sass') {
|
||||
return 'https://github.com/sass/ruby-sass/blob/stable/doc-src/SASS_CHANGELOG.md';
|
||||
}
|
||||
return `https://github.com/${repo}/releases${
|
||||
version ? `/tag/${version}` : ''
|
||||
}`;
|
||||
}
|
||||
|
||||
module.exports = async () => {
|
||||
const data = {};
|
||||
const repos = ['sass/libsass', 'sass/dart-sass', 'sass/migrator'];
|
||||
for await (const repo of repos) {
|
||||
const version = await getLatestVersion(repo);
|
||||
const url = getReleaseUrl(repo, version);
|
||||
data[repo.replace('sass/', '')] = { version, url };
|
||||
}
|
||||
return data;
|
||||
};
|
@ -73,8 +73,8 @@
|
||||
<div class="sl-l-container sl-c-list-horizontal-wrapper" aria-labelledby="release-nav">
|
||||
<ul class="sl-l-grid--justify-center">
|
||||
<li id="release-nav">Current Releases:</li>
|
||||
<li><span class="release-name"><a href="/dart-sass">Dart Sass</a> <a href="https://github.com/sass/dart-sass/releases/tag/1.57.1">1.57.1</a></span></li>
|
||||
<li><span class="release-name"><a href="/libsass">LibSass</a> <a href="https://github.com/sass/libsass/releases/tag/3.6.5">3.6.5</a></span></li>
|
||||
<li><span class="release-name"><a href="/dart-sass">Dart Sass</a> <a href="{{ releases['dart-sass'].url }}">{{ releases['dart-sass'].version }}</a></span></li>
|
||||
<li><span class="release-name"><a href="/libsass">LibSass</a> <a href="{{ releases['libsass'].url }}">{{ releases['libsass'].version }}</a></span></li>
|
||||
<li><span class="release-name"><a href="/ruby-sass">Ruby Sass</a> <span aria-label="coffin" role="presentation">⚰</span></span></li>
|
||||
<li class="sl-l-grid__column sl-l-large-grid__column--auto-size"><a href="/implementation">Implementation Guide</a></li>
|
||||
</ul>
|
||||
|
@ -6176,6 +6176,7 @@ __metadata:
|
||||
prettier: ^2.8.3
|
||||
rollup: ^3.12.0
|
||||
sass: ^1.57.1
|
||||
semver-parser: ^4.0.1
|
||||
stylelint: ^14.16.1
|
||||
stylelint-config-prettier: ^9.0.4
|
||||
stylelint-config-standard-scss: ^6.1.0
|
||||
@ -6215,6 +6216,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"semver-parser@npm:^4.0.1":
|
||||
version: 4.0.1
|
||||
resolution: "semver-parser@npm:4.0.1"
|
||||
checksum: a737d33882124b64936e1ae3ea8f39c9c78077e8eecfcbee2958f3062debd6410be511a59cb089b93e62f7c1546ee2a252a38b8721f00ab80f916e25ff3eda7e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"semver@npm:2 || 3 || 4 || 5, semver@npm:^5.5.0":
|
||||
version: 5.7.1
|
||||
resolution: "semver@npm:5.7.1"
|
||||
|
Loading…
Reference in New Issue
Block a user