feat: import plugins using import.meta.glob
This commit is contained in:
parent
f56309f448
commit
fe43fd14d4
44 changed files with 27 additions and 9 deletions
|
|
@ -4,7 +4,7 @@ import { $, main } from 'bun'
|
|||
import chalk from 'chalk'
|
||||
import { exists, mkdir, readdir, rm, writeFile } from 'fs/promises'
|
||||
import { type OutputChunk, type RolldownPlugin, rolldown } from 'rolldown'
|
||||
import { aliasPlugin } from 'rolldown/experimental'
|
||||
import { aliasPlugin, importGlobPlugin } from 'rolldown/experimental'
|
||||
|
||||
import pkg from '../package.json'
|
||||
|
||||
|
|
@ -50,7 +50,6 @@ export default async function build(dev = false, log = true) {
|
|||
__BUILD_FLAG_LOG_PROMISE_REJECTIONS__: String(dev),
|
||||
},
|
||||
plugins: [
|
||||
swcPlugin(),
|
||||
aliasPlugin({
|
||||
entries: [
|
||||
{
|
||||
|
|
@ -59,6 +58,8 @@ export default async function build(dev = false, log = true) {
|
|||
},
|
||||
],
|
||||
}),
|
||||
importGlobPlugin(),
|
||||
swcPlugin(),
|
||||
hermesCPlugin({
|
||||
flags: [
|
||||
dev ? '-Og' : '-O',
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ onModuleFirstRequired(IndexModuleId, function onIndexRequired() {
|
|||
require('@revenge-mod/discord/preinit')
|
||||
|
||||
// Run all preinit plugins
|
||||
require('~/plugins/_preinit')
|
||||
require('~/plugins/preinit')
|
||||
require('@revenge-mod/plugins/preinit')
|
||||
|
||||
onModuleInitialized(IndexModuleId, function onIndexInitialized() {
|
||||
|
|
@ -30,7 +30,7 @@ onModuleFirstRequired(IndexModuleId, function onIndexRequired() {
|
|||
// Initialize init libraries
|
||||
|
||||
// Run all init plugins
|
||||
require('~/plugins/_all')
|
||||
require('~/plugins/init')
|
||||
require('@revenge-mod/plugins/init')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
import './staff-settings'
|
||||
import './settings'
|
||||
import './developer-settings'
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
import './logging'
|
||||
import './no-track'
|
||||
3
src/plugins/init.ts
Normal file
3
src/plugins/init.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import.meta.glob('./init/*/index.ts', {
|
||||
eager: true,
|
||||
})
|
||||
3
src/plugins/preinit.ts
Normal file
3
src/plugins/preinit.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import.meta.glob('./preinit/*/index.ts', {
|
||||
eager: true,
|
||||
})
|
||||
16
types.d.ts
vendored
16
types.d.ts
vendored
|
|
@ -7,6 +7,22 @@ declare global {
|
|||
const __BUILD_VERSION__: string
|
||||
|
||||
const __BUILD_FLAG_LOG_PROMISE_REJECTIONS__: boolean
|
||||
|
||||
export interface ImportMeta {
|
||||
glob<T = any>(pattern: ImportMetaGlobPattern, options?: ImportMetaGlobOptions): Record<string, () => Promise<T>>
|
||||
glob<T = any>(
|
||||
pattern: ImportMetaGlobPattern,
|
||||
options: Extract<ImportMetaGlobOptions, { eager: true }>,
|
||||
): Record<string, T>
|
||||
}
|
||||
}
|
||||
|
||||
interface ImportMetaGlobOptions {
|
||||
eager?: boolean
|
||||
import?: string
|
||||
query?: string | Record<string, string>
|
||||
}
|
||||
|
||||
type ImportMetaGlobPattern = string | string[]
|
||||
|
||||
export {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue