-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de495ee
commit 0e996ab
Showing
7 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { resolve } from 'node:path' | ||
import process from 'node:process' | ||
import { deepMerge } from './utils' | ||
|
||
export interface ConfigOptions<T> { | ||
name: string | ||
cwd?: string | ||
defaultConfig: T | ||
} | ||
|
||
export async function loadConfig<T extends Record<string, unknown>>({ name, cwd, defaultConfig }: ConfigOptions<T>): Promise<T> { | ||
const c = cwd ?? process.cwd() | ||
const configPath = resolve(c, `${name}.config`) | ||
|
||
try { | ||
const importedConfig = await import(configPath) | ||
const loadedConfig = importedConfig.default || importedConfig | ||
return deepMerge(defaultConfig, loadedConfig) | ||
} | ||
catch (error) { | ||
console.error(`Error loading config from ${configPath}:`, error) | ||
return defaultConfig | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { DtsGenerationOption } from '@stacksjs/dtsx' | ||
import type { BunPlugin } from 'bun' | ||
import process from 'node:process' | ||
import { generate } from '@stacksjs/dtsx' | ||
|
||
export function dts(options?: DtsGenerationOption): BunPlugin { | ||
return { | ||
name: 'bun-plugin-dtsx', | ||
|
||
async setup(build) { | ||
const cwd = options?.cwd ?? process.cwd() | ||
const root = options?.root ?? build.config.root | ||
const entrypoints = options?.entrypoints ?? build.config.entrypoints | ||
const outdir = options?.outdir ?? build.config.outdir | ||
// const keepComments = options?.keepComments ?? true | ||
const clean = options?.clean ?? false | ||
const tsconfigPath = options?.tsconfigPath ?? './tsconfig.json' | ||
|
||
await generate({ | ||
...options, | ||
cwd, | ||
root, | ||
entrypoints, | ||
outdir, | ||
// keepComments, | ||
clean, | ||
tsconfigPath, | ||
}) | ||
}, | ||
} | ||
} | ||
|
||
export { generate } | ||
|
||
export type { DtsGenerationOption } | ||
|
||
export default dts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export declare interface ConfigOptions<T> { | ||
name: string | ||
cwd?: string | ||
defaultConfig: T | ||
} | ||
export declare function loadConfig<T extends Record<string, unknown>>({ name, cwd, defaultConfig }: ConfigOptions<T>): Promise<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { BunPlugin } from 'bun'; | ||
import type { DtsGenerationOption } from '@stacksjs/dtsx'; | ||
import { generate } from '@stacksjs/dtsx'; | ||
|
||
export { generate } | ||
export type { DtsGenerationOption }; | ||
export declare function dts(options?: DtsGenerationOption): BunPlugin; | ||
|
||
export default dts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export declare interface ConfigOptions<T> { | ||
name: string | ||
cwd?: string | ||
defaultConfig: T | ||
} | ||
export declare function loadConfig<T extends Record<string, unknown>>({ name, cwd, defaultConfig }: ConfigOptions<T>): Promise<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters