Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 16, 2024
1 parent f3fec05 commit 5bbae44
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 70 deletions.
Binary file modified bun.lockb
Binary file not shown.
File renamed without changes.
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export default stacks({
typescript: true,
jsonc: true,
yaml: true,
ignores: [
'fixtures/**'
]
})
32 changes: 32 additions & 0 deletions fixtures/output/example-1.d.ts
Original file line number Diff line number Diff line change
@@ -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<ResponseData> {
return fetch(config.apiUrl)
.then(response => response.json()) as Promise<ResponseData>
}
33 changes: 33 additions & 0 deletions fixtures/output/example-2.d.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
status: number
message: string
data: T
}

/**
* Example of function declaration
*/
export function getProduct(id: number): Promise<ApiResponse<Product>> {
return fetch(`${settings.apiUrl}/products/${id}`)
.then(response => response.json()) as Promise<ApiResponse<Product>>
}
34 changes: 34 additions & 0 deletions fixtures/output/example-3.d.ts
Original file line number Diff line number Diff line change
@@ -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<OrderResponse> {
return fetch(endpoints.getProducts, {
method: 'POST',
body: JSON.stringify(order),
}).then(response => response.json()) as Promise<OrderResponse>
}
30 changes: 30 additions & 0 deletions fixtures/output/example-4.d.ts
Original file line number Diff line number Diff line change
@@ -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<AuthResponse> {
return fetch('/auth/login', {
method: 'POST',
body: JSON.stringify({ user, password }),
}).then(response => response.json()) as Promise<AuthResponse>
}
30 changes: 30 additions & 0 deletions fixtures/output/example-5.d.ts
Original file line number Diff line number Diff line change
@@ -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<CommentsResponse> {
return fetch(`/posts/${postId}/comments`)
.then(response => response.json()) as Promise<CommentsResponse>
}
63 changes: 0 additions & 63 deletions fixtures/output/examples-1-5.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <chris@stacksjs.org>",
"license": "MIT",
Expand All @@ -16,8 +16,8 @@
"keywords": [
"dts",
"generation",
"isolated declarations",
"development",
"environment",
"bun",
"stacks",
"typescript",
Expand Down
17 changes: 16 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -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<DtsGenerationConfig>

/**
* DtsGenerationOptions
*
* This is the configuration object for the DTS generation process.
*/
export type DtsGenerationOptions = DtsGenerationOption | DtsGenerationOption[]
9 changes: 6 additions & 3 deletions test.ts
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 5bbae44

Please sign in to comment.