diff --git a/bun.lockb b/bun.lockb index 62ad6a3..50c2cc7 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/dts b/dtsx similarity index 100% rename from dts rename to dtsx diff --git a/eslint.config.js b/eslint.config.js index 44b7d05..8667c7b 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -9,4 +9,7 @@ export default stacks({ typescript: true, jsonc: true, yaml: true, + ignores: [ + 'fixtures/**' + ] }) diff --git a/fixtures/output/example-1.d.ts b/fixtures/output/example-1.d.ts new file mode 100644 index 0000000..2280d8c --- /dev/null +++ b/fixtures/output/example-1.d.ts @@ -0,0 +1,32 @@ +/** + * Example of const declaration + */ +export const config: { [key: string]: string } = { + apiUrl: 'https://api.example.com', + timeout: '5000', +} + +/** + * Example of interface declaration + */ +export interface User { + id: number + name: string + email: string +} + +/** + * Example of type declaration + */ +export interface ResponseData { + success: boolean + data: User[] +} + +/** + * Example of function declaration + */ +export function fetchUsers(): Promise { + return fetch(config.apiUrl) + .then(response => response.json()) as Promise +} diff --git a/fixtures/output/example-2.d.ts b/fixtures/output/example-2.d.ts new file mode 100644 index 0000000..cd39dfe --- /dev/null +++ b/fixtures/output/example-2.d.ts @@ -0,0 +1,33 @@ +/** + * Example of another const declaration + */ +export const settings: { [key: string]: any } = { + theme: 'dark', + language: 'en', +} + +/** + * Example of interface declaration + */ +export interface Product { + id: number + name: string + price: number +} + +/** + * Example of type declaration + */ +export interface ApiResponse { + status: number + message: string + data: T +} + +/** + * Example of function declaration + */ +export function getProduct(id: number): Promise> { + return fetch(`${settings.apiUrl}/products/${id}`) + .then(response => response.json()) as Promise> +} diff --git a/fixtures/output/example-3.d.ts b/fixtures/output/example-3.d.ts new file mode 100644 index 0000000..d3ee491 --- /dev/null +++ b/fixtures/output/example-3.d.ts @@ -0,0 +1,34 @@ +/** + * Example of const declaration + */ +export const endpoints = { + getUsers: '/users', + getProducts: '/products', +} + +/** + * Example of interface declaration + */ +export interface Order { + orderId: number + userId: number + productIds: number[] +} + +/** + * Example of type declaration + */ +export interface OrderResponse { + success: boolean + order: Order +} + +/** + * Example of function declaration + */ +export async function createOrder(order: Order): Promise { + return fetch(endpoints.getProducts, { + method: 'POST', + body: JSON.stringify(order), + }).then(response => response.json()) as Promise +} diff --git a/fixtures/output/example-4.d.ts b/fixtures/output/example-4.d.ts new file mode 100644 index 0000000..1383251 --- /dev/null +++ b/fixtures/output/example-4.d.ts @@ -0,0 +1,30 @@ +/** + * Example of const declaration + */ +export const apiKeys = { + google: 'GOOGLE_API_KEY', + facebook: 'FACEBOOK_API_KEY', +} + +/** + * Example of interface declaration + */ +export interface AuthResponse { + token: string + expiresIn: number +} + +/** + * Example of type declaration + */ +export type AuthStatus = 'authenticated' | 'unauthenticated' + +/** + * Example of function declaration + */ +export function authenticate(user: string, password: string): Promise { + return fetch('/auth/login', { + method: 'POST', + body: JSON.stringify({ user, password }), + }).then(response => response.json()) as Promise +} diff --git a/fixtures/output/example-5.d.ts b/fixtures/output/example-5.d.ts new file mode 100644 index 0000000..b08740c --- /dev/null +++ b/fixtures/output/example-5.d.ts @@ -0,0 +1,30 @@ +/** + * Example of const declaration + */ +export const defaultHeaders = { + 'Content-Type': 'application/json', +} + +/** + * Example of interface declaration + */ +export interface Comment { + id: number + postId: number + body: string +} + +/** + * Example of type declaration + */ +export interface CommentsResponse { + comments: Comment[] +} + +/** + * Example of function declaration + */ +export function fetchComments(postId: number): Promise { + return fetch(`/posts/${postId}/comments`) + .then(response => response.json()) as Promise +} diff --git a/fixtures/output/examples-1-5.d.ts b/fixtures/output/examples-1-5.d.ts deleted file mode 100644 index 0f09cdc..0000000 --- a/fixtures/output/examples-1-5.d.ts +++ /dev/null @@ -1,63 +0,0 @@ -export declare const config: { [key: string]: string }; -export interface User { - id: number; - name: string; - email: string; -} -export type ResponseData = { - success: boolean; - data: User[]; -}; -export declare function fetchUsers(): Promise; - -export declare const settings: { [key: string]: any }; -export interface Product { - id: number; - name: string; - price: number; -} -export type ApiResponse = { - status: number; - message: string; - data: T; -}; -export declare function getProduct(id: number): Promise>; - -export declare const endpoints: { - getUsers: string; - getProducts: string; -}; -export interface Order { - orderId: number; - userId: number; - productIds: number[]; -} -export type OrderResponse = { - success: boolean; - order: Order; -}; -export declare function createOrder(order: Order): Promise; - -export declare const apiKeys: { - google: string; - facebook: string; -}; -export interface AuthResponse { - token: string; - expiresIn: number; -} -export type AuthStatus = "authenticated" | "unauthenticated"; -export declare function authenticate(user: string, password: string): Promise; - -export declare const defaultHeaders: { - "Content-Type": string; -}; -export interface Comment { - id: number; - postId: number; - body: string; -} -export type CommentsResponse = { - comments: Comment[]; -}; -export declare function fetchComments(postId: number): Promise; diff --git a/package.json b/package.json index 4613fb7..c904059 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "dts-generation", + "name": "dtsx", "type": "module", - "version": "0.1.0", + "version": "0.0.0", "description": "A modern, fast .d.ts generation tool, powered by Bun.", "author": "Chris Breuer ", "license": "MIT", @@ -16,8 +16,8 @@ "keywords": [ "dts", "generation", + "isolated declarations", "development", - "environment", "bun", "stacks", "typescript", diff --git a/src/types.ts b/src/types.ts index 91311db..41b10b3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,12 +1,27 @@ +/** + * DtsGenerationConfig + * + * This is the configuration object for the DTS generation process. + */ export interface DtsGenerationConfig { cwd: string root: string outdir: string keepComments: boolean clean: boolean - tsconfigPath?: string + tsconfigPath: string } +/** + * DtsGenerationOption + * + * This is the configuration object for the DTS generation process. + */ export type DtsGenerationOption = Partial +/** + * DtsGenerationOptions + * + * This is the configuration object for the DTS generation process. + */ export type DtsGenerationOptions = DtsGenerationOption | DtsGenerationOption[] diff --git a/test.ts b/test.ts index e5e94c2..1604f2a 100644 --- a/test.ts +++ b/test.ts @@ -1,4 +1,7 @@ -import { generateDeclarationsFromFiles } from './src' -// Example usage -generateDeclarationsFromFiles('./src'); +import { generate } from './src' +console.log('Generating declarations...') +generate({ + root: './src', +}) +console.log('Generated declarations')