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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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