-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmeta.ts
73 lines (59 loc) · 1.87 KB
/
meta.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import metablock from "rollup-plugin-userscript-metablock";
import type { Plugin } from "rollup";
import { readFileSync } from "fs";
import { join } from "path";
const pkg = JSON.parse(readFileSync('package.json').toString("utf-8"));
// Required external resources from npm
const PKG_RESOURCES = {
gulagcleaner_wasm: "gulagcleaner_wasm_bg.wasm",
};
// Requiered js files from npm
const PKG_REQS = {
"pdf-lib": "dist/pdf-lib.min.js",
"jszip": "dist/jszip.min.js"
};
// Static required js files
const EXTERNAL_REQS = ["https://openuserjs.org/src/libs/sizzle/GM_config.js"];
// Get dependency version
const getPkgVer = (pkg: string): string => {
const jsonStr = readFileSync(join("node_modules", pkg, "package.json"));
const json = JSON.parse(jsonStr.toString("utf-8"));
return json.version;
};
// Build map from PKG_RESOURCES
const getResources = (): Record<string, string> => {
let entries: Record<string, string> = {};
const arr = Object.entries(PKG_RESOURCES);
for (const el of arr) {
const ver = getPkgVer(el[0]);
entries[el[0]] = `https://cdn.jsdelivr.net/npm/${el[0]}@${ver}/${el[1]}`;
}
return entries;
};
// Build array from PKG_RQS and EXTERNAL_REQS
const getRequires = (): string[] => {
const arr = Object.entries(PKG_REQS);
const els: string[] = EXTERNAL_REQS;
for (const el of arr) {
const ver = getPkgVer(el[0]);
els.push(`https://cdn.jsdelivr.net/npm/${el[0]}@${ver}/${el[1]}`);
}
return els;
};
const getMetablock = (): Plugin => {
return metablock({
file: "meta.json",
override: {
name: pkg.displayName,
version: pkg.version,
description: pkg.description,
homepage: pkg.homepage,
author: pkg.author,
license: pkg.license,
// @ts-expect-error dependency typing not configed properly
require: getRequires(),
resource: getResources(),
},
});
};
export default getMetablock;