diff --git a/packages/create-commandkit/src/functions/installDeps.ts b/packages/create-commandkit/src/functions/installDeps.ts index 0d57c8d..0677f4c 100644 --- a/packages/create-commandkit/src/functions/installDeps.ts +++ b/packages/create-commandkit/src/functions/installDeps.ts @@ -9,14 +9,13 @@ interface InstallDepsProps { stdio: IOType; } -export function installDeps({ - manager, - dir, - lang, - stdio = 'pipe', -}: InstallDepsProps) { - execSync(`${manager} add ${dependencies[lang].join(' ')}`, { - cwd: dir, - stdio, - }); +export function installDeps({ manager, dir, lang, stdio = 'pipe' }: InstallDepsProps) { + const depsCommand = `${manager} add ${dependencies[lang].dependencies.join(' ')}`; + const devDepsCommand = `${manager} add ${dependencies.ts.devDependencies.join(' ')}`; + + execSync(depsCommand, { cwd: dir, stdio }); + + if (lang == 'ts') { + execSync(devDepsCommand, { cwd: dir, stdio }); + } } diff --git a/packages/create-commandkit/src/index.ts b/packages/create-commandkit/src/index.ts index 326dc9c..f7118da 100755 --- a/packages/create-commandkit/src/index.ts +++ b/packages/create-commandkit/src/index.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node console.clear(); -import type { ModuleType, PackageManager } from './types'; +import type { Language, ModuleType, PackageManager } from './types'; import { intro, text, select, password, confirm, outro } from '@clack/prompts'; import { commandkit, hints, outroMsg } from './utils'; @@ -46,6 +46,14 @@ const manager = (await select({ ], })) as PackageManager; +const lang = (await select({ + message: 'Select the language to use:', + options: [ + { label: 'JavaScript', value: 'js' }, + { label: 'TypeScript', value: 'ts' }, + ], +})) as Language; + const type = (await select({ message: 'Select a module type:', options: [ @@ -75,7 +83,7 @@ const installNow = await confirm({ outro(colors.cyan('Setup complete.')); await setup({ manager, dir, token, type }); -await copyTemplates({ type, dir, lang: 'js' }); +await copyTemplates({ type, dir, lang }); if (installNow) { await installDeps({ manager, dir, lang: 'js', stdio: 'inherit' }); diff --git a/packages/create-commandkit/src/types/index.ts b/packages/create-commandkit/src/types/index.ts index ddfe518..1763bcf 100644 --- a/packages/create-commandkit/src/types/index.ts +++ b/packages/create-commandkit/src/types/index.ts @@ -1,3 +1,3 @@ -export type Language = 'js'; +export type Language = 'js' | 'ts'; export type PackageManager = 'npm' | 'pnpm' | 'yarn'; export type ModuleType = 'esm' | 'cjs'; diff --git a/packages/create-commandkit/src/utils.ts b/packages/create-commandkit/src/utils.ts index d30904b..8cec6d4 100644 --- a/packages/create-commandkit/src/utils.ts +++ b/packages/create-commandkit/src/utils.ts @@ -7,9 +7,13 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); export const templates = { js: { - esm: `${__dirname}/../templates/JavaScript/esm`, - cjs: `${__dirname}/../templates/JavaScript/cjs`, + esm: path.join(__dirname, '..', 'templates', 'JavaScript', 'esm'), + cjs: path.join(__dirname, '..', 'templates', 'JavaScript', 'cjs'), }, + ts: { + esm: path.join(__dirname, '..', 'templates', 'TypeScript', 'esm'), + cjs: path.join(__dirname, '..', 'templates', 'TypeScript', 'cjs'), + }, }; export const textColors = { @@ -22,16 +26,24 @@ export const textColors = { ts: ['#2480c5', '#2480c5'], }; +const baseDependencies = ['commandkit', 'discord.js', 'dotenv']; + export const dependencies = { - js: ['commandkit', 'discord.js', 'dotenv'], + js: { + dependencies: baseDependencies, + }, + ts: { + dependencies: baseDependencies, + devDependencies: ['@types/node', 'typescript'], + }, }; export const commands = { - init: { - npm: 'npm init -y', - yarn: 'yarn init -y; yarn config set nodeLinker node-modules', - pnpm: 'pnpm init', - }, + init: { + npm: 'npm init -y', + yarn: 'yarn init -y; yarn config set nodeLinker node-modules; yarn set version stable', + pnpm: 'pnpm init', + }, }; export const hints = { diff --git a/packages/create-commandkit/templates/TypeScript/cjs/.gitignore b/packages/create-commandkit/templates/TypeScript/cjs/.gitignore new file mode 100644 index 0000000..9a7be06 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/cjs/.gitignore @@ -0,0 +1,33 @@ +# dependencies +node_modules + +# build output +build +out +dist + +# commandkit +.commandkit + +# env +**/*.env* +!**/*.env.example* + +# logging +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# yarn v2+ +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# other +**/*.DS_Store \ No newline at end of file diff --git a/packages/create-commandkit/templates/TypeScript/cjs/README.md b/packages/create-commandkit/templates/TypeScript/cjs/README.md new file mode 100644 index 0000000..0179f53 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/cjs/README.md @@ -0,0 +1,10 @@ +# Welcome to CommandKit + +> This project was generated by [create-commandkit](https://npmjs.com/package/create-commandkit). + +Thanks for choosing CommandKit to build your Discord bot! + +## Useful links + +- [Documentation](https://commandkit.js.org) +- [Discord](https://ctrl.lol/discord) diff --git a/packages/create-commandkit/templates/TypeScript/cjs/commandkit.cjs b/packages/create-commandkit/templates/TypeScript/cjs/commandkit.cjs new file mode 100644 index 0000000..78f4acf --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/cjs/commandkit.cjs @@ -0,0 +1,6 @@ +const { defineConfig } = require('commandkit'); + +module.exports = defineConfig({ + src: 'src', + main: 'index.js', +}); diff --git a/packages/create-commandkit/templates/TypeScript/cjs/src/commands/General/ping.ts b/packages/create-commandkit/templates/TypeScript/cjs/src/commands/General/ping.ts new file mode 100644 index 0000000..e55c322 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/cjs/src/commands/General/ping.ts @@ -0,0 +1,14 @@ +import type { CommandData, SlashCommandProps, CommandOptions } from 'commandkit'; + +export const data: CommandData = { + name: 'ping', + description: 'Replies with Pong', +}; + +export const run = ({ interaction }: SlashCommandProps) => { + interaction.reply('Pong!'); +}; + +export const options: CommandOptions = { + // https://commandkit.js.org/typedef/CommandOptions +}; diff --git a/packages/create-commandkit/templates/TypeScript/cjs/src/events/ready/ready.ts b/packages/create-commandkit/templates/TypeScript/cjs/src/events/ready/ready.ts new file mode 100644 index 0000000..ba96eb5 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/cjs/src/events/ready/ready.ts @@ -0,0 +1,5 @@ +import type { Client } from 'discord.js'; + +export default (client: Client) => { + console.log(`${client.user.tag} is online!`); +}; diff --git a/packages/create-commandkit/templates/TypeScript/cjs/src/index.ts b/packages/create-commandkit/templates/TypeScript/cjs/src/index.ts new file mode 100644 index 0000000..9974bf5 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/cjs/src/index.ts @@ -0,0 +1,22 @@ +import 'dotenv/config'; + +import { Client, IntentsBitField } from 'discord.js'; +import { CommandKit } from 'commandkit'; +import { join } from 'node:path'; + +const client = new Client({ + intents: [ + IntentsBitField.Flags.Guilds, + IntentsBitField.Flags.GuildMembers, + IntentsBitField.Flags.GuildMessages, + IntentsBitField.Flags.MessageContent, + ], +}); + +new CommandKit({ + client, + eventsPath: join(__dirname, 'events'), + commandsPath: join(__dirname, 'commands'), +}); + +client.login(process.env.TOKEN); diff --git a/packages/create-commandkit/templates/TypeScript/cjs/tsconfig.json b/packages/create-commandkit/templates/TypeScript/cjs/tsconfig.json new file mode 100644 index 0000000..2e6e38d --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/cjs/tsconfig.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "lib": ["ES2022"], + "target": "ES2022", + "moduleResolution": "Bundler", + "module": "ES2022", + "esModuleInterop": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "noUncheckedIndexedAccess": true, + "removeComments": true, + "allowJs": true, + "strict": true, + "noEmit": true, + "declaration": false + }, + "include": ["src"], + "exclude": ["dist", "node_modules", ".commandkit"] +} diff --git a/packages/create-commandkit/templates/TypeScript/esm/.gitignore b/packages/create-commandkit/templates/TypeScript/esm/.gitignore new file mode 100644 index 0000000..9a7be06 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/esm/.gitignore @@ -0,0 +1,33 @@ +# dependencies +node_modules + +# build output +build +out +dist + +# commandkit +.commandkit + +# env +**/*.env* +!**/*.env.example* + +# logging +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# yarn v2+ +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# other +**/*.DS_Store \ No newline at end of file diff --git a/packages/create-commandkit/templates/TypeScript/esm/README.md b/packages/create-commandkit/templates/TypeScript/esm/README.md new file mode 100644 index 0000000..0179f53 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/esm/README.md @@ -0,0 +1,10 @@ +# Welcome to CommandKit + +> This project was generated by [create-commandkit](https://npmjs.com/package/create-commandkit). + +Thanks for choosing CommandKit to build your Discord bot! + +## Useful links + +- [Documentation](https://commandkit.js.org) +- [Discord](https://ctrl.lol/discord) diff --git a/packages/create-commandkit/templates/TypeScript/esm/commandkit.mjs b/packages/create-commandkit/templates/TypeScript/esm/commandkit.mjs new file mode 100644 index 0000000..937ee5f --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/esm/commandkit.mjs @@ -0,0 +1,6 @@ +import { defineConfig } from 'commandkit'; + +export default defineConfig({ + src: 'src', + main: 'index.js', +}); diff --git a/packages/create-commandkit/templates/TypeScript/esm/src/commands/General/ping.ts b/packages/create-commandkit/templates/TypeScript/esm/src/commands/General/ping.ts new file mode 100644 index 0000000..e55c322 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/esm/src/commands/General/ping.ts @@ -0,0 +1,14 @@ +import type { CommandData, SlashCommandProps, CommandOptions } from 'commandkit'; + +export const data: CommandData = { + name: 'ping', + description: 'Replies with Pong', +}; + +export const run = ({ interaction }: SlashCommandProps) => { + interaction.reply('Pong!'); +}; + +export const options: CommandOptions = { + // https://commandkit.js.org/typedef/CommandOptions +}; diff --git a/packages/create-commandkit/templates/TypeScript/esm/src/events/ready/ready.ts b/packages/create-commandkit/templates/TypeScript/esm/src/events/ready/ready.ts new file mode 100644 index 0000000..ba96eb5 --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/esm/src/events/ready/ready.ts @@ -0,0 +1,5 @@ +import type { Client } from 'discord.js'; + +export default (client: Client) => { + console.log(`${client.user.tag} is online!`); +}; diff --git a/packages/create-commandkit/templates/TypeScript/esm/src/index.ts b/packages/create-commandkit/templates/TypeScript/esm/src/index.ts new file mode 100644 index 0000000..ce07d7e --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/esm/src/index.ts @@ -0,0 +1,26 @@ +import 'dotenv/config'; + +import { Client, IntentsBitField } from 'discord.js'; +import { CommandKit } from 'commandkit'; + +import { join, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +const client = new Client({ + intents: [ + IntentsBitField.Flags.Guilds, + IntentsBitField.Flags.GuildMembers, + IntentsBitField.Flags.GuildMessages, + IntentsBitField.Flags.MessageContent, + ], +}); + +new CommandKit({ + client, + eventsPath: join(__dirname, 'events'), + commandsPath: join(__dirname, 'commands'), +}); + +client.login(process.env.TOKEN); diff --git a/packages/create-commandkit/templates/TypeScript/esm/tsconfig.json b/packages/create-commandkit/templates/TypeScript/esm/tsconfig.json new file mode 100644 index 0000000..2e6e38d --- /dev/null +++ b/packages/create-commandkit/templates/TypeScript/esm/tsconfig.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "lib": ["ES2022"], + "target": "ES2022", + "moduleResolution": "Bundler", + "module": "ES2022", + "esModuleInterop": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "noUncheckedIndexedAccess": true, + "removeComments": true, + "allowJs": true, + "strict": true, + "noEmit": true, + "declaration": false + }, + "include": ["src"], + "exclude": ["dist", "node_modules", ".commandkit"] +}