read from base_manifest.json

This commit is contained in:
amsyarasyiq 2023-04-05 16:27:53 +08:00
parent 9a98225dd7
commit c7f43e403d
9 changed files with 29 additions and 60 deletions

View file

@ -23,7 +23,8 @@
"rules": {
"indent": [
"error",
4
4,
{ "SwitchCase": 1 }
],
"quotes": [
"error",

9
base_manifest.json Normal file
View file

@ -0,0 +1,9 @@
{
"authors": [
{
"name": "amsyarasyiq",
"id": "492949202121261067"
}
],
"main": "src/index.ts"
}

View file

@ -1,8 +1,7 @@
/* eslint-disable indent */
import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import { createHash } from "crypto";
import { readdirSync, readFileSync, writeFileSync } from "fs";
import { readFile, readdir, writeFile } from "fs/promises";
import { argv } from "process";
import { rollup, watch } from "rollup";
@ -16,7 +15,7 @@ const inputPlugins = args.filter(x => !x.startsWith("-"));
const flags = args.map(x => x.toLowerCase()).filter(x => x.startsWith("-"));
const isWatch = flags.includes("--watch") || flags.includes("-w");
const toBuild = inputPlugins.length ? inputPlugins : readdirSync("./plugins");
const toBuild = inputPlugins.length ? inputPlugins : await readdir("./plugins");
console.log(`Building ${toBuild.length} plugin(s)...`);
@ -40,7 +39,13 @@ console.log("\n" + (
isWatch && console.log("\nWatching for changes...");
async function buildPlugin(plugin) {
const manifest = JSON.parse(readFileSync(`./plugins/${plugin}/manifest.json`).toString());
if (plugin.endsWith(".ts")) return;
const manifest = Object.assign(
JSON.parse(await readFile("./base_manifest.json")),
JSON.parse(await readFile(`./plugins/${plugin}/manifest.json`))
);
const entry = "index.js";
const outPath = `./dist/${plugin}/${entry}`;
@ -102,15 +107,17 @@ async function buildPlugin(plugin) {
]
};
Object.assign(manifest, {
hash: createHash("sha256").update(await readFile(outPath)).digest("hex"),
main: entry
});
if (!isWatch) {
const bundle = await rollup(options);
await bundle.write(options.output);
await bundle.close();
const toHash = readFileSync(outPath);
manifest.hash = createHash("sha256").update(toHash).digest("hex");
manifest.main = "index.js";
writeFileSync(`./dist/${plugin}/manifest.json`, JSON.stringify(manifest));
await writeFile(`./dist/${plugin}/manifest.json`, JSON.stringify(manifest));
console.log(`${plugin}: ` + "\x1b[32m" + "Build succeed!" + "\x1b[0m");
return;
@ -119,28 +126,22 @@ async function buildPlugin(plugin) {
const watcher = watch(options);
return await new Promise((resolve, reject) => {
watcher.on("event", (event) => {
watcher.on("event", async (event) => {
switch (event.code) {
case "BUNDLE_END": {
event.result.close();
const toHash = readFileSync(outPath);
manifest.hash = createHash("sha256").update(toHash).digest("hex");
manifest.main = "index.js";
writeFileSync(`./dist/${plugin}/manifest.json`, JSON.stringify(manifest));
await writeFile(`./dist/${plugin}/manifest.json`, JSON.stringify(manifest));
console.log(`${plugin}: ` + "\x1b[32m" + `Build succeed! (${event.duration}ms)` + "\x1b[0m");
resolve();
break;
}
case "ERROR":
console.error(`${plugin}: ` + "\x1b[31m", "Failed! :(", "\x1b[0m");
reject(event.error);
break;
case "FATAL":
console.error(`${plugin}: ` + "\x1b[31m", "Failed! :(", "\x1b[0m");
reject(event.error);
process.exit(1);
break;
}
});
});

View file

@ -1,13 +1,6 @@
{
"name": "HideGiftButton",
"description": "Hides the gift button in the chat input.",
"authors": [
{
"name": "amsyarasyiq",
"id": "492949202121261067"
}
],
"main": "src/index.ts",
"vendetta": {
"icon": "ic_gift_24px"
}

View file

@ -1,13 +1,6 @@
{
"name": "Last.fm",
"description": "Show off your last.fm status on your Discord profile.",
"authors": [
{
"name": "amsyarasyiq",
"id": "492949202121261067"
}
],
"main": "src/index.ts",
"vendetta": {
"icon": "ic_stage_music"
}

View file

@ -1,13 +1,6 @@
{
"name": "MoreConfirm",
"description": "Prompts confirmations before making irreversible actions.",
"authors": [
{
"name": "amsyarasyiq",
"id": "492949202121261067"
}
],
"main": "src/index.ts",
"vendetta": {
"icon": "check"
}

View file

@ -1,13 +1,6 @@
{
"name": "NoAutoReplyMention",
"description": "Turns off auto mention when replying to someone.",
"authors": [
{
"name": "amsyarasyiq",
"id": "492949202121261067"
}
],
"main": "src/index.ts",
"vendetta": {
"icon": "ic_notif_off"
}

View file

@ -1,13 +1,6 @@
{
"name": "NoIdle",
"description": "Prevent status from idling when Discord is in the background.",
"authors": [
{
"name": "amsyarasyiq",
"id": "492949202121261067"
}
],
"main": "src/index.ts",
"vendetta": {
"icon": "StatusIdle"
}

View file

@ -1,13 +1,6 @@
{
"name": "RichPresence",
"description": "Sets Discord Rich Presence for your profile.",
"authors": [
{
"name": "amsyarasyiq",
"id": "492949202121261067"
}
],
"main": "src/index.ts",
"vendetta": {
"icon": "games"
}