Skip to content

Commit

Permalink
Remove zlib support and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Neodymium7 committed Dec 10, 2024
1 parent aeae5aa commit 0efe07c
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 3,009 deletions.
2 changes: 0 additions & 2 deletions .github/FUNDING.yml

This file was deleted.

10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# v5.0.0

- Removed Zere's Plugin Library support.
- Plugin configurations moved to `manifest.json` file (previously `plugin.json`).
- Moved `module-comments` under `format` option in the bundler configuration.
- `betterdiscord` now exports extra utility types from BdApi typings.
- Style strings will be expanded instead of minified when plugins are built.

# v4.0.0

- Removed library.
- Added `defineConfig` function for autocomplete and types for config files.
- Fixed import aliases not working properly and updated their usage (See Wiki).
- Added `module-comments` option.
- Added `format` option to configure formatting such as indentation.
- Removed `reuire-config` option. The bundler will now always require configuration files.
- Removed `require-config` option. The bundler will now always require configuration files.
- Many other minor fixes

# v3.4.0
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@ npm i bundlebd -D
1. [What?! Another Discord plugin bundler/builder/transpiler?](https://github.com/Neodymium7/BundleBD/wiki/FAQ#1-what-another-discord-plugin-bundlerbuildertranspiler-arent-there-a-few-of-those-already)
2. [Why are typings/autocomplete not working?](https://github.com/Neodymium7/BundleBD/wiki/FAQ#2-why-are-typingsautocomplete-not-working)
3. [I have a feature/change suggestion or bug to report, what should I do?](https://github.com/Neodymium7/BundleBD/wiki/FAQ#3-i-have-a-featurechange-suggestion-or-bug-to-report-what-should-i-do)

## Dontate

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/neodymium7)
8 changes: 5 additions & 3 deletions bin/config/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface BundleBDOptions {
input: string;
output: string;
dev: boolean;
moduleComments: boolean;
format: {
moduleComments: boolean;
indent: string;
};
bdPath?: string;
Expand All @@ -21,16 +21,16 @@ type OptionsKeys = (keyof BundleBDOptions)[];

const configFileName = "bundlebd.config.js";

const universalOptionKeys: OptionsKeys = ["input", "output", "moduleComments", "bdPath"];
const universalOptionKeys: OptionsKeys = ["input", "output", "bdPath"];
const configOptionKeys: OptionsKeys = [...universalOptionKeys, "format", "importAliases", "postcssPlugins"];
const argOptionKeys: OptionsKeys = [...universalOptionKeys, "dev", "plugin"];

const defaultOptions: BundleBDOptions = {
input: "src",
output: "dist",
dev: false,
moduleComments: true,
format: {
moduleComments: true,
indent: "\t",
},
};
Expand Down Expand Up @@ -91,6 +91,8 @@ export default function getBundlerOptions(argv: string[]): BundleBDOptions {
if (config.hasOwnProperty("input") && !config.input) Logger.error("The 'input' option cannot be undefined.");
if (config.hasOwnProperty("output") && !config.output) Logger.error("The 'output' option cannot be undefined.");

if (config.format) config.format = { ...defaultOptions.format, ...config.format };

configOptions = config;
}

Expand Down
20 changes: 4 additions & 16 deletions bin/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,16 @@ import Logger from "../logger";
import { Meta } from "bdapi";
import { BundleBDOptions } from "./bundler";

export interface ZLibraryConfig {
info?: any;
changelog?: {
title: string;
type?: string;
items: string[];
}[];
defaultConfig?: any;
}

export interface PluginConfiguration {
entry: string;
installScript: boolean;
zlibrary: boolean | ZLibraryConfig;
}

const pluginConfigFileName = "plugin.json";
const pluginConfigFileName = "manifest.json";

const defaultPluginConfig = {
entry: "index",
installScript: true,
zlibrary: false,
};

const metaKeys = [
Expand All @@ -44,7 +32,7 @@ const metaKeys = [

const requiredMetaKeys = ["name", "author", "description", "version"];

const pluginConfigKeys = ["entry", "installScript", "zlibrary"];
const pluginConfigKeys = ["entry", "installScript"];

export default function getPluginConfig(options: BundleBDOptions) {
const pluginConfigPath = path.join(process.cwd(), options.input, pluginConfigFileName);
Expand All @@ -60,8 +48,6 @@ export default function getPluginConfig(options: BundleBDOptions) {
pluginMeta[key] = config[key];
} else if (pluginConfigKeys.includes(key)) {
pluginConfig[key] = config[key];
} else {
Logger.warn(`Unknown key '${key}' in ${pluginConfigFileName}`);
}
}
} else {
Expand All @@ -73,5 +59,7 @@ export default function getPluginConfig(options: BundleBDOptions) {
Logger.error(`Missing required configuration option '${key}' in ${pluginConfigFileName}.`);
}

if (options.dev) pluginMeta.version += "-dev";

return { pluginConfig, pluginMeta };
}
9 changes: 2 additions & 7 deletions bin/config/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import styleLoader from "../plugins/styleloader";
import text from "../plugins/text";
import moduleComments from "../plugins/modulecomments";
import constPlugin from "../plugins/const";
import meta from "../plugins/meta";
import expandedStyles from "../plugins/expandedstyles";

type AliasEntry = { find: RegExp; replacement: string };
Expand Down Expand Up @@ -69,11 +68,8 @@ const createAliases = (aliases: Record<string, string>) => {
export default function getRollupConfig(options: BundleBDOptions, pluginConfig: PluginConfiguration, pluginMeta: Meta) {
const globals = {
betterdiscord: `new BdApi("${pluginMeta.name}")`,
zlibrary: "Library",
"zlibrary/plugin": "BasePlugin",
react: "BdApi.React",
"react-dom": "BdApi.ReactDOM",
lodash: "_",
};

const entryDir = path.join(process.cwd(), options.input);
Expand Down Expand Up @@ -105,7 +101,7 @@ export default function getRollupConfig(options: BundleBDOptions, pluginConfig:
input: entryPath,
output: {
file: outputPath,
format: pluginConfig.zlibrary ? "iife" : "cjs",
format: "cjs",
exports: "default",
globals: {
...globals,
Expand Down Expand Up @@ -161,8 +157,7 @@ export default function getRollupConfig(options: BundleBDOptions, pluginConfig:
}),
constPlugin({ regex: constRegex }),
replace(createReplaced(globals)),
meta(pluginMeta),
options.moduleComments && moduleComments({ root: entryDir, aliases: options.importAliases }),
options.format.moduleComments && moduleComments({ root: entryDir, aliases: options.importAliases }),
options.importAliases &&
alias({
entries: createAliases(options.importAliases),
Expand Down
12 changes: 0 additions & 12 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Logger from "./logger";
import { checkDirExists } from "./utils";
import installScript from "./templates/installscript";
import meta from "./templates/meta";
import zlibrary from "./templates/zlibrary";

const argv = process.argv.slice(2);

Expand All @@ -36,22 +35,11 @@ async function bundle(bundle?: RollupBuild) {
.replace(/\/\* @__PURE__ \*\/ /g, "")
.replace("\nrequire('react');\n", "\n");

if (pluginConfig.zlibrary) code = zlibrary(code, pluginMeta, pluginConfig.zlibrary, options.format.indent);
if (pluginConfig.installScript) code = installScript(code, options.format.indent);
code = meta(code, pluginMeta);

const importsZlib = /\nvar \S+ = Library;\n/.test(code);
const importsBasePlugin = /\nvar \S+ = BasePlugin;\n/.test(code);

const outputPath: string = (rollupConfig.output as OutputOptions).file;

// Warn if importing zlib without building with zlib support
if ((importsZlib || importsBasePlugin) && !pluginConfig.zlibrary) {
Logger.warn(
"It appears the plugin imports ZeresPluginLibrary, but is not being built with ZeresPluginLibrary support. Did you mean to set 'zlibrary' to true in the plugin's configuration?"
);
}

fs.writeFileSync(outputPath, code);
Logger.log(`Done! Successfully bundled plugin '${pluginMeta.name}'`);

Expand Down
18 changes: 0 additions & 18 deletions bin/plugins/meta.ts

This file was deleted.

4 changes: 0 additions & 4 deletions bin/plugins/modulecomments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export default function moduleComments(options: ModuleCommentsOptions): Plugin {
else if (id.includes("node_modules")) {
id = id.slice(id.indexOf("node_modules") + 13).split(path.sep)[0];
}
// Meta
else if (id === "meta.json") {
id = "meta";
}
// Import aliases
else if (options.aliases) {
for (const key in options.aliases) {
Expand Down
50 changes: 0 additions & 50 deletions bin/templates/zlibrary.ts

This file was deleted.

4 changes: 0 additions & 4 deletions bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@ export function ensureDirExists(path: string, message?: string) {
Logger.error(message ?? `Cannot find directory '${path}'`);
}
}

export function stringify(object: unknown, indent: string): string {
return JSON.stringify(object, null, indent).replace(/"([^"]+)":/g, "$1:");
}
Loading

0 comments on commit 0efe07c

Please sign in to comment.