build(create-bot): fixed package building

This commit is contained in:
alina 🌸 2023-10-23 12:18:04 +03:00
parent f1bc6aff64
commit d5d5615a4d
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
4 changed files with 18 additions and 4 deletions

View file

@ -7,11 +7,11 @@
"license": "MIT",
"type": "module",
"scripts": {
"build": "pnpm run -w build-package node",
"build": "pnpm run -w build-package create-bot",
"run": "ts-node-esm src/main.ts"
},
"bin": {
"create-bot": "./dist/main.js"
"create-bot": "./src/main.js"
},
"dependencies": {
"chalk": "^5.3.0",

View file

@ -1,11 +1,10 @@
import chalk from 'chalk'
import { join } from 'node:path'
import { askForConfig } from './cli.js'
import { installDependencies } from './dependencies.js'
import { runTemplater } from './templater.js'
const config = await askForConfig()
const projectName = process.argv[2]
if (!projectName) {
@ -13,6 +12,7 @@ if (!projectName) {
process.exit(1)
}
const config = await askForConfig()
config.name = projectName
const outDir = process.env.TARGET_DIR || join(process.cwd(), projectName)
@ -21,3 +21,8 @@ const __dirname = new URL('.', import.meta.url).pathname
await runTemplater(join(__dirname, '../template'), outDir, config)
await installDependencies(outDir, config)
console.log(`✅ Scaffolded new project at ${chalk.blue(outDir)}`)
console.log('🚀 Run it with:')
console.log(` ${chalk.blue('$')} cd ${projectName}`)
console.log(` ${chalk.blue('$')} pnpm run run`)

View file

@ -43,6 +43,7 @@ export async function runTemplaterForFile(file: string, config: UserConfig): Pro
return acc
},
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
{} as Record<MtcuteFeature, boolean>,
),
})

View file

@ -99,6 +99,12 @@ const BUILD_CONFIGS = {
},
},
node: { esmOnlyDirectives: true },
'create-bot': {
buildCjs: false,
customScript(packageDir, outDir) {
fs.cpSync(path.join(packageDir, 'template'), path.join(outDir, 'template'), { recursive: true })
},
},
}
const buildConfig = {
@ -258,6 +264,8 @@ try {
console.log('[!] Failed to copy README.md: ' + e.message)
}
fs.cpSync(path.join(__dirname, '../LICENSE'), path.join(outDir, 'LICENSE'))
fs.writeFileSync(path.join(outDir, '.npmignore'), '*.tsbuildinfo\n')
buildConfig.customScript(packageDir, outDir)