-
-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add create-commandkit #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
4f88478
feat: add create-commandkit
windowsnashville 4d248a2
chore: update create-commandkit package.json
windowsnashville 2e8766a
build: create-commandkit tsconfig
windowsnashville de3b86b
chore: install deps
windowsnashville 862852d
fix: create-commandkit tsconfig
windowsnashville 1a29c3f
chore: update lockfile
windowsnashville b9ea985
refactor: remove create-commandkit config files
windowsnashville f63a983
feat: migrate create-commandkit to typescript
windowsnashville d4a43b2
chore: create-commandkit package.json
windowsnashville c292f5d
refactor: commandkit repo data
windowsnashville 68a81bb
refactor: create-commandkit package.json
windowsnashville 0250ab3
docs: create-commandkit readme
windowsnashville 5fb1257
docs: add create-commandkit to guide
windowsnashville 04df114
chore: create-commandkit keywords
windowsnashville 2b7361b
feat: use commandkit CLI
windowsnashville 025058f
chore: remove nodemon from deps
windowsnashville 7ca5a30
feat: add config file
windowsnashville 744b9e8
build: generate lockfile
windowsnashville bcbd108
feat: add .gitignore for templates
windowsnashville 02d7407
refactor: init commands
windowsnashville 0a697e2
chore: add .commandkit to gitignore
windowsnashville 48640df
refactor: remove getDirname function
windowsnashville d80441c
chore: remove package.json main
windowsnashville 799edf9
refactor: use deps array instead of commands
windowsnashville 7224c10
refactor: consistent imports
windowsnashville 5ec082b
refactor: use path.join for paths
windowsnashville 600777a
refactor(docs): create-commandkit command
windowsnashville 19b4765
feat: installNow option
windowsnashville 0739484
refactor: wrap env token in double quotes
windowsnashville 22494be
style: 2 space formatting for package.json
windowsnashville 6acf835
chore: dependencies
windowsnashville cbfdf00
docs: upgrade deps
windowsnashville 9604ca7
chore: use -y flag with yarn
windowsnashville File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # create-commandkit | ||
|
|
||
| Besides installing CommandKit to your existing project, you can also start a new one with `create-commandkit` — a command-line utility used for creating new discord.js bots with CommandKit. | ||
|
|
||
| ## Usage | ||
|
|
||
| If you want to create a new CommandKit application, simply run the following command: | ||
|
|
||
| ```sh copy | ||
| npm create commandkit@latest | ||
| ``` | ||
|
|
||
| This will start the CLI in the current directory. | ||
|
|
||
| ## Prompts | ||
|
|
||
| When running create-commandkit, you should be asked the following questions: | ||
|
|
||
| - **Project Directory:** Defines where your project will be located. It defaults to the current working directory. | ||
|
|
||
| - **Package Manager:** Lets you choose which package manager to use — npm, pnpm, or Yarn. | ||
|
|
||
| - **Module Type:** Allows you to pick between CommonJS (using require and module.exports), and ESM (using import and export). | ||
|
|
||
| - **Bot Token:** Asks you for your bot token, and writes it into the `.env` file where it will be stored. | ||
|
|
||
| After these questions are answered, your project solution should appear in the selected folder. |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <div align="center"> | ||
| <img src="https://raw.githubusercontent.com/underctrl-io/commandkit/master/apps/docs/public/ckit_logo.svg" width="60%" /> | ||
| <br /> | ||
| <a href="https://ctrl.lol/discord"><img src="https://img.shields.io/discord/1055188344188973066?color=5865F2&logo=discord&logoColor=white" alt="support server" /></a> | ||
| <a href="https://www.npmjs.com/package/create-commandkit"><img src="https://img.shields.io/npm/v/create-commandkit?maxAge=3600" alt="npm version" /></a> | ||
| <a href="https://www.npmjs.com/package/create-commandkit"><img src="https://img.shields.io/npm/dt/create-commandkit?maxAge=3600" alt="npm downloads" /></a> | ||
| </div> | ||
|
|
||
| # create-commandkit | ||
|
|
||
| create-commandkit is a CLI utility to quickly instantiate a Discord bot with CommandKit. | ||
|
|
||
| ## Features | ||
|
|
||
| - Interactive, beautiful command-line interface 🖥️ | ||
| - Supports CommonJS and ES Modules 📦 | ||
|
|
||
| ## Documentation | ||
|
|
||
| You can find the full documentation [here](https://commandkit.js.org). | ||
|
|
||
| ## Usage | ||
|
|
||
| Run the following command in your terminal: | ||
|
|
||
| ```sh | ||
| npx create-commandkit@latest | ||
| ``` | ||
|
|
||
| ## Support and Suggestions | ||
|
|
||
| Submit any queries or suggestions in our [Discord community](https://ctrl.lol/discord). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| { | ||
| "name": "create-commandkit", | ||
| "description": "Effortlessly create a CommandKit project", | ||
| "version": "2.0.0", | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.js", | ||
| "bin": "./dist/index.js", | ||
| "type": "module", | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "commandkit", | ||
| "create-commandkit", | ||
| "discord.js", | ||
| "discord", | ||
| "node", | ||
| "client", | ||
| "cli", | ||
| "commands" | ||
| ], | ||
| "files": [ | ||
| "dist", | ||
| "templates" | ||
| ], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/underctrl-io/commandkit", | ||
| "directory": "packages/create-commandkit" | ||
| }, | ||
| "homepage": "https://commandkit.js.org", | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "lint": "tsc" | ||
| }, | ||
| "dependencies": { | ||
| "@clack/prompts": "^0.7.0", | ||
| "colors": "^1.4.0", | ||
| "fs-extra": "^11.1.1", | ||
| "gradient-string": "^2.0.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^20.11.6", | ||
| "@types/gradient-string": "^1.1.5", | ||
| "@types/fs-extra": "^11.0.4", | ||
| "typescript": "^5.3.3", | ||
| "tsconfig": "workspace:*", | ||
| "tsup": "^8.0.1" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { Language, ModuleType } from '../types'; | ||
| import { templates } from '../utils'; | ||
| import fs from 'fs-extra'; | ||
|
|
||
| interface CopyTemplatesProps { | ||
| type: ModuleType; | ||
| lang: Language; | ||
| dir: string; | ||
| } | ||
|
|
||
| export async function copyTemplates({ type, dir, lang }: CopyTemplatesProps) { | ||
| await fs.copy(templates[lang][type], dir); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { Language, PackageManager } from '../types'; | ||
| import { type IOType, execSync } from 'node:child_process'; | ||
| import { dependencies } from '../utils'; | ||
|
|
||
| interface InstallDepsProps { | ||
| manager: PackageManager; | ||
| dir: string; | ||
| lang: Language; | ||
| stdio: IOType; | ||
| } | ||
|
|
||
| export function installDeps({ manager, dir, lang, stdio = 'pipe' }: InstallDepsProps) { | ||
| execSync(`${manager} add ${dependencies[lang].join(' ')}`, { cwd: dir, stdio }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { ModuleType, PackageManager } from '../types'; | ||
| import { type IOType, execSync } from 'child_process'; | ||
| import { commands } from '../utils'; | ||
|
|
||
| import fs from 'fs-extra'; | ||
| import path from 'node:path'; | ||
|
|
||
| interface SetupProps { | ||
| manager: PackageManager; | ||
| type: ModuleType; | ||
| token: string; | ||
| dir: string; | ||
| stdio?: IOType; | ||
| } | ||
|
|
||
| export async function setup({ manager, type, token, dir, stdio = 'pipe' }: SetupProps) { | ||
| await fs.emptyDir(dir); | ||
| execSync(commands.init[manager], { cwd: dir, stdio }); | ||
|
|
||
| const packageJsonPath = path.join(dir, 'package.json'); | ||
| const packageJson = await fs.readJSON(packageJsonPath); | ||
|
|
||
| delete packageJson.main; | ||
| packageJson.name = packageJson.name.toLowerCase(); | ||
| packageJson.type = type == 'esm' ? 'module' : 'commonjs'; | ||
| packageJson.version = '0.0.0'; | ||
|
|
||
| packageJson.scripts = { | ||
| dev: 'commandkit dev', | ||
| build: 'commandkit build', | ||
| start: 'commandkit start', | ||
| }; | ||
|
|
||
| await fs.writeJSON(packageJsonPath, packageJson, { spaces: 2 }); | ||
| await fs.writeFile(`${dir}/.env`, `TOKEN="${token}"`); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env node | ||
| console.clear(); | ||
|
|
||
| import type { ModuleType, PackageManager } from './types'; | ||
|
|
||
| import { intro, text, select, password, confirm, outro } from '@clack/prompts'; | ||
| import { commandkit, hints, outroMsg } from './utils'; | ||
| import { setup } from './functions/setup'; | ||
| import { installDeps } from './functions/installDeps'; | ||
| import { copyTemplates } from './functions/copyTemplates'; | ||
|
|
||
| import path from 'node:path'; | ||
| import colors from 'colors'; | ||
| import fs from 'fs-extra'; | ||
|
|
||
| await intro(`Welcome to ${commandkit}!`); | ||
|
|
||
| const dir = path.resolve( | ||
| process.cwd(), | ||
| (await text({ | ||
| message: 'Enter a project directory:', | ||
| placeholder: 'Leave blank for current directory', | ||
| defaultValue: '.', | ||
| validate: (value) => { | ||
| value = path.resolve(process.cwd(), value); | ||
| let isEmpty; | ||
|
|
||
| try { | ||
| const contents = fs.readdirSync(value); | ||
| isEmpty = contents.length === 0; | ||
| } catch { | ||
| isEmpty = true; | ||
| } | ||
|
|
||
| return isEmpty ? undefined : 'Directory is not empty!'; | ||
| }, | ||
| })) as string, | ||
windowsnashville marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| const manager = (await select({ | ||
| message: 'Select a package manager:', | ||
| options: [ | ||
| { label: 'npm', value: 'npm' }, | ||
| { label: 'pnpm', value: 'pnpm' }, | ||
| { label: 'yarn', value: 'yarn' }, | ||
| ], | ||
| })) as PackageManager; | ||
windowsnashville marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const type = (await select({ | ||
| message: 'Select a module type:', | ||
| options: [ | ||
| { label: 'CommonJS', value: 'cjs', hint: `${hints.require} & ${hints.module}` }, | ||
| { label: 'ES Modules', value: 'esm', hint: `${hints.import} & ${hints.export}` }, | ||
| ], | ||
| })) as ModuleType; | ||
windowsnashville marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const token = (await password({ | ||
| message: 'Enter your bot token:', | ||
| mask: colors.gray('*'), | ||
| })) as string; | ||
|
|
||
| const installNow = await confirm({ | ||
| message: 'Install dependencies now?', | ||
| initialValue: true, | ||
| }); | ||
|
|
||
| outro(colors.cyan('Setup complete.')); | ||
|
|
||
| await setup({ manager, dir, token, type }); | ||
| await copyTemplates({ type, dir, lang: 'js' }); | ||
|
|
||
| if (installNow) { | ||
| await installDeps({ manager, dir, lang: 'js', stdio: 'inherit' }); | ||
| } | ||
|
|
||
| console.log(outroMsg); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export type Language = 'js'; | ||
| export type PackageManager = 'npm' | 'pnpm' | 'yarn'; | ||
| export type ModuleType = 'esm' | 'cjs'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import colors from 'colors'; | ||
| import gradient from 'gradient-string'; | ||
| import path from 'node:path'; | ||
| import url from 'node:url'; | ||
|
|
||
| const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); | ||
|
|
||
| export const templates = { | ||
| js: { | ||
| esm: `${__dirname}/../templates/JavaScript/esm`, | ||
| cjs: `${__dirname}/../templates/JavaScript/cjs`, | ||
| }, | ||
| }; | ||
|
|
||
| export const textColors = { | ||
| commandkit: ['#fdba74', '#e4a5a2', '#c288de', '#b27bf9'], | ||
| import: ['#c586c0', '#c586c0'], | ||
| export: ['#569cd6', '#569cd6'], | ||
| require: ['#dcdcaa', '#dcdcaa'], | ||
| module: ['#4ec9b0', '#4ec9b0'], | ||
| js: ['#f7e01c', '#f7e01c'], | ||
| ts: ['#2480c5', '#2480c5'], | ||
| }; | ||
|
|
||
| export const dependencies = { | ||
| js: ['commandkit', 'discord.js', 'dotenv'], | ||
| }; | ||
|
|
||
| export const commands = { | ||
| init: { | ||
| npm: 'npm init -y', | ||
| yarn: 'yarn init -y; yarn config set nodeLinker node-modules', | ||
| pnpm: 'pnpm init', | ||
| }, | ||
| }; | ||
|
|
||
| export const hints = { | ||
| import: gradient(textColors.import)('import'), | ||
| export: gradient(textColors.export)('export'), | ||
| require: gradient(textColors.require)('require'), | ||
| module: gradient(textColors.module)('exports'), | ||
| javascript: gradient(textColors.js)('JavaScript'), | ||
| typescript: gradient(textColors.ts)('TypeScript'), | ||
| }; | ||
|
|
||
| export const commandkit = gradient(textColors.commandkit)('CommandKit'); | ||
| export const outroMsg = ` | ||
| ${gradient(textColors.commandkit)('Thank you for choosing CommandKit!')} | ||
|
|
||
| • Documentation: ${colors.blue('https://commandkit.js.org')} | ||
| • Join us on Discord: ${colors.blue('https://ctrl.lol/discord')} | ||
| `; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.