forked from rolldown/rolldown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (47 loc) · 1.23 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { defineCommand, runMain, showUsage } from 'citty'
import consola from 'consola'
import process from 'node:process'
import path from 'node:path'
import pkgJson from '../../package.json' assert { type: 'json' }
import { loadConfig } from './utils.js'
import { bundle } from './commands/bundle'
const main = defineCommand({
meta: {
name: 'rolldown',
version: pkgJson.version,
description: pkgJson.description,
},
args: {
config: {
type: 'string',
alias: 'c',
description:
'Use this config file (if argument is used but value is unspecified, defaults to rolldown.config.js)',
},
help: {
type: 'boolean',
alias: 'h',
description: 'Show this help message',
},
},
async run(ctx) {
if (ctx.args.help) {
await showUsage(ctx.cmd)
return
}
const cwd = process.cwd()
let configPath
if (ctx.args.config) {
configPath = path.resolve(cwd, ctx.args.config)
} else {
configPath = path.resolve(cwd, 'rolldown.config.js')
}
const config = await loadConfig(configPath)
if (!config) {
consola.error(`No configuration found at ${configPath}`)
process.exit(1)
}
await bundle(config)
},
})
runMain(main)