feat(create-bot): support bun
This commit is contained in:
parent
bcbf0d6b8c
commit
9d34d902a4
8 changed files with 70 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
||||||
# @mtcute/create-bot
|
# @mtcute/create-bot
|
||||||
|
|
||||||
Starter kit for creating bots using `@mtcute/node`.
|
Starter kit for creating bots using `@mtcute/node` or `@mtcute/bun`.
|
||||||
|
|
||||||
[Learn more](https://mtcute.dev/guide/)
|
[Learn more](https://mtcute.dev/guide/)
|
||||||
|
|
||||||
|
@ -12,7 +12,15 @@ Starter kit for creating bots using `@mtcute/node`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
Depending on your preferred package manager, run one of the following commands:
|
||||||
```bash
|
```bash
|
||||||
pnpm create @mtcute/bot
|
pnpm create @mtcute/bot
|
||||||
# and follow the instructions
|
# or
|
||||||
|
yarn create @mtcute/bot
|
||||||
|
# or
|
||||||
|
npm create @mtcute/bot
|
||||||
|
# or
|
||||||
|
bun create @mtcute/bot
|
||||||
```
|
```
|
||||||
|
|
||||||
|
and follow the instructions
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { readConfig, UserConfigPersisted, writeConfig } from './config.js'
|
||||||
import { TELEGRAM_APPS_PAGE } from './constants.js'
|
import { TELEGRAM_APPS_PAGE } from './constants.js'
|
||||||
import { getFeatureChoices } from './features/cli.js'
|
import { getFeatureChoices } from './features/cli.js'
|
||||||
import { MtcuteFeature } from './features/types.js'
|
import { MtcuteFeature } from './features/types.js'
|
||||||
import { getPackageManager, PackageManager } from './package-manager.js'
|
import { PackageManager } from './package-manager.js'
|
||||||
|
|
||||||
interface UserConfigAnswers {
|
interface UserConfigAnswers {
|
||||||
reuse?: boolean
|
reuse?: boolean
|
||||||
|
@ -101,7 +101,7 @@ export async function askForConfigPersisted(): Promise<UserConfigPersisted> {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function askForConfig(): Promise<UserConfig> {
|
export async function askForConfig(packageManager: PackageManager): Promise<UserConfig> {
|
||||||
const persisted = await askForConfigPersisted()
|
const persisted = await askForConfigPersisted()
|
||||||
|
|
||||||
let allowEmptyBotToken = false
|
let allowEmptyBotToken = false
|
||||||
|
@ -128,7 +128,7 @@ export async function askForConfig(): Promise<UserConfig> {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
choices: getFeatureChoices(),
|
choices: getFeatureChoices(packageManager),
|
||||||
name: 'features',
|
name: 'features',
|
||||||
message: 'Select features:',
|
message: 'Select features:',
|
||||||
},
|
},
|
||||||
|
@ -137,7 +137,7 @@ export async function askForConfig(): Promise<UserConfig> {
|
||||||
return {
|
return {
|
||||||
...persisted,
|
...persisted,
|
||||||
name: '', // will be filled later
|
name: '', // will be filled later
|
||||||
packageManager: getPackageManager(),
|
packageManager,
|
||||||
botToken: botToken || undefined,
|
botToken: botToken || undefined,
|
||||||
features,
|
features,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
import { UserConfig } from './cli.js'
|
import { UserConfig } from './cli.js'
|
||||||
import { MtcuteFeature } from './features/types.js'
|
import { MtcuteFeature } from './features/types.js'
|
||||||
import { getInstallCommand } from './package-manager.js'
|
import { getInstallCommand, PackageManager } from './package-manager.js'
|
||||||
import { exec } from './utils.js'
|
import { exec } from './utils.js'
|
||||||
|
|
||||||
export function buildDependenciesList(config: UserConfig) {
|
export function buildDependenciesList(config: UserConfig) {
|
||||||
const dependencies = ['@mtcute/node']
|
const dependencies = []
|
||||||
const devDepdenencies = ['dotenv-cli']
|
const devDepdenencies = ['dotenv-cli']
|
||||||
|
|
||||||
|
if (config.packageManager === PackageManager.Bun) {
|
||||||
|
dependencies.push('@mtcute/bun')
|
||||||
|
} else {
|
||||||
|
dependencies.push('@mtcute/node')
|
||||||
|
}
|
||||||
|
|
||||||
if (config.features.includes(MtcuteFeature.Dispatcher)) {
|
if (config.features.includes(MtcuteFeature.Dispatcher)) {
|
||||||
dependencies.push('@mtcute/dispatcher')
|
dependencies.push('@mtcute/dispatcher')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
import { CheckboxChoiceOptions } from 'inquirer'
|
import { CheckboxChoiceOptions } from 'inquirer'
|
||||||
|
|
||||||
|
import { PackageManager } from '../package-manager.js'
|
||||||
import { MtcuteFeature } from './types.js'
|
import { MtcuteFeature } from './types.js'
|
||||||
|
|
||||||
export function getFeatureChoices(): CheckboxChoiceOptions[] {
|
export function getFeatureChoices(packageMananger: PackageManager): CheckboxChoiceOptions[] {
|
||||||
return [
|
const arr: CheckboxChoiceOptions[] = [
|
||||||
{
|
|
||||||
name: ' 🚀 Native addon (better performance)',
|
|
||||||
short: 'Native addon',
|
|
||||||
value: MtcuteFeature.NativeAddon,
|
|
||||||
checked: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: ' 🌐 Internationalization',
|
name: ' 🌐 Internationalization',
|
||||||
short: 'i18n',
|
short: 'i18n',
|
||||||
|
@ -21,12 +16,6 @@ export function getFeatureChoices(): CheckboxChoiceOptions[] {
|
||||||
value: MtcuteFeature.Dispatcher,
|
value: MtcuteFeature.Dispatcher,
|
||||||
checked: true,
|
checked: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: ' 🐳 Generate Dockerfile',
|
|
||||||
short: 'Dockerfile',
|
|
||||||
value: MtcuteFeature.Docker,
|
|
||||||
checked: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: ' ✨ Use TypeScript',
|
name: ' ✨ Use TypeScript',
|
||||||
short: 'TypeScript',
|
short: 'TypeScript',
|
||||||
|
@ -40,4 +29,25 @@ export function getFeatureChoices(): CheckboxChoiceOptions[] {
|
||||||
checked: true,
|
checked: true,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (packageMananger !== PackageManager.Bun) {
|
||||||
|
arr.unshift({
|
||||||
|
name: ' 🚀 Native addon (better performance)',
|
||||||
|
short: 'Native addon',
|
||||||
|
value: MtcuteFeature.NativeAddon,
|
||||||
|
checked: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packageMananger === PackageManager.Pnpm) {
|
||||||
|
// todo: add support for dockerfile generation for other package managers
|
||||||
|
arr.push({
|
||||||
|
name: ' 🐳 Generate Dockerfile',
|
||||||
|
short: 'Dockerfile',
|
||||||
|
value: MtcuteFeature.Docker,
|
||||||
|
checked: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url'
|
||||||
import { askForConfig } from './cli.js'
|
import { askForConfig } from './cli.js'
|
||||||
import { installDependencies } from './dependencies.js'
|
import { installDependencies } from './dependencies.js'
|
||||||
import { MtcuteFeature } from './features/types.js'
|
import { MtcuteFeature } from './features/types.js'
|
||||||
import { getExecCommand } from './package-manager.js'
|
import { getExecCommand, getPackageManager, PackageManager } from './package-manager.js'
|
||||||
import { runTemplater } from './templater.js'
|
import { runTemplater } from './templater.js'
|
||||||
import { exec } from './utils.js'
|
import { exec } from './utils.js'
|
||||||
|
|
||||||
|
@ -17,7 +17,13 @@ if (!projectName) {
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = await askForConfig()
|
const packageManager = getPackageManager()
|
||||||
|
|
||||||
|
if (packageManager === PackageManager.Bun) {
|
||||||
|
console.log(`${colors.red('‼️ Warning:')} ${colors.yellow('Bun')} support is ${colors.bold('experimental')}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = await askForConfig(packageManager)
|
||||||
config.name = projectName
|
config.name = projectName
|
||||||
const outDir = process.env.TARGET_DIR || join(process.cwd(), projectName)
|
const outDir = process.env.TARGET_DIR || join(process.cwd(), projectName)
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,19 @@
|
||||||
"lint:fix": "eslint --fix .",
|
"lint:fix": "eslint --fix .",
|
||||||
"format": "prettier --write \"src/**/*.ts\"",
|
"format": "prettier --write \"src/**/*.ts\"",
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{#if (eq packageManager "bun")}}
|
||||||
|
{{#if features.typescript}}
|
||||||
|
"start": "bun ./src/index.ts"
|
||||||
|
{{else}}
|
||||||
|
"start": "bun ./src/index.js"
|
||||||
|
{{/if}}
|
||||||
|
{{else}}
|
||||||
{{#if features.typescript}}
|
{{#if features.typescript}}
|
||||||
"start": "tsc && dotenv node ./dist/index.js",
|
"start": "tsc && dotenv node ./dist/index.js",
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
{{else}}
|
{{else}}
|
||||||
"start": "dotenv node ./src/index.js"
|
"start": "dotenv node ./src/index.js"
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,11 @@
|
||||||
{{#if features.dispatcher}}
|
{{#if features.dispatcher}}
|
||||||
import { Dispatcher, filters } from '@mtcute/dispatcher'
|
import { Dispatcher, filters } from '@mtcute/dispatcher'
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{#if (eq packageManager "bun")}}
|
||||||
|
import { TelegramClient } from '@mtcute/bun'
|
||||||
|
{{else}}
|
||||||
import { TelegramClient } from '@mtcute/node'
|
import { TelegramClient } from '@mtcute/node'
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
import * as env from './env.js'
|
import * as env from './env.js'
|
||||||
{{#if features.i18n}}
|
{{#if features.i18n}}
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
{{#if features.dispatcher}}
|
{{#if features.dispatcher}}
|
||||||
import { Dispatcher, filters } from '@mtcute/dispatcher'
|
import { Dispatcher, filters } from '@mtcute/dispatcher'
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{#if (eq packageManager "bun")}}
|
||||||
|
import { TelegramClient } from '@mtcute/bun'
|
||||||
|
{{else}}
|
||||||
import { TelegramClient } from '@mtcute/node'
|
import { TelegramClient } from '@mtcute/node'
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
import * as env from './env.js'
|
import * as env from './env.js'
|
||||||
{{#if features.i18n}}
|
{{#if features.i18n}}
|
||||||
|
|
Loading…
Reference in a new issue