From 6ab721f051dff6c8ee1f344e0a523182caf7411c Mon Sep 17 00:00:00 2001 From: Kodie Date: Mon, 23 Sep 2024 16:47:29 +1200 Subject: [PATCH] refactor: move linked roles to core package (#138) * refactor: move linked roles to core package * chore: remove entry from tsconfig * chore: fix undefined existing in docs path name on windows * chore: refactor copy api script to support "subpackages" --- .changeset/itchy-spiders-grin.md | 5 + apps/rocko/package.json | 1 - apps/rocko/src/index.ts | 4 +- formatter.mjs | 4 +- packages/carbon/package.json | 10 ++ .../src/plugins/linked-roles}/LinkedRoles.ts | 2 +- .../src/plugins/linked-roles}/index.ts | 0 .../src/plugins/linked-roles}/types.ts | 0 packages/carbon/typedoc.json | 2 +- packages/linked-roles/CHANGELOG.md | 104 ----------------- packages/linked-roles/README.md | 13 --- packages/linked-roles/package.json | 23 ---- packages/linked-roles/tsconfig.json | 11 -- packages/linked-roles/typedoc.json | 7 -- pnpm-lock.yaml | 9 -- website/content/carbon/meta.json | 1 + website/content/carbon/plugins/index.mdx | 6 + .../plugins/linked-roles.mdx} | 5 +- website/content/carbon/plugins/meta.json | 1 + website/content/linked-roles/meta.json | 4 - website/copy-api.sh | 105 +++++++++++++++--- website/modes.ts | 14 +-- 22 files changed, 123 insertions(+), 208 deletions(-) create mode 100644 .changeset/itchy-spiders-grin.md rename packages/{linked-roles/src => carbon/src/plugins/linked-roles}/LinkedRoles.ts (99%) rename packages/{linked-roles/src => carbon/src/plugins/linked-roles}/index.ts (100%) rename packages/{linked-roles/src => carbon/src/plugins/linked-roles}/types.ts (100%) delete mode 100644 packages/linked-roles/CHANGELOG.md delete mode 100644 packages/linked-roles/README.md delete mode 100644 packages/linked-roles/package.json delete mode 100644 packages/linked-roles/tsconfig.json delete mode 100644 packages/linked-roles/typedoc.json create mode 100644 website/content/carbon/plugins/index.mdx rename website/content/{linked-roles/index.mdx => carbon/plugins/linked-roles.mdx} (89%) create mode 100644 website/content/carbon/plugins/meta.json delete mode 100644 website/content/linked-roles/meta.json diff --git a/.changeset/itchy-spiders-grin.md b/.changeset/itchy-spiders-grin.md new file mode 100644 index 00000000..81debec2 --- /dev/null +++ b/.changeset/itchy-spiders-grin.md @@ -0,0 +1,5 @@ +--- +"@buape/carbon": minor +--- + +refactor: move linked roles to core package diff --git a/apps/rocko/package.json b/apps/rocko/package.json index be071f36..52c97488 100644 --- a/apps/rocko/package.json +++ b/apps/rocko/package.json @@ -10,7 +10,6 @@ }, "dependencies": { "@buape/carbon": "workspace:*", - "@buape/carbon-linked-roles": "workspace:*", "@buape/carbon-nodejs": "workspace:*", "@types/node": "22.5.5" }, diff --git a/apps/rocko/src/index.ts b/apps/rocko/src/index.ts index a0401a51..eaae1bfe 100644 --- a/apps/rocko/src/index.ts +++ b/apps/rocko/src/index.ts @@ -1,11 +1,11 @@ import { dirname } from "node:path" import { fileURLToPath } from "node:url" import { Client, ClientMode } from "@buape/carbon" +import { loadCommands, serve } from "@buape/carbon-nodejs" import { ApplicationRoleConnectionMetadataType, LinkedRoles -} from "@buape/carbon-linked-roles" -import { loadCommands, serve } from "@buape/carbon-nodejs" +} from "@buape/carbon/linked-roles" const __dirname = dirname(fileURLToPath(import.meta.url)) if ( diff --git a/formatter.mjs b/formatter.mjs index e1e6ab46..7fd600d5 100644 --- a/formatter.mjs +++ b/formatter.mjs @@ -1,4 +1,4 @@ -import { dirname, relative } from "node:path" +import { dirname, relative, sep } from "node:path" // @ts-check import { fileURLToPath } from "node:url" import { MarkdownPageEvent } from "typedoc-plugin-markdown" @@ -27,7 +27,7 @@ export function load(app) { (page) => { if (!page.contents) return const rel = relative(root, dirname(page.filename)) - const parts = rel.split("/") + const parts = rel.split(sep) const pkg = parts[1] const dirParts = parts.slice(3) const dir = dirParts.length ? `${dirParts.join("/")}/` : "" diff --git a/packages/carbon/package.json b/packages/carbon/package.json index 03bf38d8..8d92d7cd 100644 --- a/packages/carbon/package.json +++ b/packages/carbon/package.json @@ -4,6 +4,16 @@ "type": "module", "main": "./dist/src/index.js", "repository": "github:buape/carbon", + "exports": { + ".": { + "types": "./dist/src/index.d.ts", + "import": "./dist/src/index.js" + }, + "./*": { + "types": "./dist/src/plugins/*/index.d.ts", + "import": "./dist/src/plugins/*/index.js" + } + }, "scripts": { "build": "tsc", "dev": "tsc -w", diff --git a/packages/linked-roles/src/LinkedRoles.ts b/packages/carbon/src/plugins/linked-roles/LinkedRoles.ts similarity index 99% rename from packages/linked-roles/src/LinkedRoles.ts rename to packages/carbon/src/plugins/linked-roles/LinkedRoles.ts index 963a0f7b..9df60ede 100644 --- a/packages/linked-roles/src/LinkedRoles.ts +++ b/packages/carbon/src/plugins/linked-roles/LinkedRoles.ts @@ -1,4 +1,4 @@ -import type { Client } from "@buape/carbon" +import type { Client } from "../../classes/Client.js" import { ApplicationRoleConnectionMetadataType, type LinkedRolesOptions diff --git a/packages/linked-roles/src/index.ts b/packages/carbon/src/plugins/linked-roles/index.ts similarity index 100% rename from packages/linked-roles/src/index.ts rename to packages/carbon/src/plugins/linked-roles/index.ts diff --git a/packages/linked-roles/src/types.ts b/packages/carbon/src/plugins/linked-roles/types.ts similarity index 100% rename from packages/linked-roles/src/types.ts rename to packages/carbon/src/plugins/linked-roles/types.ts diff --git a/packages/carbon/typedoc.json b/packages/carbon/typedoc.json index 83c0e874..0c8909be 100644 --- a/packages/carbon/typedoc.json +++ b/packages/carbon/typedoc.json @@ -1,7 +1,7 @@ { "$schema": "https://typedoc.org/schema.json", "extends": ["../../typedoc.json"], - "entryPoints": ["src/index.ts"], + "entryPoints": ["src/index.ts", "src/plugins/*/index.ts"], "name": "@buape/carbon", "out": "docs", "excludeExternals": true, diff --git a/packages/linked-roles/CHANGELOG.md b/packages/linked-roles/CHANGELOG.md deleted file mode 100644 index 98e60ef2..00000000 --- a/packages/linked-roles/CHANGELOG.md +++ /dev/null @@ -1,104 +0,0 @@ -# @buape/carbon-linked-roles - -## 0.2.2 - -### Patch Changes - -- Updated dependencies [63a6d07] - - @buape/carbon@0.5.0 - -## 0.2.1 - -### Patch Changes - -- 6b73575: chore: readme cleanups -- Updated dependencies [6b73575] - - @buape/carbon@0.4.2 - -## 0.2.0 - -### Minor Changes - -- 07b0817: fix: make side packages use peer dependencies - -### Patch Changes - -- Updated dependencies [558b73c] -- Updated dependencies [28f252f] -- Updated dependencies [50e360e] -- Updated dependencies [4475a84] -- Updated dependencies [29f8493] -- Updated dependencies [5bc4b84] -- Updated dependencies [6239590] -- Updated dependencies [0a22fa8] -- Updated dependencies [9456bf0] - - @buape/carbon@0.4.0 - -## 0.1.7 - -### Patch Changes - -- Updated dependencies [dcf5b44] -- Updated dependencies [c8e7c1c] - - @buape/carbon@0.3.2 - -## 0.1.6 - -### Patch Changes - -- Updated dependencies [c80ce0f] - - @buape/carbon@0.3.1 - -## 0.1.5 - -### Patch Changes - -- Updated dependencies [f8b608f] -- Updated dependencies [50c8200] -- Updated dependencies [a15bf55] -- Updated dependencies [51d84c3] - - @buape/carbon@0.3.0 - -## 0.1.4 - -### Patch Changes - -- Updated dependencies [9e93027] -- Updated dependencies [ad9666b] - - @buape/carbon@0.2.0 - -## 0.1.3 - -### Patch Changes - -- Updated dependencies - - @buape/carbon@0.1.3 - -## 0.1.2 - -### Patch Changes - -- Updated dependencies [2bdc7f3] -- Updated dependencies [e79c435] -- Updated dependencies [917416a] - - @buape/carbon@0.1.2 - -## 0.1.1 - -### Patch Changes - -- Updated dependencies [8438b8d] - - @buape/carbon@0.1.1 - -## 0.1.0 - -### Minor Changes - -- 1a00131: Initial beta! - - Featuring interactions, commands, messages, subcommands, options, linked roles, and more! - -### Patch Changes - -- Updated dependencies [1a00131] - - @buape/carbon@0.1.0 diff --git a/packages/linked-roles/README.md b/packages/linked-roles/README.md deleted file mode 100644 index ed1ba0ae..00000000 --- a/packages/linked-roles/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# @buape/carbon-linked-roles - -
-Carbon Wordmark - -Discord -NPM Version -NPM Downloads -
- -This package is part of [the Carbon framework](https://github.com/buape/carbon), check it out for more details. - -You can find the documentation for this package [here](https://carbon.buape.com/carbon/linked-roles). \ No newline at end of file diff --git a/packages/linked-roles/package.json b/packages/linked-roles/package.json deleted file mode 100644 index 5f767400..00000000 --- a/packages/linked-roles/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "@buape/carbon-linked-roles", - "version": "0.2.2", - "type": "module", - "main": "./dist/src/index.js", - "repository": "github:buape/carbon", - "scripts": { - "build": "tsc", - "dev": "tsc -w", - "docs": "typedoc" - }, - "license": "MIT", - "peerDependencies": { - "@buape/carbon": "workspace:^0.5.0" - }, - "devDependencies": { - "@buape/carbon": "workspace:*" - }, - "files": [ - "dist", - "LICENSE" - ] -} \ No newline at end of file diff --git a/packages/linked-roles/tsconfig.json b/packages/linked-roles/tsconfig.json deleted file mode 100644 index 458e52de..00000000 --- a/packages/linked-roles/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": [ - "src/**/*.ts", - "src/*.ts" - ], - "compilerOptions": { - "outDir": "dist", - "rootDir": "." - } -} \ No newline at end of file diff --git a/packages/linked-roles/typedoc.json b/packages/linked-roles/typedoc.json deleted file mode 100644 index 47bdce0c..00000000 --- a/packages/linked-roles/typedoc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "https://typedoc.org/schema.json", - "extends": ["../../typedoc.json"], - "entryPoints": ["src/index.ts"], - "name": "@buape/carbon-linked-roles", - "out": "docs" -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49a78b7b..da917aa7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -70,9 +70,6 @@ importers: '@buape/carbon': specifier: workspace:* version: link:../../packages/carbon - '@buape/carbon-linked-roles': - specifier: workspace:* - version: link:../../packages/linked-roles '@buape/carbon-nodejs': specifier: workspace:* version: link:../../packages/nodejs @@ -117,12 +114,6 @@ importers: specifier: ^22.5.5 version: 22.5.5 - packages/linked-roles: - devDependencies: - '@buape/carbon': - specifier: workspace:* - version: link:../carbon - packages/nodejs: dependencies: '@hono/node-server': diff --git a/website/content/carbon/meta.json b/website/content/carbon/meta.json index eda2e11f..af48b469 100644 --- a/website/content/carbon/meta.json +++ b/website/content/carbon/meta.json @@ -8,6 +8,7 @@ "...", "--- Usage ---", "classes", + "plugins", "helpful-guides", "even-more", "--- API Reference ---", diff --git a/website/content/carbon/plugins/index.mdx b/website/content/carbon/plugins/index.mdx new file mode 100644 index 00000000..d9751bb8 --- /dev/null +++ b/website/content/carbon/plugins/index.mdx @@ -0,0 +1,6 @@ +--- +title: Plugins +index: true +icon: Cable +--- + diff --git a/website/content/linked-roles/index.mdx b/website/content/carbon/plugins/linked-roles.mdx similarity index 89% rename from website/content/linked-roles/index.mdx rename to website/content/carbon/plugins/linked-roles.mdx index d94bed29..008a6b99 100644 --- a/website/content/linked-roles/index.mdx +++ b/website/content/carbon/plugins/linked-roles.mdx @@ -1,5 +1,6 @@ --- title: Linked Roles +description: Linked Roles are a handy feature of Discord that allows you to create roles that users have to meet certain criteria in order to claim those roles. --- Linked Roles are a handy feature of Discord that allows you to create roles that users have to meet certain criteria in order to claim those roles. @@ -17,13 +18,13 @@ Then, create a new instance of the `LinkedRoles` class, and pass it your metadat ### Installation - + ### Example ```ts title="src/index.ts" import { Client } from "@buape/carbon" -import { LinkedRoles } from "@buape/carbon-linked-roles" +import { LinkedRoles } from "@buape/carbon/linked-roles" const client = new Client({ clientId: "12345678901234567890", diff --git a/website/content/carbon/plugins/meta.json b/website/content/carbon/plugins/meta.json new file mode 100644 index 00000000..c79c9c0c --- /dev/null +++ b/website/content/carbon/plugins/meta.json @@ -0,0 +1 @@ +{ "title": "Plugins" } diff --git a/website/content/linked-roles/meta.json b/website/content/linked-roles/meta.json deleted file mode 100644 index 3b333fd1..00000000 --- a/website/content/linked-roles/meta.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "root": true, - "pages": ["--- Usage ---", "index", "--- API Reference ---", "...api"] -} diff --git a/website/copy-api.sh b/website/copy-api.sh index d002e037..838c9b83 100755 --- a/website/copy-api.sh +++ b/website/copy-api.sh @@ -1,15 +1,90 @@ -#!/usr/bin/env bash -# set -euo pipefail - -CONTENT_DIR="website/content" -cd .. -for d in packages/*/docs; do - PKG="$(basename "$(dirname "$d")")" - API_DIR="$CONTENT_DIR/$PKG/api" - echo "Copying $PKG to $API_DIR" - rm -rf "$API_DIR" - mkdir -p "$API_DIR" - cp -rv "$d"/* "$API_DIR" -done - -find . -type d -name "type-aliases" | xargs -I {} cp -v website/type-aliases.meta.json {}/meta.json \ No newline at end of file +#!/bin/bash + +WEBSITE_DIR="$(dirname "$(realpath "$0")")" +CONTENT_DIR="$WEBSITE_DIR/content" +PACKAGES_DIR="$WEBSITE_DIR/../packages" + +# Convert a kebab-case string to Title Case +# $1: The kebab-case string +kebab_to_title_case() { + echo "$1" | sed -e 's/-/ /g' -e 's/\b\(.\)/\u\1/g' +} + +# Copy API docs for each package +# $1: The package directory +copy_api_docs() { + for dir in $1; do + local pkg_name="$(basename "$dir")" + local from_dir="$PACKAGES_DIR/$pkg_name/docs" + local to_dir="$CONTENT_DIR/$pkg_name/api" + + rm -rf "$to_dir" + mkdir -p "$to_dir" + cp -r "$from_dir"/* "$to_dir" + done +} + +# Add meta.json files to the API doc pages that need them +# $1: The API directory +add_meta_files() { + for dir in $1; do + if [ -d "$api_dir/type-aliases" ]; then + echo "{ \"title\": \"Type Aliases\" }" >"$api_dir/type-aliases/meta.json" + fi + done +} + +# Process the subpackage (aka exports) of a package +# $1: The package name +# $2: The glob of subpackages +process_subpackage() { + for dir in $2; do + local pkg_name="$(basename "$dir")" + local scope_name="$(basename "$(dirname "$dir")")" + if [ "$pkg_name" = "*" ]; then continue; fi + echo "Processing subpackage @buape/$1/$pkg_name" + + if [ "$pkg_name" = "index" ]; then + local name="@buape/$1" + local title="Core" + rm -rf "$dir/../index.mdx" + elif [ "$scope_name" = "plugins" ]; then + local name="@buape/$1/$pkg_name" + local title="$(kebab_to_title_case "$pkg_name")" + elif [ "$scope_name" = "adapters" ]; then + local name="@buape/$1/adapters\/$pkg_name" + local title="$(kebab_to_title_case "$pkg_name")" + fi + + escaped_name="${name//@/\\@}" + escaped_name="${escaped_name//\//\\/}" + sed -i -e "s/title: \(.*\)/title: \"$escaped_name\"/" "$dir/index.mdx" + sed -i -e "s/## Index/ /" "$dir/index.mdx" + echo "{ \"title\": \"$title\" }" >"$dir/meta.json" + + add_meta_files "$dir" + done +} + +# Process a glob of packages +# $1: The glob of packages +process_package() { + for dir in $1; do + local pkg_name="$(basename "$dir")" + + echo "Processing package @buape/$pkg_name" + copy_api_docs "$dir" + + local api_dir="$CONTENT_DIR/$pkg_name/api" + # Process each of the core subpackages separately + if [ "$pkg_name" = "carbon" ]; then + process_subpackage "carbon" "$api_dir/index" + process_subpackage "carbon" "$api_dir/plugins/*" + # process_subpackage "carbon" "$api_dir/adapters/*" + else + add_meta_files "$api_dir" + fi + done +} + +process_package "$PACKAGES_DIR/*" diff --git a/website/modes.ts b/website/modes.ts index 2a82be22..b30c3eb4 100644 --- a/website/modes.ts +++ b/website/modes.ts @@ -1,10 +1,4 @@ -import { - Brackets, - Computer, - Link, - type LucideIcon, - Package -} from "lucide-react" +import { Computer, Link, type LucideIcon, Package } from "lucide-react" export interface Mode { param: string @@ -20,12 +14,6 @@ export const modes: Mode[] = [ description: "@buape/carbon", icon: Package }, - { - param: "linked-roles", - name: "Linked Roles", - description: "@buape/carbon-linked-roles", - icon: Brackets - }, { param: "nodejs", name: "NodeJS",