Skip to content

Commit d0ebe4d

Browse files
committed
feat: add creating of dev instance of Harmonix
1 parent 50cc4a0 commit d0ebe4d

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

bin/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22

3-
import { createHarmonix } from '../dist/index.mjs'
3+
import { createDevHarmonix, createHarmonix } from '../dist/index.mjs'
44
import 'dotenv/config'
55

66
const initHarmonix = async () => {
7-
await createHarmonix({ rootDir: './playground' }, { cwd: './playground' })
7+
await createDevHarmonix({ rootDir: './playground' }, { cwd: './playground' })
88
}
99

1010
initHarmonix()

src/harmonix.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { colors } from 'consola/utils'
66
import { watch } from 'chokidar'
77
import { resolve } from 'pathe'
88
import { debounce } from 'perfect-debounce'
9+
import type { Stats } from 'node:fs'
910
import { loadOptions } from './options'
1011
import {
1112
scanButtons,
@@ -46,7 +47,6 @@ import {
4647
} from './resolve'
4748
import type { Harmonix, HarmonixConfig, HarmonixOptions } from './types'
4849
import { version } from '../package.json'
49-
import { Stats } from 'fs'
5050

5151
export const ctx = getContext<Harmonix>('harmonix')
5252

@@ -73,12 +73,38 @@ export const createHarmonix = async (
7373
preconditions: new Collection()
7474
}
7575

76+
consola.log(colors.blue(`Harmonix ${colors.bold(version)}\n`))
77+
await loadHarmonix(harmonix, config, opts)
78+
79+
return harmonix
80+
}
81+
82+
export const createDevHarmonix = async (
83+
config: HarmonixConfig = {},
84+
opts: LoadConfigOptions = {}
85+
) => {
86+
if (!process.env.DISCORD_CLIENT_TOKEN) {
87+
createError(
88+
'Client token is required. Please provide it in the environment variable DISCORD_CLIENT_TOKEN.'
89+
)
90+
}
91+
const options = await loadOptions(config, opts)
92+
const harmonix: Harmonix = {
93+
options: options as HarmonixOptions,
94+
events: new Collection(),
95+
commands: new Collection(),
96+
contextMenus: new Collection(),
97+
buttons: new Collection(),
98+
modals: new Collection(),
99+
selectMenus: new Collection(),
100+
preconditions: new Collection()
101+
}
102+
76103
consola.log(colors.blue(`Harmonix ${colors.bold(version)}\n`))
77104
const watcher = watch(harmonix.options.scanDirs, {
78105
ignored: harmonix.options.ignore,
79106
ignoreInitial: true
80107
})
81-
82108
const reload = debounce(
83109
async (event: string, path: string, stats: Stats | undefined) => {
84110
if (stats?.size === 0) return

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export * from './define'
22
export * from './getters'
33
export * from './uses'
4-
export { createHarmonix, createError, useHarmonix } from './harmonix'
4+
export {
5+
createHarmonix,
6+
createDevHarmonix,
7+
createError,
8+
useHarmonix
9+
} from './harmonix'

0 commit comments

Comments
 (0)