fix: getTemplates

This commit is contained in:
Andras Bacsai 2022-11-11 14:19:42 +01:00
parent 868c4001f6
commit ac7d4e3645

View File

@ -2,16 +2,13 @@ import { isDev } from "./common";
import fs from 'fs/promises'; import fs from 'fs/promises';
export async function getTemplates() { export async function getTemplates() {
const templatePath = isDev ? './templates.json' : '/app/templates.json'; const templatePath = isDev ? './templates.json' : '/app/templates.json';
const open = await fs.open(templatePath, 'r');
let data;
try { try {
data = await open.readFile({ encoding: 'utf-8' }); const ts = await fs.readFile(templatePath, 'utf8')
return JSON.parse(data); if (ts) {
} catch (error) { return JSON.parse(ts);
return [] }
} finally { } catch (error) { }
await open?.close() return [];
}
} }
const compareSemanticVersions = (a: string, b: string) => { const compareSemanticVersions = (a: string, b: string) => {
const a1 = a.split('.'); const a1 = a.split('.');