import { parseJSONC, path } from "./deps.ts";import type { JSONValue } from "./deps.ts";
export async function getJSON(file: string): Promise<JSONValue> { try { const fileContents = await Deno.readTextFile(file); return parseJSONC(fileContents); } catch (err) { throw new Error(err.message, { cause: err }); }}
export async function getDefaultExport( functionFilePath: string, ): Promise<any> { const functionModule = await import(`file://${functionFilePath}`); if (!functionModule.default) { throw new Error(`File: ${functionFilePath} has no default export!`); } return functionModule.default;}
export async function validateManifestFunctions( applicationRoot: string, manifest: any,): Promise<void> { for (const fnId in manifest.functions) { const fnDef = manifest.functions[fnId]; if (fnDef.type === "API") { continue; }
if (!fnDef.source_file) { throw new Error( `No source_file property provided for function with ID ${fnId}!`, ); } const fnFilePath = path.join(applicationRoot, fnDef.source_file); try { const { isFile } = await Deno.stat(fnFilePath); if (!isFile) { throw new Error( `Could not find source_file: ${fnFilePath} for function with ID ${fnId}!`, ); } } catch (e) { if (e instanceof Deno.errors.NotFound) { throw new Error( `Could not find file: ${fnFilePath}. Make sure the function definition with ID ${fnId}'s source_file is relative to your project root.`, ); } throw e; }
const defaultExport = await getDefaultExport(fnFilePath); if (typeof defaultExport !== "function") { throw new Error( `The function with ID ${fnId} located at ${fnFilePath}'s default export is not a function!`, ); } }}
export const isNewSemverRelease = (current: string, target: string) => { const [currMajor, currMinor, currPatch] = current .split(".") .map((val) => Number(val)); const [targetMajor, targetMinor, targetPatch] = target .split(".") .map((val) => Number(val));
if (targetMajor !== currMajor) return targetMajor > currMajor; if (targetMinor !== currMinor) return targetMinor > currMinor; return targetPatch > currPatch;};