mirror of
https://github.com/sern-handler/create-bot
synced 2026-06-06 01:16:53 +00:00
feat: add templates
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "create",
|
||||
"name": "@sern/create-bot",
|
||||
"version": "1.0.0",
|
||||
"main": "./dist/index.js",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"@sern/create": "index.js"
|
||||
"@sern/create-bot": "index.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/minimist": "^1.2.2",
|
||||
|
||||
51
src/index.ts
51
src/index.ts
@@ -1,8 +1,9 @@
|
||||
import { greenBright, redBright, underline } from 'colorette';
|
||||
import { greenBright, red, redBright } from 'colorette';
|
||||
import prompt, { PromptObject } from 'prompts';
|
||||
import minimist from 'minimist'
|
||||
import { writeFile } from 'fs/promises'
|
||||
import { join } from 'path'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
const argv = minimist<{
|
||||
template?: string
|
||||
}>(process.argv.slice(2));
|
||||
@@ -43,8 +44,25 @@ async function runInteractive() {
|
||||
const result: prompt.Answers<'template'|'name'> = await prompt([
|
||||
template,
|
||||
name,
|
||||
]);
|
||||
],
|
||||
{
|
||||
onCancel: () => {
|
||||
throw new Error(red('✖') + ' Operation cancelled')
|
||||
},
|
||||
},
|
||||
);
|
||||
const root = path.join(cwd, result.name);
|
||||
|
||||
|
||||
let overwrite = false;
|
||||
if (overwrite) {
|
||||
emptyDir(root)
|
||||
} else if (!fs.existsSync(root)) {
|
||||
fs.mkdirSync(root, { recursive: true })
|
||||
}
|
||||
//determine template
|
||||
const isTypescript = (result.template as string).includes('typescript');
|
||||
|
||||
const configJson = {
|
||||
language : isTypescript ? 'typescript' : 'javascript',
|
||||
paths: {
|
||||
@@ -52,16 +70,15 @@ async function runInteractive() {
|
||||
cmds_dir: 'commands'
|
||||
},
|
||||
};
|
||||
//console.log(greenBright('Writing sern.config.json to '+ result.name + "/sern.config.json"));
|
||||
|
||||
console.log(greenBright('Writing sern.config.json to '+ result.name + "/sern.config.json"));
|
||||
try{
|
||||
await writeFile(join(cwd, result.name, 'sern.config.json'), JSON.stringify(configJson), 'utf8');
|
||||
} catch(E) {
|
||||
console.error(redBright(E));
|
||||
process.exit(1);
|
||||
};
|
||||
// try{
|
||||
// await writeFile(path.join(cwd, result.name, 'sern.config.json'), JSON.stringify(configJson), 'utf8');
|
||||
// } catch(E) {
|
||||
// console.error(redBright(E));
|
||||
// process.exit(1);
|
||||
// };
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +95,17 @@ async function init() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function emptyDir(dir: string) {
|
||||
if (!fs.existsSync(dir)) {
|
||||
return
|
||||
}
|
||||
for (const file of fs.readdirSync(dir)) {
|
||||
if (file === '.git') {
|
||||
continue
|
||||
}
|
||||
fs.rmSync(path.resolve(dir, file), { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
init()
|
||||
|
||||
|
||||
2
template-js-esm/.gitignore
vendored
Normal file
2
template-js-esm/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
.env
|
||||
1
template-js-esm/README.md
Normal file
1
template-js-esm/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# TODO
|
||||
24
template-js-esm/package.json
Normal file
24
template-js-esm/package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "js-example",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"private": true,
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"javacsript",
|
||||
"sern",
|
||||
"discord.js"
|
||||
],
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@sern/handler": "^3.0.0",
|
||||
"discord.js": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.25"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
11
template-js-esm/src/commands/ping.js
Normal file
11
template-js-esm/src/commands/ping.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const { CommandType, commandModule } = require('@sern/handler');
|
||||
|
||||
exports.default = commandModule({
|
||||
type: CommandType.Both,
|
||||
plugins: [],
|
||||
description: 'A ping command',
|
||||
//alias : [],
|
||||
execute: async (ctx, args) => {
|
||||
await ctx.reply('Pong 🏓');
|
||||
},
|
||||
});
|
||||
35
template-js-esm/src/index.js
Normal file
35
template-js-esm/src/index.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import { Sern, single } from '@sern/handler';
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
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
|
||||
*/
|
||||
await makeDependencies({
|
||||
build: (root) =>
|
||||
root
|
||||
.add({ '@sern/client': single(() => client) })
|
||||
});
|
||||
|
||||
//View docs for all options
|
||||
Sern.init({
|
||||
defaultPrefix: '!', // removing defaultPrefix will shut down text commands
|
||||
commands: 'src/commands',
|
||||
// events: 'src/events' (optional),
|
||||
});
|
||||
|
||||
client.login();
|
||||
2
template-js/.gitignore
vendored
Normal file
2
template-js/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
.env
|
||||
1
template-js/README.md
Normal file
1
template-js/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# TODO
|
||||
23
template-js/package.json
Normal file
23
template-js/package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "js-example",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"private": true,
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"javacsript",
|
||||
"sern",
|
||||
"discord.js"
|
||||
],
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@sern/handler": "^3.0.0",
|
||||
"discord.js": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.25"
|
||||
}
|
||||
}
|
||||
11
template-js/src/commands/ping.js
Normal file
11
template-js/src/commands/ping.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const { CommandType, commandModule } = require('@sern/handler');
|
||||
|
||||
exports.default = commandModule({
|
||||
type: CommandType.Both,
|
||||
plugins: [],
|
||||
description: 'A ping command',
|
||||
//alias : [],
|
||||
execute: async (ctx, args) => {
|
||||
await ctx.reply('Pong 🏓');
|
||||
},
|
||||
});
|
||||
38
template-js/src/index.js
Normal file
38
template-js/src/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const { Client, GatewayIntentBits } = require('discord.js');
|
||||
const { Sern, single, DefaultLogging } = require('@sern/handler');
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
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
|
||||
*/
|
||||
|
||||
async function init() {
|
||||
await makeDependencies({
|
||||
build: (root) =>
|
||||
root.add({ '@sern/client': single(() => client) })
|
||||
});
|
||||
|
||||
//View docs for all options
|
||||
Sern.init({
|
||||
defaultPrefix: '!', // removing defaultPrefix will shut down text commands
|
||||
commands: 'src/commands',
|
||||
// events: 'src/events' (optional),
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
client.login();
|
||||
3
template-ts-esm/.gitignore
vendored
Normal file
3
template-ts-esm/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/node_modules
|
||||
/dist
|
||||
.env
|
||||
1
template-ts-esm/README.md
Normal file
1
template-ts-esm/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# TODO
|
||||
26
template-ts-esm/package.json
Normal file
26
template-ts-esm/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "ts-example",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "tsc",
|
||||
"start": "tsc && node ./dist/index.js"
|
||||
},
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"sern",
|
||||
"discord.js"
|
||||
],
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@sern/handler": "^3.0.0",
|
||||
"discord.js": "^14.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.25",
|
||||
"typescript": "5.0"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
11
template-ts-esm/src/commands/ping.ts
Normal file
11
template-ts-esm/src/commands/ping.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { commandModule, CommandType } from '@sern/handler';
|
||||
|
||||
export default commandModule({
|
||||
type: CommandType.Both,
|
||||
plugins: [],
|
||||
description: 'A ping command',
|
||||
//alias : [],
|
||||
execute: async (ctx, args) => {
|
||||
await ctx.reply('Pong 🏓');
|
||||
},
|
||||
});
|
||||
38
template-ts-esm/src/index.ts
Normal file
38
template-ts-esm/src/index.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import {
|
||||
Sern,
|
||||
makeDependencies,
|
||||
single,
|
||||
} from '@sern/handler';
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
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
|
||||
*/
|
||||
await makeDependencies({
|
||||
build: (root) =>
|
||||
root.add({ '@sern/client': single(() => client) })
|
||||
});
|
||||
|
||||
//View docs for all options
|
||||
Sern.init({
|
||||
defaultPrefix: '!', // removing defaultPrefix will shut down text commands
|
||||
commands: 'dist/commands',
|
||||
// events: 'dist/events' (optional),
|
||||
});
|
||||
|
||||
client.login();
|
||||
16
template-ts-esm/tsconfig.json
Normal file
16
template-ts-esm/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"importsNotUsedAsValues": "error",
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
3
template-ts/.gitignore
vendored
Normal file
3
template-ts/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/node_modules
|
||||
/dist
|
||||
.env
|
||||
1
template-ts/README.md
Normal file
1
template-ts/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# TODO
|
||||
25
template-ts/package.json
Normal file
25
template-ts/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "ts-example",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "tsc",
|
||||
"start": "tsc && node ./dist/index.js"
|
||||
},
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"sern",
|
||||
"discord.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@sern/handler": "^3.0.0",
|
||||
"discord.js": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.25",
|
||||
"typescript": "^5.0"
|
||||
}
|
||||
}
|
||||
11
template-ts/src/commands/ping.ts
Normal file
11
template-ts/src/commands/ping.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { commandModule, CommandType } from '@sern/handler';
|
||||
|
||||
export default commandModule({
|
||||
type: CommandType.Both,
|
||||
plugins: [],
|
||||
description: 'A ping command',
|
||||
//alias : [],
|
||||
execute: async (ctx, args) => {
|
||||
await ctx.reply('Pong 🏓');
|
||||
},
|
||||
});
|
||||
41
template-ts/src/index.ts
Normal file
41
template-ts/src/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import {
|
||||
Sern,
|
||||
single,
|
||||
makeDependencies
|
||||
} from '@sern/handler';
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
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
|
||||
*/
|
||||
async function init() {
|
||||
await makeDependencies({
|
||||
build: (root) =>
|
||||
root.add({ '@sern/client': single(() => client) })
|
||||
});
|
||||
|
||||
//View docs for all options
|
||||
Sern.init({
|
||||
defaultPrefix: '!', // removing defaultPrefix will shut down text commands
|
||||
commands: 'dist/commands',
|
||||
// events: 'dist/events' (optional),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
client.login();
|
||||
16
template-ts/tsconfig.json
Normal file
16
template-ts/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"target": "ESNext",
|
||||
"module": "CommonJS",
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"importsNotUsedAsValues": "error",
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user