Add auto deploy

This commit is contained in:
Vendicated
2023-04-20 01:24:02 +02:00
parent 0417e9c5ea
commit 6c9aa23ef9
2 changed files with 36 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
import { context } from "esbuild"; import { context } from "esbuild";
import { readdirSync } from "fs"; import { cpSync, existsSync, readdirSync, rmSync } from "fs";
import vencordDep from "./vencordDep.mjs"; import vencordDep from "./vencordDep.mjs";
import Config from "../config.json" assert { type: "json" };
import { join } from "path";
const plugins = readdirSync("./plugins"); const plugins = readdirSync("./plugins");
@@ -11,7 +13,7 @@ const contexts = await Promise.all(
plugins.map(p => plugins.map(p =>
context({ context({
entryPoints: [`./plugins/${p}`], entryPoints: [`./plugins/${p}`],
outfile: `dist/${p}/index.js`, outfile: `dist/${p}.js`,
format: "iife", format: "iife",
globalName: "VencordPlugin", globalName: "VencordPlugin",
jsxFactory: "Vencord.Webpack.Common.React.createElement", jsxFactory: "Vencord.Webpack.Common.React.createElement",
@@ -28,6 +30,33 @@ const contexts = await Promise.all(
) )
); );
function deploy() {
const { autoDeploy, vencordDataDir } = Config;
if (!autoDeploy) return;
if (!existsSync(vencordDataDir)) {
console.warn("Vencord data directory does not exist:", vencordDataDir);
console.warn("Thus, deployment is skipped");
console.warn("You can fix this by editing config.json");
return;
}
if (autoDeploy && existsSync(vencordDataDir)) {
const pluginDir = join(vencordDataDir, "plugins");
rmSync(pluginDir, {
recursive: true,
force: true
});
cpSync("dist", pluginDir, {
recursive: true
});
console.log("Deployed Plugins to", pluginDir);
}
}
if (watch) { if (watch) {
await Promise.all(contexts.map(ctx => ctx.watch())); await Promise.all(contexts.map(ctx => ctx.watch()));
} else { } else {
@@ -37,4 +66,5 @@ if (watch) {
await ctx.dispose(); await ctx.dispose();
}) })
); );
deploy();
} }

4
config.json Normal file
View File

@@ -0,0 +1,4 @@
{
"autoDeploy": true,
"vencordDataDir": "C:/Users/Ven/AppData/Roaming/VencordDesktop/VencordDesktop"
}