2024-02-22 14:34:50 +03:00
|
|
|
import * as colors from 'colorette'
|
2023-10-22 20:18:12 +03:00
|
|
|
import { join } from 'node:path'
|
|
|
|
|
|
|
|
import { askForConfig } from './cli.js'
|
|
|
|
import { installDependencies } from './dependencies.js'
|
2023-10-27 00:15:56 +03:00
|
|
|
import { MtcuteFeature } from './features/types.js'
|
2023-10-22 20:18:12 +03:00
|
|
|
import { runTemplater } from './templater.js'
|
2023-10-27 00:15:56 +03:00
|
|
|
import { exec } from './utils.js'
|
2023-10-22 20:18:12 +03:00
|
|
|
|
|
|
|
const projectName = process.argv[2]
|
|
|
|
|
|
|
|
if (!projectName) {
|
|
|
|
console.error('Usage: create-mtcute-bot <project-name>')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2023-10-23 12:18:04 +03:00
|
|
|
const config = await askForConfig()
|
2023-10-22 20:18:12 +03:00
|
|
|
config.name = projectName
|
|
|
|
const outDir = process.env.TARGET_DIR || join(process.cwd(), projectName)
|
|
|
|
|
|
|
|
const __dirname = new URL('.', import.meta.url).pathname
|
|
|
|
|
|
|
|
await runTemplater(join(__dirname, '../template'), outDir, config)
|
|
|
|
|
|
|
|
await installDependencies(outDir, config)
|
2023-10-23 12:18:04 +03:00
|
|
|
|
2023-10-27 00:15:56 +03:00
|
|
|
await exec(outDir, 'git', 'init')
|
|
|
|
|
|
|
|
if (config.features.includes(MtcuteFeature.Linters)) {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
// windows doesn't track executable bit, but git does
|
|
|
|
await exec(outDir, 'git', 'update-index', '--chmod=+x', '.husky/pre-commit')
|
|
|
|
} else {
|
|
|
|
await exec(outDir, 'chmod', '+x', '.husky/pre-commit')
|
|
|
|
}
|
|
|
|
|
|
|
|
await exec(outDir, 'pnpm', 'exec', 'husky', 'install')
|
|
|
|
}
|
|
|
|
|
2024-02-22 14:34:50 +03:00
|
|
|
console.log(`✅ Scaffolded new project at ${colors.blue(outDir)}`)
|
2023-10-23 12:18:04 +03:00
|
|
|
console.log('🚀 Run it with:')
|
2024-02-22 14:34:50 +03:00
|
|
|
console.log(` ${colors.blue('$')} cd ${projectName}`)
|
|
|
|
console.log(` ${colors.blue('$')} pnpm start`)
|