Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 29, 2024
1 parent 7e3207f commit 3bd5594
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
9 changes: 0 additions & 9 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { extract } from './extract'
import { checkIsolatedDeclarations, getAllTypeScriptFiles, writeToFile } from './utils'

export async function generateDeclarationsFromFiles(options?: DtsGenerationConfig): Promise<void> {
// console.log('Generating declaration files...', options)
try {
// Check for isolatedModules setting
const isIsolatedDeclarations = await checkIsolatedDeclarations(options)
Expand All @@ -17,7 +16,6 @@ export async function generateDeclarationsFromFiles(options?: DtsGenerationConfi
}

if (options?.clean) {
// console.log('Cleaning output directory...')
await rm(options.outdir, { recursive: true, force: true })
}

Expand All @@ -29,10 +27,7 @@ export async function generateDeclarationsFromFiles(options?: DtsGenerationConfi
files = await getAllTypeScriptFiles(options?.root)
}

// console.log('Found the following TypeScript files:', files)

for (const file of files) {
// console.log(`Processing file: ${file}`)
const fileDeclarations = await extract(file)

if (fileDeclarations) {
Expand All @@ -45,15 +40,11 @@ export async function generateDeclarationsFromFiles(options?: DtsGenerationConfi

// Write the declarations without additional formatting
await writeToFile(outputPath, fileDeclarations)

// console.log(`Generated ${outputPath}`)
}
else {
console.warn(`No declarations extracted for ${file}`)
}
}

// console.log('Declaration file generation complete')
}
catch (error) {
console.error('Error generating declarations:', error)
Expand Down
52 changes: 0 additions & 52 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,58 +34,6 @@ export async function checkIsolatedDeclarations(options?: DtsGenerationConfig):
}
}

export function formatDeclarations(declarations: string): string {
const lines = declarations.split('\n')
const formattedLines = lines.map((line) => {
// Trim trailing spaces
line = line.trimEnd()

// Handle interface and type declarations
if (line.startsWith('export interface') || line.startsWith('export type')) {
const parts = line.split('{')
if (parts.length > 1) {
return `${parts[0].trim()} {${parts[1]}`
}
}

// Remove semicolons from the end of lines
if (line.endsWith(';')) {
line = line.slice(0, -1)
}

return line
})

// Join lines and ensure only one blank line between declarations
let result = formattedLines.join('\n')
result = result.replace(/\n{3,}/g, '\n\n')

// Format comments
result = result.replace(/\/\*\*\n([^*]*)(\n \*\/)/g, (match, content) => {
const formattedContent = content
.split('\n')
.map((line: string) => ` *${line.trim() ? ` ${line.trim()}` : ''}`)
.join('\n')
return `/**\n${formattedContent}\n */`
})

return `${result.trim()}\n`
}

export function formatComment(comment: string): string {
const lines = comment.split('\n')
return lines
.map((line, index) => {
if (index === 0)
return '/**'
if (index === lines.length - 1)
return ' */'
const trimmedLine = line.replace(/^\s*\*?\s?/, '').trim()
return ` * ${trimmedLine}`
})
.join('\n')
}

export function deepMerge<T extends object>(target: T, ...sources: Array<Partial<T>>): T {
if (!sources.length)
return target
Expand Down

0 comments on commit 3bd5594

Please sign in to comment.