mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-13 01:36:22 +00:00
feat: simplify version history api
This commit is contained in:
committed by
Rainer Killinger
parent
d44204cf8d
commit
d2c8120255
@@ -1,5 +1,5 @@
|
||||
// @ts-check
|
||||
import {readFile} from 'fs/promises';
|
||||
import {readFile, readdir} from 'fs/promises';
|
||||
|
||||
/**
|
||||
* @example version(1, import.meta.url)
|
||||
@@ -23,20 +23,14 @@ export async function version(options, base) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param infos {Record<string, import('@openstapps/core').SCAppVersionInfo['published']>}
|
||||
* @param base {string} Base path of the file as `import.meta.url`
|
||||
* @returns {Promise<import('@openstapps/core').SCAppVersionInfo[]>}
|
||||
*/
|
||||
export async function versions(infos, base) {
|
||||
return Promise.all(
|
||||
Object.entries(infos).map(([versionName, published]) =>
|
||||
version(
|
||||
{
|
||||
published,
|
||||
version: versionName,
|
||||
},
|
||||
base,
|
||||
),
|
||||
),
|
||||
).then(it => it.sort(({version: a}, {version: b}) => -a.localeCompare(b, undefined, {numeric: true})));
|
||||
export async function versions(base) {
|
||||
const directory = await readdir(new URL(base));
|
||||
const versions = [...new Set(directory.map(it => it.replace(/\.\w+\.md$/, '')))].sort(
|
||||
(a, b) => -a.localeCompare(b, undefined, {numeric: true}),
|
||||
);
|
||||
|
||||
return Promise.all(versions.map(versionName => version({version: versionName}, base)));
|
||||
}
|
||||
|
||||
@@ -2,11 +2,6 @@
|
||||
import {versions} from '../../default/tools/version.js';
|
||||
|
||||
/** @type {import('@openstapps/core').SCAppVersionInfo[]} */
|
||||
const versionHistory = await versions(
|
||||
{
|
||||
'2.4.0': {},
|
||||
},
|
||||
import.meta.url,
|
||||
);
|
||||
const versionHistory = await versions(import.meta.url);
|
||||
|
||||
export default versionHistory;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"useUnknownInCatchVariables": false,
|
||||
"allowJs": true
|
||||
}
|
||||
"allowJs": true,
|
||||
"checkJs": true
|
||||
},
|
||||
"exclude": ["app.js", "lib/"]
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
"dockerode": "3.3.5",
|
||||
"is-cidr": "4.0.2",
|
||||
"mustache": "4.2.0",
|
||||
"semver": "7.3.8",
|
||||
"semver": "7.5.4",
|
||||
"typescript": "5.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -65,7 +65,7 @@
|
||||
"@types/mustache": "4.2.2",
|
||||
"@types/node": "18.15.3",
|
||||
"@types/proxyquire": "1.3.28",
|
||||
"@types/semver": "7.3.13",
|
||||
"@types/semver": "7.5.6",
|
||||
"@types/sha1": "1.1.3",
|
||||
"@types/sinon": "10.0.14",
|
||||
"@types/sinon-chai": "3.2.9",
|
||||
|
||||
Reference in New Issue
Block a user