diff options
author | Justice Almanzar <superdash993@gmail.com> | 2023-08-15 23:32:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-16 01:32:11 +0200 |
commit | ffdf63563bab53a65b2a1a318f0f05e7917de002 (patch) | |
tree | 4b48475a76471434f5dad7fcd987aae8373b39b8 /scripts | |
parent | 55b755b2df7e186df8fb253742478bca146fbf46 (diff) | |
download | Vencord-ffdf63563bab53a65b2a1a318f0f05e7917de002.tar.gz Vencord-ffdf63563bab53a65b2a1a318f0f05e7917de002.tar.bz2 Vencord-ffdf63563bab53a65b2a1a318f0f05e7917de002.zip |
feat(plugins): Web/Vesktop AI Noise Suppression powered by RNNoise (#1477)
Co-authored-by: V <vendicated@riseup.net>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/build/common.mjs | 16 | ||||
-rw-r--r-- | scripts/generatePluginList.ts | 11 | ||||
-rw-r--r-- | scripts/utils.mjs | 30 |
3 files changed, 44 insertions, 13 deletions
diff --git a/scripts/build/common.mjs b/scripts/build/common.mjs index 2875a9c..b63ea61 100644 --- a/scripts/build/common.mjs +++ b/scripts/build/common.mjs @@ -27,6 +27,7 @@ import { promisify } from "util"; // wtf is this assert syntax import PackageJSON from "../../package.json" assert { type: "json" }; +import { getPluginTarget } from "../utils.mjs"; export const VERSION = PackageJSON.version; export const BUILD_TIMESTAMP = Date.now(); @@ -81,14 +82,13 @@ export const globPlugins = kind => ({ if (file.startsWith("_") || file.startsWith(".")) continue; if (file === "index.ts") continue; - const fileBits = file.split("."); - if (fileBits.length > 2 && ["ts", "tsx"].includes(fileBits.at(-1))) { - const mod = fileBits.at(-2); - if (mod === "dev" && !watch) continue; - if (mod === "web" && kind === "discordDesktop") continue; - if (mod === "desktop" && kind === "web") continue; - if (mod === "discordDesktop" && kind !== "discordDesktop") continue; - if (mod === "vencordDesktop" && kind !== "vencordDesktop") continue; + const target = getPluginTarget(file); + if (target) { + if (target === "dev" && !watch) continue; + if (target === "web" && kind === "discordDesktop") continue; + if (target === "desktop" && kind === "web") continue; + if (target === "discordDesktop" && kind !== "discordDesktop") continue; + if (target === "vencordDesktop" && kind !== "vencordDesktop") continue; } const mod = `p${i}`; diff --git a/scripts/generatePluginList.ts b/scripts/generatePluginList.ts index c78c340..ea08d30 100644 --- a/scripts/generatePluginList.ts +++ b/scripts/generatePluginList.ts @@ -21,6 +21,8 @@ import { access, readFile } from "fs/promises"; import { join } from "path"; import { BigIntLiteral, createSourceFile, Identifier, isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isSatisfiesExpression, isStringLiteral, isVariableStatement, NamedDeclaration, NodeArray, ObjectLiteralExpression, ScriptTarget, StringLiteral, SyntaxKind } from "typescript"; +import { getPluginTarget } from "./utils.mjs"; + interface Dev { name: string; id: string; @@ -157,11 +159,10 @@ async function parseFile(fileName: string) { if (!data.name || !data.description || !data.authors) throw fail("name, description or authors are missing"); - const fileBits = fileName.split("."); - if (fileBits.length > 2 && ["ts", "tsx"].includes(fileBits.at(-1)!)) { - const mod = fileBits.at(-2)!; - if (!["web", "discordDesktop", "vencordDesktop", "dev"].includes(mod)) throw fail(`invalid target ${fileBits.at(-2)}`); - data.target = mod as any; + const target = getPluginTarget(fileName); + if (target) { + if (!["web", "discordDesktop", "vencordDesktop", "dev"].includes(target)) throw fail(`invalid target ${target}`); + data.target = target as any; } return data; diff --git a/scripts/utils.mjs b/scripts/utils.mjs new file mode 100644 index 0000000..46a9466 --- /dev/null +++ b/scripts/utils.mjs @@ -0,0 +1,30 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +/** + * @param {string} filePath + * @returns {string | null} + */ +export function getPluginTarget(filePath) { + const pathParts = filePath.split(/[/\\]/); + if (/^index\.tsx?$/.test(filePath.at(-1))) pathParts.pop(); + + const identifier = pathParts.at(-1).replace(/\.tsx?$/, ""); + const identiferBits = identifier.split("."); + return identiferBits.length === 1 ? null : identiferBits.at(-1); +} |