create-commandkit 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/underctrl-io/commandkit/master/apps/docs/public/ckit_logo.png" width="60%" />
3
+ <br />
4
+ <a href="https://ctrl.lol/discord"><img src="https://img.shields.io/discord/1055188344188973066?color=5865F2&logo=discord&logoColor=white" alt="support server" /></a>
5
+ <a href="https://www.npmjs.com/package/commandkit"><img src="https://img.shields.io/npm/v/commandkit?maxAge=3600&label=commandkit" alt="commandkit version" /></a>
6
+ <a href="https://www.npmjs.com/package/commandkit"><img src="https://img.shields.io/npm/v/create-commandkit?maxAge=3600&label=create-commandkit" alt="create-commandkit version" /></a>
7
+ <a href="https://www.npmjs.com/package/commandkit"><img src="https://img.shields.io/npm/dt/commandkit?maxAge=3600" alt="npm downloads" /></a>
8
+ </div>
9
+
10
+ # create-commandkit
11
+
12
+ A command-line interface (CLI) to quickly generate a discord.js bot using CommandKit.
13
+
14
+ ## Usage
15
+
16
+ Run one of the following commands:
17
+
18
+ ```sh
19
+ npm create commandkit
20
+ pnpm create commandkit
21
+ yarn create commandkit
22
+ ```
23
+
24
+ ## Setup Options
25
+
26
+ - Project directory
27
+ - Package manager (npm/pnpm/yarn)
28
+ - Module type (ESM/CommonJS)
29
+ - Bot token (written to .env)
30
+
31
+ ## Repositories
32
+
33
+ - [CommandKit](https://github.com/underctrl-io/commandkit)
34
+ - [create-commandkit](https://github.com/m1-dev/create-commandkit)
package/package.json CHANGED
@@ -1,12 +1,20 @@
1
1
  {
2
- "name": "create-commandkit",
3
- "version": "0.0.0",
4
- "description": "",
5
- "main": "index.js",
6
- "keywords": [],
7
- "author": "",
8
- "license": "ISC",
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- }
2
+ "name": "create-commandkit",
3
+ "description": "Start a new CommandKit project with ease.",
4
+ "version": "0.0.1",
5
+ "main": "src/index.js",
6
+ "bin": "src/index.js",
7
+ "type": "commonjs",
8
+ "license": "MIT",
9
+ "keywords": [
10
+ "commandkit",
11
+ "discord.js",
12
+ "cli"
13
+ ],
14
+ "dependencies": {
15
+ "@clack/prompts": "^0.7.0",
16
+ "gradient-string": "^2.0.2",
17
+ "fs-extra": "^11.1.1",
18
+ "colors": "^1.4.0"
19
+ }
12
20
  }
package/src/config.js ADDED
@@ -0,0 +1,45 @@
1
+ const gradient = require('gradient-string');
2
+
3
+
4
+ // import #c586c0
5
+ // export #569cd6
6
+
7
+ // require #dcdcaa
8
+ // module #4ec9b0
9
+
10
+ exports.templates = {
11
+ js: {
12
+ esm: `${__dirname}/templates/JavaScript/esm`,
13
+ cjs: `${__dirname}/templates/JavaScript/cjs`,
14
+ }
15
+ }
16
+
17
+ exports.colors = {
18
+ commandkit: ['#fdba74', '#e4a5a2', '#c288de', '#b27bf9'],
19
+ import: ['#c586c0', '#c586c0'],
20
+ export: ['#569cd6', '#569cd6'],
21
+ require: ['#dcdcaa', '#dcdcaa'],
22
+ module: ['#4ec9b0', '#4ec9b0'],
23
+ js: ['#f7e01c', '#f7e01c'],
24
+ ts: ['#2480c5', '#2480c5']
25
+ }
26
+
27
+ exports.commands = {
28
+ init: { npm: 'npm init -y', yarn: 'yarn init -y', pnpm: 'pnpm init' },
29
+ install: {
30
+ npm: 'npm install commandkit discord.js dotenv nodemon',
31
+ yarn: 'yarn add commandkit discord.js dotenv nodemon',
32
+ pnpm: 'pnpm add commandkit discord.js dotenv nodemon',
33
+ }
34
+ }
35
+
36
+ exports.hints = {
37
+ import: gradient(exports.colors.import)('import'),
38
+ export: gradient(exports.colors.export)('export'),
39
+ require: gradient(exports.colors.require)('require'),
40
+ module: gradient(exports.colors.module)('exports'),
41
+ javascript: gradient(exports.colors.js)('JavaScript'),
42
+ typescript: gradient(exports.colors.ts)('TypeScript')
43
+ }
44
+
45
+ exports.commandkit = gradient(exports.colors.commandkit)('CommandKit');
@@ -0,0 +1,8 @@
1
+ const { templates } = require('../config');
2
+ const { execSync: ex } = require('child_process');
3
+
4
+ const fs = require('fs-extra');
5
+
6
+ module.exports = async ({ type, dir, lang }) => {
7
+ await fs.copy(templates[lang][type], dir);
8
+ }
@@ -0,0 +1,6 @@
1
+ const { commands } = require('../config');
2
+ const { execSync: ex } = require('child_process');
3
+
4
+ module.exports = async ({ manager, dir, stdio = 'pipe' }) => {
5
+ ex(commands.install[manager], { cwd: dir, stdio });
6
+ }
@@ -0,0 +1,26 @@
1
+ const { execSync: ex } = require('child_process');
2
+ const { commands } = require('../config');
3
+
4
+ const fs = require('fs-extra');
5
+ const path = require('path');
6
+
7
+
8
+ module.exports = async ({ manager, dir, token, type, stdio = 'pipe' }) => {
9
+ await fs.emptyDir(dir);
10
+ ex(commands.init[manager], { cwd: dir, stdio });
11
+
12
+ const packageJsonPath = path.join(dir, 'package.json');
13
+ const packageJson = await fs.readJSON(packageJsonPath);
14
+
15
+ packageJson.name = packageJson.name.toLowerCase();
16
+ packageJson.type = type == 'esm' ? 'module' : 'commonjs';
17
+ packageJson.main = './src/index.js';
18
+ packageJson.version = '0.0.0';
19
+ packageJson.scripts = {
20
+ start: 'node ./src/index.js',
21
+ dev: 'nodemon --ext js,json,ts ./src/index.js'
22
+ };
23
+
24
+ await fs.writeJSON(packageJsonPath, packageJson, { spaces: 4 });
25
+ await fs.writeFile(`${dir}/.env`, `TOKEN = ${token}`);
26
+ }
package/src/index.js ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ console.clear();
3
+
4
+ const { gray } = require('colors');
5
+ const { commandkit, hints } = require('./config');
6
+
7
+ const setup = require('./functions/setup');
8
+ const installDeps = require('./functions/installDeps');
9
+ const copyTemplates = require('./functions/copyTemplates');
10
+
11
+ const prompts = require('@clack/prompts');
12
+ const path = require('path');
13
+
14
+ const gradient = require('gradient-string');
15
+
16
+ (async () => {
17
+ prompts.intro(`Welcome to ${commandkit}!`);
18
+
19
+ const { dir, manager, type, token } = {
20
+ dir: path.resolve(process.cwd(), await prompts.text({
21
+ message: 'Enter a project directory:',
22
+ placeholder: 'Leave blank for current directory',
23
+ defaultValue: '.',
24
+ })),
25
+
26
+ manager: await prompts.select({
27
+ message: 'Select a package manager:',
28
+ options: [{ value: 'npm' }, { value: 'pnpm' }, { value: 'yarn' }],
29
+ }),
30
+
31
+ type: await prompts.select({
32
+ message: 'Select a module type:',
33
+ options: [
34
+ { label: 'CommonJS', value: 'cjs', hint: `${hints.require} & ${hints.module}` },
35
+ { label: 'ES Modules', value: 'esm', hint: `${hints.import} & ${hints.export}` },
36
+ ]
37
+ }),
38
+
39
+ token: await prompts.password({
40
+ message: 'Enter your bot token:',
41
+ mask: gray('*')
42
+ })
43
+ }
44
+
45
+ const spinner = prompts.spinner();
46
+ spinner.start('Setting up project');
47
+
48
+ await setup({ manager, token, dir, type });
49
+ await installDeps({ manager, dir });
50
+ await copyTemplates({ type, dir, lang: 'js' });
51
+
52
+ spinner.stop('Setup done.');
53
+
54
+ prompts.outro(gradient.summer('Happy coding!'));
55
+ })();
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ /** @type {import('commandkit').CommandData} */
3
+ data: {
4
+ name: 'ping',
5
+ description: 'Replies with Pong'
6
+ },
7
+
8
+ /**
9
+ * @param {import('commandkit').SlashCommandProps} param0
10
+ */
11
+ run: ({ interaction }) => {
12
+ interaction.reply('Pong!');
13
+ },
14
+
15
+ /** @type {import('commandkit').CommandOptions} */
16
+ options: {
17
+ // https://commandkit.js.org/typedef/CommandOptions
18
+ }
19
+ }
@@ -0,0 +1,4 @@
1
+ /** * @param {import('discord.js').Client} client */
2
+ module.exports = (client) => {
3
+ console.log(`${client.user.tag} is online!`);
4
+ }
@@ -0,0 +1,21 @@
1
+ require('dotenv/config');
2
+
3
+ const { Client, IntentsBitField } = require('discord.js');
4
+ const { CommandKit } = require('commandkit');
5
+
6
+ const client = new Client({
7
+ intents: [
8
+ IntentsBitField.Flags.Guilds,
9
+ IntentsBitField.Flags.GuildMembers,
10
+ IntentsBitField.Flags.GuildMessages,
11
+ IntentsBitField.Flags.MessageContent
12
+ ]
13
+ });
14
+
15
+ new CommandKit({
16
+ client,
17
+ eventsPath: `${__dirname}/events`,
18
+ commandsPath: `${__dirname}/commands`
19
+ });
20
+
21
+ client.login(process.env.TOKEN);
@@ -0,0 +1,17 @@
1
+ /** @type {import('commandkit').CommandData} */
2
+ export const data = {
3
+ name: 'ping',
4
+ description: 'Replies with Pong'
5
+ }
6
+
7
+ /**
8
+ * @param {import('commandkit').SlashCommandProps} param0
9
+ */
10
+ export const run = ({ interaction }) => {
11
+ interaction.reply('Pong!');
12
+ }
13
+
14
+ /** @type {import('commandkit').CommandOptions} */
15
+ export const options = {
16
+ // https://commandkit.js.org/typedef/CommandOptions
17
+ }
@@ -0,0 +1,4 @@
1
+ /** * @param {import('discord.js').Client} client */
2
+ export default (client) => {
3
+ console.log(`${client.user.tag} is online!`);
4
+ }
@@ -0,0 +1,26 @@
1
+ import 'dotenv/config';
2
+
3
+ import { Client, IntentsBitField } from 'discord.js';
4
+ import { CommandKit } from 'commandkit';
5
+
6
+ import { dirname as dn } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ const dirname = dn(fileURLToPath(import.meta.url));
10
+
11
+ const client = new Client({
12
+ intents: [
13
+ IntentsBitField.Flags.Guilds,
14
+ IntentsBitField.Flags.GuildMembers,
15
+ IntentsBitField.Flags.GuildMessages,
16
+ IntentsBitField.Flags.MessageContent
17
+ ]
18
+ });
19
+
20
+ new CommandKit({
21
+ client,
22
+ eventsPath: `${dirname}/events`,
23
+ commandsPath: `${dirname}/commands`
24
+ });
25
+
26
+ client.login(process.env.TOKEN);