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 fs from "node:fs"
|
||||||
|
|
||||||
import lodash from "lodash"
|
|
||||||
import got from "got"
|
import got from "got"
|
||||||
|
|
||||||
export async function fetchAndCreateModule(manifest) {
|
export async function fetchAndCreateModule(manifest) {
|
||||||
console.log(`Fetching ${manifest}...`)
|
console.log(`[${manifest.id}] fetchAndCreateModule() | Fetching ${manifest}...`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await got.get(manifest)
|
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
|
// 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
|
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 target = manifest?.remote_url ?? manifest
|
||||||
const _module = await fetchAndCreateModule(manifest)
|
|
||||||
const remoteUrl = lodash.clone(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 {
|
} else {
|
||||||
if (!fs.existsSync(manifest)) {
|
if (!fs.existsSync(target)) {
|
||||||
throw new Error(`Manifest not found: ${manifest}`)
|
throw new Error(`Manifest not found: ${target}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.statSync(manifest).isFile()) {
|
if (!fs.statSync(target).isFile()) {
|
||||||
throw new Error(`Manifest is not a file: ${manifest}`)
|
throw new Error(`Manifest is not a file: ${target}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const manifestFilePath = lodash.clone(manifest)
|
manifest = require(target)
|
||||||
|
|
||||||
manifest = require(manifest)
|
|
||||||
|
|
||||||
if (!just_read) {
|
|
||||||
// copy manifest
|
|
||||||
fs.copyFileSync(manifestFilePath, path.resolve(MANIFEST_PATH, path.basename(manifest)))
|
|
||||||
|
|
||||||
manifest.remote_url = manifestFilePath
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return manifest
|
return manifest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user