Files
openstapps/backend/backend/config/default/tools/version.js
2023-12-08 13:49:53 +00:00

37 lines
1.1 KiB
JavaScript

// @ts-check
import {readFile, readdir} from 'fs/promises';
/**
* @example version(1, import.meta.url)
* @param options {Omit<import('@openstapps/core').SCAppVersionInfo, 'releaseNotes' | 'translations'>}
* @param base {string}
* @returns {Promise<import('@openstapps/core').SCAppVersionInfo>}
*/
export async function version(options, base) {
const de = await readFile(new URL(`${options.version}.de.md`, base), 'utf8');
const en = await readFile(new URL(`${options.version}.en.md`, base), 'utf8');
return {
...options,
releaseNotes: de,
translations: {
en: {
releaseNotes: en,
},
},
};
}
/**
* @param base {string} Base path of the file as `import.meta.url`
* @returns {Promise<import('@openstapps/core').SCAppVersionInfo[]>}
*/
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)));
}