a
This commit is contained in:
parent
9a83a6a012
commit
925e5ec850
5 changed files with 246 additions and 11 deletions
51
native.ts
51
native.ts
|
@ -1,7 +1,11 @@
|
|||
import { exec, spawn } from "child_process";
|
||||
import { IpcMainInvokeEvent } from "electron";
|
||||
import { read, readdir, readdirSync, readFileSync, rmSync } from "fs";
|
||||
|
||||
const PLUGIN_META_REGEX = /export default definePlugin\((?:\s|\/(?:\/|\*).*)*{\s*(?:\s|\/(?:\/|\*).*)*name:\s*(?:"|'|`)(.*)(?:"|'|`)(?:\s|\/(?:\/|\*).*)*,(?:\s|\/(?:\/|\*).*)*(?:\s|\/(?:\/|\*).*)*description:\s*(?:"|'|`)(.*)(?:"|'|`)(?:\s|\/(?:\/|\*).*)*/;
|
||||
|
||||
export async function cloneRepo(_: IpcMainInvokeEvent, repo: string, clonePath: string): Promise<any> {
|
||||
rmSync(clonePath, { recursive: true, force: true });
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`git clone ${repo} ${clonePath}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
|
@ -13,3 +17,50 @@ export async function cloneRepo(_: IpcMainInvokeEvent, repo: string, clonePath:
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPluginMeta(_, path: string): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const files = readdirSync(path);
|
||||
let fileToRead: "index.ts" | "index.tsx" | "index.js" | "index.jsx" | undefined;
|
||||
files.forEach(f => {
|
||||
if (f === "index.ts") fileToRead = "index.ts";
|
||||
if (f === "index.tsx") fileToRead = "index.tsx";
|
||||
if (f === "index.js") fileToRead = "index.js";
|
||||
if (f === "index.jsx") fileToRead = "index.jsx";
|
||||
});
|
||||
if (!fileToRead) reject();
|
||||
|
||||
const file = readFileSync(`${path}/${fileToRead}`, "utf8");
|
||||
const rawMeta = file.match(PLUGIN_META_REGEX);
|
||||
resolve({
|
||||
name: rawMeta![1],
|
||||
description: rawMeta![2],
|
||||
usesPreSend: file.includes("PreSendListener")
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteFolder(_, path: string) {
|
||||
rmSync(path, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
export async function build(_: IpcMainInvokeEvent, path: string): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`pnpm build`, {
|
||||
cwd: path
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
return reject(
|
||||
stderr
|
||||
);
|
||||
}
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPlugins(_, path: string): Promise<string[]> {
|
||||
return new Promise((resolve) => {
|
||||
return resolve(readdirSync(path));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue