mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 10:34:18 +00:00
support original manifest
This commit is contained in:
parent
f7818495e3
commit
33f73fefbb
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user