From 33f73fefbb1047f8508fd55fdbe0f1d2dcc9c584 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 25 Jan 2024 23:11:49 +0100 Subject: [PATCH] support original manifest --- src/main/utils/readManifest.js | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/utils/readManifest.js b/src/main/utils/readManifest.js index 886cfe5..9b37f41 100644 --- a/src/main/utils/readManifest.js +++ b/src/main/utils/readManifest.js @@ -1,11 +1,8 @@ -import path from "node:path" import fs from "node:fs" - -import lodash from "lodash" import got from "got" export async function fetchAndCreateModule(manifest) { - console.log(`Fetching ${manifest}...`) + console.log(`[${manifest.id}] fetchAndCreateModule() | Fetching ${manifest}...`) try { const response = await got.get(manifest) @@ -20,36 +17,39 @@ export async function fetchAndCreateModule(manifest) { } } -export async function readManifest(manifest, { just_read = false } = {}) { +export async function readManifest(manifest) { // check if manifest is a directory or a url const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi - if (urlRegex.test(manifest)) { - const _module = await fetchAndCreateModule(manifest) - const remoteUrl = lodash.clone(manifest) + const target = manifest?.remote_url ?? manifest - manifest = _module.exports + if (urlRegex.test(target)) { + const _module = await fetchAndCreateModule(target) - manifest.remote_url = remoteUrl + if (typeof manifest === "object") { + manifest._original_manifest = { + ...manifest, + } + + manifest = { + ...manifest, + ..._module.exports, + } + } else { + manifest = _module.exports + } + + manifest.remote_url = target } else { - if (!fs.existsSync(manifest)) { - throw new Error(`Manifest not found: ${manifest}`) + if (!fs.existsSync(target)) { + throw new Error(`Manifest not found: ${target}`) } - if (!fs.statSync(manifest).isFile()) { - throw new Error(`Manifest is not a file: ${manifest}`) + if (!fs.statSync(target).isFile()) { + throw new Error(`Manifest is not a file: ${target}`) } - const manifestFilePath = lodash.clone(manifest) - - manifest = require(manifest) - - if (!just_read) { - // copy manifest - fs.copyFileSync(manifestFilePath, path.resolve(MANIFEST_PATH, path.basename(manifest))) - - manifest.remote_url = manifestFilePath - } + manifest = require(target) } return manifest