Changed self-hosted to run on ESM

This commit is contained in:
Alexander Cerutti
2025-01-11 15:36:43 +01:00
parent 028831ea9a
commit 4044125e6a
12 changed files with 343 additions and 42 deletions

View File

@@ -5,18 +5,30 @@
* examples, creation through templates is already shown
*/
import { app } from "./webserver";
import { getCertificates } from "./shared";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { promises as fs } from "node:fs";
import { PKPass } from "passkit-generator";
import { app } from "./webserver.js";
import { getCertificates } from "./shared.js";
import * as Utils from "passkit-generator/lib/utils";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// ******************************************** //
// *** CODE FROM GET MODEL FOLDER INTERNALS *** //
// ******************************************** //
/**
* Removes hidden files from a list (those starting with dot)
*
* @params from - list of file names
* @return
*/
export function removeHidden(from: Array<string>): Array<string> {
return from.filter((e) => e.charAt(0) !== ".");
}
async function readFileOrDirectory(filePath: string) {
if ((await fs.lstat(filePath)).isDirectory()) {
return Promise.all(await readDirectory(filePath));
@@ -59,7 +71,7 @@ function getObjectFromModelFile(
*/
async function readDirectory(filePath: string) {
const dirContent = await fs.readdir(filePath).then(Utils.removeHidden);
const dirContent = await fs.readdir(filePath).then(removeHidden);
return dirContent.map(async (fileName) => {
const content = await fs.readFile(path.resolve(filePath, fileName));