Skip to content

Commit

Permalink
Readd author link to meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Jan 23, 2023
1 parent 711e159 commit 2b1aa51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
8 changes: 6 additions & 2 deletions packages/bd-meta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ export async function resolvePkg(dir: string): Promise<string> {
return undefined;
}

export async function readMetaFromPkg(file: string): Promise<Meta> {
export interface Options {
authorGithub?: boolean;
}

export async function readMetaFromPkg(file: string, {authorGithub = false}: Options = {}): Promise<Meta> {
const pkg = JSON.parse(await fs.readFile(file, "utf8")) as PackageWithMeta;
return {
name: upperFirst(camelCase(pkg.name)),
version: pkg.version,
author: typeof pkg.author === "string" ? pkg.author : pkg.author.name,
authorLink: typeof pkg.author === "object" ? pkg.author.url : undefined,
authorLink: typeof pkg.author === "object" ? pkg.author.url : (authorGithub ? `https://github.com/${pkg.author}` : undefined),
description: pkg.description,
website: pkg.homepage,
...pkg.meta
Expand Down
20 changes: 11 additions & 9 deletions packages/rollup-plugin-bd-meta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {resolvePkg, readMetaFromPkg, writeMeta, Meta} from "bd-meta";

export interface Options {
meta?: Partial<Meta>;
authorGithub?: boolean;
}

/**
* Rollup plugin for BetterDiscord plugin meta generation.
*/
export function bdMeta(options: Options = {}): Plugin {
export function bdMeta({meta, authorGithub}: Options = {}): Plugin {
const pkgFiles: Record<string, string> = {};

return {
Expand Down Expand Up @@ -39,15 +40,16 @@ export function bdMeta(options: Options = {}): Plugin {
async handler(code, chunk) {
if (chunk.isEntry) {
const pkg = pkgFiles[chunk.facadeModuleId];
return {
code: writeMeta({
...pkg ? await readMetaFromPkg(pkg) : {},
...options.meta
}) + code,
map: {
mappings: ""
}
const combinedMeta = {
...pkg ? await readMetaFromPkg(pkg, {authorGithub}) : {},
...meta
};
if (Object.keys(combinedMeta).length > 0) {
return {
code: writeMeta(combinedMeta) + code,
map: {mappings: ""}
};
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ function generateRollupConfig(name: string, inputPath: string, outputPath: strin
meta: {
website: repository,
source: `${repository}/tree/master/src/${path.basename(inputPath)}`
}
},
authorGithub: true
}),
bdWScript()
],
Expand Down

0 comments on commit 2b1aa51

Please sign in to comment.