-
-
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
a92e32b
commit caedf34
Showing
3 changed files
with
152 additions
and
134 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,32 @@ | ||
import { readdir, readFile } from 'node:fs/promises' | ||
import { extname, join } from 'node:path' | ||
import { config } from './config' | ||
import { type DtsGenerationConfig } from './types' | ||
|
||
export async function writeToFile(filePath: string, content: string): Promise<void> { | ||
await Bun.write(filePath, content) | ||
} | ||
|
||
export async function getAllTypeScriptFiles(directory?: string): Promise<string[]> { | ||
const dir = directory ?? config.root | ||
const entries = await readdir(dir, { withFileTypes: true }) | ||
|
||
const files = await Promise.all(entries.map((entry) => { | ||
const res = join(dir, entry.name) | ||
return entry.isDirectory() ? getAllTypeScriptFiles(res) : res | ||
})) | ||
|
||
return Array.prototype.concat(...files).filter(file => extname(file) === '.ts') | ||
} | ||
|
||
export async function checkIsolatedDeclarations(options: DtsGenerationConfig): Promise<boolean> { | ||
try { | ||
const tsconfigPath = options.tsconfigPath || join(options.root, 'tsconfig.json') | ||
const tsconfigContent = await readFile(tsconfigPath, 'utf-8') | ||
const tsconfig = JSON.parse(tsconfigContent) | ||
|
||
return tsconfig.compilerOptions?.isolatedDeclarations === true | ||
} catch (error) { | ||
return false | ||
} | ||
} |