cleanup stuffs

This commit is contained in:
Andras Bacsai
2022-10-27 09:55:32 +02:00
parent 4416646954
commit 2030f714fa
18 changed files with 130 additions and 160 deletions

View File

@@ -3,9 +3,9 @@ import fs from 'fs/promises';
export async function getTemplates() {
let templates: any = [];
if (isDev) {
templates = JSON.parse(await (await fs.readFile('./template.json')).toString())
templates = JSON.parse(await (await fs.readFile('./templates.json')).toString())
} else {
templates = JSON.parse(await (await fs.readFile('/app/template.json')).toString())
templates = JSON.parse(await (await fs.readFile('/app/templates.json')).toString())
}
// if (!isDev) {
// templates.push({
@@ -141,6 +141,19 @@ export async function getTemplates() {
// }
return templates
}
const compareSemanticVersions = (a: string, b: string) => {
const a1 = a.split('.');
const b1 = b.split('.');
const len = Math.min(a1.length, b1.length);
for (let i = 0; i < len; i++) {
const a2 = +a1[ i ] || 0;
const b2 = +b1[ i ] || 0;
if (a2 !== b2) {
return a2 > b2 ? 1 : -1;
}
}
return b1.length - a1.length;
};
export async function getTags(type?: string) {
let tags: any = [];
if (isDev) {
@@ -148,5 +161,7 @@ export async function getTags(type?: string) {
} else {
tags = JSON.parse(await (await fs.readFile('/app/tags.json')).toString())
}
return tags.find((tag: any) => tag.name.includes(type))
tags = tags.find((tag: any) => tag.name.includes(type))
tags.tags = tags.tags.sort(compareSemanticVersions).reverse();
return tags
}