From 37207f8eec4d7bccde9a2535f7bc441638af6814 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 8 Jan 2023 07:14:14 -0600 Subject: [PATCH] feat!: templates for sern v2 (#19) --- .github/workflows/linter.yml | 2 +- templates/javascript-esm/.gitignore | 2 +- templates/javascript-esm/package.json | 4 ++-- templates/javascript-esm/src/index.js | 23 ++++++++++++++++-- templates/javascript/.gitignore | 2 +- templates/javascript/package.json | 4 ++-- templates/javascript/src/index.js | 23 ++++++++++++++++-- templates/typescript/package.json | 6 ++--- templates/typescript/src/index.ts | 34 +++++++++++++++++++++++++-- 9 files changed, 84 insertions(+), 16 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 79cac1b5..55344d13 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -29,4 +29,4 @@ jobs: run: npm i - name: Run linters - run: npm run format \ No newline at end of file + run: npm run format diff --git a/templates/javascript-esm/.gitignore b/templates/javascript-esm/.gitignore index caa2994d..7af7f047 100644 --- a/templates/javascript-esm/.gitignore +++ b/templates/javascript-esm/.gitignore @@ -1,2 +1,2 @@ -/node_modules +/node_modules .env \ No newline at end of file diff --git a/templates/javascript-esm/package.json b/templates/javascript-esm/package.json index 439d2d0b..7121a7b0 100644 --- a/templates/javascript-esm/package.json +++ b/templates/javascript-esm/package.json @@ -13,8 +13,8 @@ ], "license": "UNLICENSED", "dependencies": { - "@sern/handler": "^1.0.0", - "discord.js": "^14.2.0" + "@sern/handler": "^2.0.0", + "discord.js": "^14.7.1" }, "devDependencies": { "@types/node": "^17.0.25" diff --git a/templates/javascript-esm/src/index.js b/templates/javascript-esm/src/index.js index e61e213c..d3c8514e 100644 --- a/templates/javascript-esm/src/index.js +++ b/templates/javascript-esm/src/index.js @@ -1,5 +1,5 @@ import { Client, GatewayIntentBits } from 'discord.js'; -import { Sern } from '@sern/handler'; +import { Sern, single, DefaultLogging } from '@sern/handler'; const client = new Client({ intents: [ @@ -9,12 +9,31 @@ const client = new Client({ GatewayIntentBits.MessageContent, // Make sure this is enabled for text commands! ], }); + +/** + * Where all of your dependencies are composed. + * '@sern/client' is usually your Discord Client. + * View documentation for pluggable dependencies + * Configure your dependency root to your liking. + * It follows the npm package iti https://itijs.org/. + * Use this function to access all of your dependencies. + * This is used for external event modules as well + */ +export const useContainer = Sern.makeDependencies({ + build: (root) => + root + .add({ '@sern/client': single(client) }) + .add({ '@sern/logger': single(new DefaultLogging()) }), +}); + //View docs for all options Sern.init({ - client, defaultPrefix: '!', // removing defaultPrefix will shut down text commands commands: 'src/commands', // events: 'src/events' (optional), + containerConfig: { + get: useContainer, + }, }); client.login(); diff --git a/templates/javascript/.gitignore b/templates/javascript/.gitignore index caa2994d..7af7f047 100644 --- a/templates/javascript/.gitignore +++ b/templates/javascript/.gitignore @@ -1,2 +1,2 @@ -/node_modules +/node_modules .env \ No newline at end of file diff --git a/templates/javascript/package.json b/templates/javascript/package.json index 81713b35..6d214824 100644 --- a/templates/javascript/package.json +++ b/templates/javascript/package.json @@ -13,8 +13,8 @@ ], "license": "UNLICENSED", "dependencies": { - "@sern/handler": "^1.0.0", - "discord.js": "^14.2.0" + "@sern/handler": "^2.0.0", + "discord.js": "^14.7.1" }, "devDependencies": { "@types/node": "^17.0.25" diff --git a/templates/javascript/src/index.js b/templates/javascript/src/index.js index c14636c5..8fad7584 100644 --- a/templates/javascript/src/index.js +++ b/templates/javascript/src/index.js @@ -1,5 +1,5 @@ const { Client, GatewayIntentBits } = require('discord.js'); -const { Sern } = require('@sern/handler'); +const { Sern, single, DefaultLogging } = require('@sern/handler'); const client = new Client({ intents: [ @@ -9,12 +9,31 @@ const client = new Client({ GatewayIntentBits.MessageContent, // Make sure this is enabled for text commands! ], }); + +/** + * Where all of your dependencies are composed. + * '@sern/client' is usually your Discord Client. + * View documentation for pluggable dependencies + * Configure your dependency root to your liking. + * It follows the npm package iti https://itijs.org/. + * Use this function to access all of your dependencies. + * This is used for external event modules as well + */ +export const useContainer = Sern.makeDependencies({ + build: (root) => + root + .add({ '@sern/client': single(client) }) + .add({ '@sern/logger': single(new DefaultLogging()) }), +}); + //View docs for all options Sern.init({ - client, defaultPrefix: '!', // removing defaultPrefix will shut down text commands commands: 'src/commands', // events: 'src/events' (optional), + containerConfig: { + get: useContainer, + }, }); client.login(); diff --git a/templates/typescript/package.json b/templates/typescript/package.json index da563145..02ee8976 100644 --- a/templates/typescript/package.json +++ b/templates/typescript/package.json @@ -15,11 +15,11 @@ ], "license": "UNLICENSED", "dependencies": { - "@sern/handler": "^1.0.0", - "discord.js": "^14.2.0" + "@sern/handler": "^2.0.0", + "discord.js": "^14.7.1" }, "devDependencies": { "@types/node": "^17.0.25", - "typescript": "^4.6.3" + "typescript": "^4.9" } } diff --git a/templates/typescript/src/index.ts b/templates/typescript/src/index.ts index fc2a2fe0..71ba32d9 100644 --- a/templates/typescript/src/index.ts +++ b/templates/typescript/src/index.ts @@ -1,5 +1,11 @@ import { Client, GatewayIntentBits } from 'discord.js'; -import { Sern } from '@sern/handler'; +import { + Dependencies, + Sern, + single, + Singleton, + DefaultLogging, +} from '@sern/handler'; const client = new Client({ intents: [ @@ -9,12 +15,36 @@ const client = new Client({ GatewayIntentBits.MessageContent, //Make sure this is enabled for text commands! ], }); + +//With typescript, you can customize / augment your typings. +interface MyDependencies extends Dependencies { + '@sern/client': Singleton; + '@sern/logger': Singleton; +} +/** + * Where all of your dependencies are composed. + * '@sern/client' is usually your Discord Client. + * View documentation for pluggable dependencies + * Configure your dependency root to your liking. + * It follows the npm package iti https://itijs.org/. + * Use this function to access all of your dependencies. + * This is used for external event modules as well + */ +export const useContainer = Sern.makeDependencies({ + build: (root) => + root + .add({ '@sern/client': single(client) }) + .add({ '@sern/logger': single(new DefaultLogging()) }), +}); + //View docs for all options Sern.init({ - client, defaultPrefix: '!', // removing defaultPrefix will shut down text commands commands: 'dist/commands', // events: 'dist/events' (optional), + containerConfig: { + get: useContainer, + }, }); client.login();