diff --git a/package.json b/package.json
index c4e62c270..5cf9bf442 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro",
- "postinstall": "bun run setup.mjs",
+ "postinstall": "bun run setup.ts",
"lunaria:build": "lunaria build",
"lunaria:preview": "lunaria preview"
},
diff --git a/setup.mjs b/setup.mjs
deleted file mode 100644
index 0fe9360e8..000000000
--- a/setup.mjs
+++ /dev/null
@@ -1,37 +0,0 @@
-import { $ } from "bun";
-import { GITHUB_URL } from '~/utils/consts.ts';
-import { existsSync } from 'node:fs';
-import { copyFile } from "node:fs/promises";
-
-const gits = [
- {
- name: 'sern-handler-v3'
- },
- {
- name: 'sern-handler-v4',
- branch: 'feat/v4',
- },
-];
-
-for (const git of gits) {
- await $`rm -rf ${git.name}`;
- await $`git clone -b ${git.branch || 'main'} ${GITHUB_URL}/handler ${git.name}`;
- await $`cd ${git.name} && bun install`;
-}
-
-const tools = ['poster', 'ioc', 'builder', 'localizer', 'publisher'];
-// await $`bunx --yes degit --force sern-handler/tools/packages tools/`;
-
-await Promise.all(tools.map((tool) => {
- const docpage = `./tools/${tool}/index.mdx`;
- const metadata = `./tools/${tool}/metadata.json`;
- if (existsSync(docpage) && existsSync(metadata)) {
- console.log(`cp ${docpage} ./src/content/docs/v4/tools/${tool}.mdx`);
- return copyFile(docpage, `./src/content/docs/v4/tools/${tool}.mdx`);
- }
-
- console.warn(`${docpage} or ${metadata} not found for ${tool}`);
-}));
-
-
-
diff --git a/setup.ts b/setup.ts
new file mode 100644
index 000000000..ff63e2312
--- /dev/null
+++ b/setup.ts
@@ -0,0 +1,56 @@
+import { $ } from "bun";
+import { GITHUB_URL } from "~/utils/consts.ts";
+import { existsSync } from "node:fs";
+import { copyFile } from "node:fs/promises";
+
+interface GitItem {
+ name: string;
+ repo: string;
+ branch?: string;
+ install?: boolean;
+ folder?: string;
+}
+
+const gits: GitItem[] = [
+ {
+ name: "sern-handler-v3",
+ repo: "handler",
+ },
+ {
+ name: "sern-handler-v4",
+ repo: "handler",
+ branch: "feat/v4",
+ },
+ {
+ name: "tools",
+ repo: "tools",
+ folder: "packages",
+ install: false,
+ },
+];
+
+for (const git of gits) {
+ await $`rm -rf ${git.name}`;
+ await $`git clone -b ${git.branch ?? "main"} ${GITHUB_URL}/${git.repo} ${git.name}`;
+
+ if (git.install ?? true) {
+ await $`cd ${git.name} && bun install`;
+ }
+
+ if (git.folder) {
+ await $`mv ${git.name}/${git.folder}/* ${git.name} && rm -rf ${git.name}/${git.folder}`;
+ }
+}
+
+const tools = (await $`ls -d tools/* | grep -v .github`.text())
+ .split("\n")
+ .filter(
+ (t) => existsSync(`${t}/index.mdx`) && existsSync(`${t}/metadata.json`),
+ );
+
+for (const tool of tools) {
+ await copyFile(
+ `${tool}/index.mdx`,
+ `src/content/docs/v4/tools/${tool.split("/")[1]}.mdx`,
+ );
+}
diff --git a/src/content/docs/v4/tools/localizer.mdx b/src/content/docs/v4/tools/localizer.mdx
index 2b338bc07..0d33a731b 100644
--- a/src/content/docs/v4/tools/localizer.mdx
+++ b/src/content/docs/v4/tools/localizer.mdx
@@ -2,12 +2,10 @@
title: Localizer
description: Translate your bot for the world
sidebar:
- order: 1
+ order: 2
---
-# @sern/localizer
-
A localization module for managing translations and providing localized content in your application.
## Installation
@@ -16,25 +14,47 @@ A localization module for managing translations and providing localized content
npm i @sern/localizer
```
-## Usage
-
-**Initializing the Localizer**
-```ts
-import { makeDependencies } from '@sern/handler';
-import { Localization } from '@sern/localizer';
-
-await makeDependencies(({ add }) => {
- add('localizer', Localization());
-});
-```
-This localizer is **FILE BASED**.
-Create the directory `assets/locals`. Each json file in here must be named after the `locale`
import { Tabs, TabItem } from "@astrojs/starlight/components";
+
+## Usage
+
+**Initializing the Localizer**
+
+
+
+ ```ts {2} {6}
+ import { makeDependencies } from '@sern/handler';
+ import { Localization } from '@sern/localizer';
+
+ await makeDependencies(({ add }) => {
+ // add other deps
+ add('localizer', Localization());
+ });
+ ```
+
+
+ ```ts {5}
+ import type { Logging, CoreDependencies } from '@sern/handler'
+ import type { Localizer } from '@sern/localizer'
+ declare global {
+ interface Dependencies extends CoreDependencies {
+ localizer: Localizer;
+ }
+ }
+ export {}
+ ```
+
+
+
+This localizer is **FILE BASED**.
+Create the directory `assets/locals`. Each json file in here must be named after the `locale`
+
+
- ```json title=~/assets/locals/es.json
+ ```json title=~/assets/locals/es-ES.json
{
"salute": {
"hello": "hola"
@@ -46,7 +66,7 @@ import { Tabs, TabItem } from "@astrojs/starlight/components";
```json title=~/assets/locals/en-US.json
{
"salute": {
- "hello": "hola"
+ "hello": "hello"
}
}
```
@@ -62,7 +82,7 @@ execute : (ctx, { deps }) => {
//the localizer object from makeDependencies
deps.localizer
// Returns the Spanish translation for 'salute.hello'
- deps.localizer.translate("salute.hello", "es");
+ deps.localizer.translate("salute.hello", "es-ES");
}
```
@@ -71,5 +91,5 @@ execute : (ctx, { deps }) => {
import { local } from '@sern/localizer';
// Returns the Spanish translation for 'salute.hello'
-const greeting = local('salute.hello', 'es');
+const greeting = local('salute.hello', 'es-ES');
```
diff --git a/src/content/docs/v4/tools/publisher.mdx b/src/content/docs/v4/tools/publisher.mdx
new file mode 100644
index 000000000..d1cd15b29
--- /dev/null
+++ b/src/content/docs/v4/tools/publisher.mdx
@@ -0,0 +1,106 @@
+---
+title: Publisher
+description: Publish application commands as a Service
+sidebar:
+ order: 1
+---
+
+## Implicits
+- Requires process.env to be populated
+- A common provider of this is `dotenv`
+```txt title=".env"
+DISCORD_TOKEN=
+NODE_ENV=
+```
+- Calls the discord API with the [PUT route](https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands). Wherever your commands directory is located, publish will override the existing application commands at Discord.
+
+## Usage
+
+**Initializing the Publisher**
+```ts
+import { makeDependencies } from '@sern/handler';
+import { Publisher } from '@sern/publisher';
+
+await makeDependencies(({ add }) => {
+ add('publisher', new Publisher());
+});
+```
+
+## Features
+- Automatically syncs api with your command base
+- generates JSON file of output (**.sern/command-data-remote.json**)
+- supports a configuration that is the same as the original publish plugin.
+
+
+Each command file can have an extra plugin `publishConfig` that follows `ValidPublishOptions`:
+## Config
+```ts
+
+type ValidMemberPermissions =
+ | typeof PermissionFlagBits //discord.js enum
+ | typeof PermissionFlagBits[] //array of discord.js enum
+ | string //must be a stringified number
+ | bigint
+
+interface PublishConfig {
+ guildIds?: string[];
+ defaultMemberPermissions?: ValidMemberPermissions;
+ integrationTypes?: Array<'Guild'|'User'>
+ contexts: number[]
+}
+type ValidPublishOptions =
+ | PublishConfig
+ | (absPath: string, module: CommandModule) => PublishConfig
+```
+:::tip
+These types are exported under @sern/publisher
+:::
+
+### Example: command published with integrationTypes
+
+:::tip
+Make sure you modify the install method in the Discord dev portal
+:::
+
+```ts title=src/commands/ping.ts
+import { commandModule, CommandType } from '@sern/handler'
+import { publishConfig } from '@sern/publisher'
+
+export default commandModule( {
+ type: CommandType.Slash,
+ plugins: [
+ publishConfig({
+ integrationTypes: ['User'],
+ contexts: [1,2]
+ })
+ ],
+ description: `hello worl`,
+ execute: (ctx) => {
+ ctx.reply('pong')
+ }
+})
+
+```
+
+
+### Example: command published in guild
+
+```ts title=src/commands/ping.ts
+import { commandModule, CommandType } from '@sern/handler'
+import { publishConfig } from '@sern/publisher'
+
+export default commandModule( {
+ type: CommandType.Slash,
+ plugins: [
+ publishConfig({
+ guildIds: ["889026545715400705"]
+ })
+ ],
+ description: `hello worl`,
+ execute: (ctx) => {
+ ctx.reply('pong')
+ }
+})
+
+```
+