Skip to content

Commit f2fc599

Browse files
committed
chore: wip
1 parent 75233fa commit f2fc599

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ node_modules
1212
temp
1313
docs/.vitepress/cache
1414
storage
15+
fixtures/generated

bin/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { version } from '../package.json'
33

44
// import { generate } from '../src/generate'
55

6-
const cli = new CAC('dts')
6+
const cli = new CAC('dtsx')
77

88
cli
99
.command('generate', 'Start the Reverse Proxy Server')

dts.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
export default {
1+
import type { DtsGenerationOption } from './src/types'
2+
3+
const config: DtsGenerationOption = {
24
cwd: './',
35
root: './src',
6+
entrypoints: ['**/*.ts'],
47
outdir: './dist',
58
keepComments: true,
69
clean: true,
710

811
// bundle: true,
912
// minify: true,
1013
}
14+
15+
export default config

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const config: DtsGenerationConfig = (await loadConfig({
99
defaultConfig: {
1010
cwd: process.cwd(),
1111
root: './src',
12-
file: '**/*.ts',
12+
entrypoints: ['**/*.ts'],
1313
outdir: './dist',
1414
keepComments: true,
1515
clean: true,

src/generate.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { DtsGenerationConfig, DtsGenerationOption } from './types'
22
import { rm, mkdir } from 'node:fs/promises'
3-
import { join, relative, dirname } from 'node:path'
3+
import { join, relative, dirname, parse } from 'node:path'
44
import { config } from './config'
55
import { writeToFile, getAllTypeScriptFiles, checkIsolatedDeclarations } from './utils'
66
import { extractTypeFromSource } from './extract'
77
import { glob } from 'tinyglobby'
88

99
export async function generateDeclarationsFromFiles(options: DtsGenerationConfig): Promise<void> {
10+
// console.log('Generating declaration files...', options)
1011
try {
1112
// Check for isolatedModules setting
1213
const isIsolatedDeclarations = await checkIsolatedDeclarations(options)
@@ -21,8 +22,8 @@ export async function generateDeclarationsFromFiles(options: DtsGenerationConfig
2122
}
2223

2324
let files: string[]
24-
if (options.file) {
25-
files = await glob(options.file, { cwd: options.root ?? options.cwd, absolute: true })
25+
if (options.entrypoints) {
26+
files = await glob(options.entrypoints, { cwd: options.root ?? options.cwd, absolute: true })
2627
} else {
2728
files = await getAllTypeScriptFiles(options.root)
2829
}
@@ -35,7 +36,8 @@ export async function generateDeclarationsFromFiles(options: DtsGenerationConfig
3536

3637
if (fileDeclarations) {
3738
const relativePath = relative(options.root, file)
38-
const outputPath = join(options.outdir, relativePath.replace(/\.ts$/, '.d.ts'))
39+
const parsedPath = parse(relativePath)
40+
const outputPath = join(options.outdir, `${parsedPath.name}.d.ts`)
3941

4042
// Ensure the directory exists
4143
await mkdir(dirname(outputPath), { recursive: true })

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
export interface DtsGenerationConfig {
77
cwd: string
88
root: string
9-
file: string
9+
entrypoints: string[]
1010
outdir: string
1111
keepComments: boolean
1212
clean: boolean

test/dts.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ describe('dts-generation', () => {
1414
const example = 'example-1'
1515

1616
const config: DtsGenerationOption = {
17-
file: join(inputDir, `${example}.ts`),
17+
entrypoints: [join(inputDir, `${example}.ts`)],
1818
outdir: generatedDir,
19-
clean: true,
19+
clean: false,
2020
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
2121
}
2222

@@ -35,9 +35,9 @@ describe('dts-generation', () => {
3535
const example = 'example-2'
3636

3737
const config: DtsGenerationOption = {
38-
file: join(inputDir, `${example}.ts`),
38+
entrypoints: [join(inputDir, `${example}.ts`)],
3939
outdir: generatedDir,
40-
clean: true,
40+
clean: false,
4141
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
4242
}
4343

@@ -56,9 +56,9 @@ describe('dts-generation', () => {
5656
const example = 'example-3'
5757

5858
const config: DtsGenerationOption = {
59-
file: join(inputDir, `${example}.ts`),
59+
entrypoints: [join(inputDir, `${example}.ts`)],
6060
outdir: generatedDir,
61-
clean: true,
61+
clean: false,
6262
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
6363
}
6464

@@ -77,9 +77,9 @@ describe('dts-generation', () => {
7777
const example = 'example-4'
7878

7979
const config: DtsGenerationOption = {
80-
file: join(inputDir, `${example}.ts`),
80+
entrypoints: [join(inputDir, `${example}.ts`)],
8181
outdir: generatedDir,
82-
clean: true,
82+
clean: false,
8383
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
8484
}
8585

@@ -98,9 +98,9 @@ describe('dts-generation', () => {
9898
const example = 'example-5'
9999

100100
const config: DtsGenerationOption = {
101-
file: join(inputDir, `${example}.ts`),
101+
entrypoints: [join(inputDir, `${example}.ts`)],
102102
outdir: generatedDir,
103-
clean: true,
103+
clean: false,
104104
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
105105
}
106106

@@ -119,7 +119,6 @@ describe('dts-generation', () => {
119119
// Clean up generated files
120120
try {
121121
await rm(generatedDir, { recursive: true, force: true })
122-
console.log('Cleaned up generated files')
123122
} catch (error) {
124123
console.error('Error cleaning up generated files:', error)
125124
}

0 commit comments

Comments
 (0)