-
Notifications
You must be signed in to change notification settings - Fork 0
/
createRequireFile.ts
45 lines (39 loc) · 1.38 KB
/
createRequireFile.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
import fs from "fs/promises";
import path from "path";
import { metadata } from "./metadata.ts";
const packageJsonPath = path.join(__dirname, "package.json");
// const matchUrl = 'https://x.com/home'; // replace with your match URL
const distDir = path.join(__dirname, "dist");
async function createUserscriptFile() {
try {
const files = await fs.readdir(distDir);
const jsFile = files.find((file) => path.extname(file) === ".js");
const packageJsonContent = await fs.readFile(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonContent);
const repoName = packageJson.name;
const version = packageJson.version;
const author = packageJson.author;
const description = packageJson.description;
const matchUrl = metadata.match;
const icon = metadata.icon;
if (jsFile) {
const userscriptContent = `// ==UserScript==
// @name ${repoName}
// @namespace npm/vite-plugin-monkey
// @version ${version}
// @author ${author ?? "monkey"}
// @description ${description ?? "Load script"}
// @icon ${icon}
// @match ${matchUrl}
// @require file:///${path.join(distDir, jsFile)}
// ==/UserScript==`;
await fs.writeFile("require.user.js", userscriptContent);
console.log("Userscript file created successfully!");
} else {
console.error("No .js files found in /dist");
}
} catch (err) {
console.error(err);
}
}
createUserscriptFile();