Skip to content

Commit 5c5d15d

Browse files
chore: wip
1 parent bd0fb7e commit 5c5d15d

File tree

8 files changed

+1088
-13
lines changed

8 files changed

+1088
-13
lines changed

packages/dtsx/README.md

Lines changed: 238 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
# dtsx
1010

11-
> A library that helps you generate TypeScript declaration files from your project. Given we do not know the user's input ever, we need to never hardcode based results based from our examples, always create a dynamic solution.
11+
> A blazing-fast TypeScript declaration file (.d.ts) generator with advanced features like incremental builds, watch mode, bundling, and IDE integration.
1212
1313
## Features
1414

1515
- ⚡ Extremely fast .d.ts generation
16+
- 🔄 Watch mode with incremental builds
17+
- 📦 Declaration bundling support
18+
- 🔌 Plugin system for custom transformations
19+
- 🧩 Monorepo/workspace support
20+
- 🛠️ IDE integration via LSP
1621
- ⚙️ Highly configurable
1722
- 🪶 Lightweight library
1823
- 🤖 Cross-platform binary
@@ -69,22 +74,41 @@ const options: DtsGenerationOptions = {
6974
await generate(options)
7075
```
7176

72-
_Available options:_
77+
### Configuration File
7378

7479
Library usage can also be configured using a `dts.config.ts` _(or `dts.config.js`)_ file which is automatically loaded when running the `./dtsx` _(or `bunx dtsx`)_ command. It is also loaded when the `generate` function is called, unless custom options are provided.
7580

7681
```ts
7782
// dts.config.ts (or dts.config.js)
83+
import { defineConfig } from '@stacksjs/dtsx'
7884

79-
export default {
85+
export default defineConfig({
8086
cwd: './',
8187
root: './src',
8288
entrypoints: ['**/*.ts'],
8389
outdir: './dist',
8490
keepComments: true,
8591
clean: true,
8692
verbose: true,
87-
}
93+
94+
// Advanced options
95+
watch: false, // Enable watch mode
96+
incremental: false, // Enable incremental builds
97+
parallel: false, // Enable parallel processing
98+
concurrency: 4, // Number of parallel workers
99+
100+
// Bundling
101+
bundle: false, // Bundle all declarations into one file
102+
bundleOutput: 'index.d.ts', // Output filename when bundling
103+
104+
// Output formatting
105+
prettier: false, // Use Prettier for formatting
106+
indentStyle: 'spaces', // 'spaces' or 'tabs'
107+
indentSize: 2, // Number of spaces
108+
109+
// Plugins
110+
plugins: [],
111+
})
88112
```
89113

90114
_You may also run:_
@@ -98,9 +122,11 @@ _You may also run:_
98122

99123
## CLI
100124

101-
The `dtsx` CLI provides a simple way to generate TypeScript declaration files from your project. Here's how to use it:
125+
The `dtsx` CLI provides a comprehensive set of commands for generating and managing TypeScript declaration files.
102126

103-
### Usage
127+
### Commands
128+
129+
#### Generate Declarations
104130

105131
Generate declaration files using the default options:
106132

@@ -111,29 +137,228 @@ dtsx generate
111137
_Or use custom options:_
112138

113139
```bash
114-
# Generate declarations for specific entry points:
140+
# Generate declarations for specific entry points
115141
dtsx generate --entrypoints src/index.ts,src/utils.ts --outdir dist/types
116142

117-
# Generate declarations with custom configuration:
143+
# Generate declarations with custom configuration
118144
dtsx generate --root ./lib --outdir ./types --clean
119145

120-
dtsx --help
121-
dtsx --version
146+
# Enable incremental builds
147+
dtsx generate --incremental
148+
149+
# Enable parallel processing
150+
dtsx generate --parallel --concurrency 8
151+
```
152+
153+
#### Watch Mode
154+
155+
Watch for file changes and automatically regenerate declarations:
156+
157+
```bash
158+
dtsx watch
159+
160+
# Watch with custom options
161+
dtsx watch --root ./src --outdir ./dist --debounce 300
162+
```
163+
164+
#### Bundle Declarations
165+
166+
Bundle multiple declaration files into a single file:
167+
168+
```bash
169+
dtsx bundle --outdir ./dist --output bundle.d.ts
170+
```
171+
172+
#### Workspace/Monorepo Support
173+
174+
Generate declarations for all packages in a monorepo:
175+
176+
```bash
177+
dtsx workspace
178+
179+
# Specify packages directory
180+
dtsx workspace --packages ./packages
181+
```
182+
183+
#### Type Checking
184+
185+
Run type checking with isolated declarations support:
186+
187+
```bash
188+
dtsx check
189+
190+
# Check specific files
191+
dtsx check --files "src/**/*.ts"
192+
```
193+
194+
#### Circular Dependency Detection
195+
196+
Detect circular dependencies in your TypeScript files:
197+
198+
```bash
199+
dtsx circular
200+
201+
# Output as JSON or DOT (Graphviz) format
202+
dtsx circular --format json
203+
dtsx circular --format dot
204+
```
205+
206+
#### Generate Documentation
207+
208+
Generate API documentation from your TypeScript files:
209+
210+
```bash
211+
dtsx docs
212+
213+
# Specify output format
214+
dtsx docs --format markdown
215+
dtsx docs --format html
216+
dtsx docs --format json
217+
```
218+
219+
#### Optimize Declarations
220+
221+
Optimize and tree-shake declaration files:
222+
223+
```bash
224+
dtsx optimize
225+
226+
# Optimize specific files
227+
dtsx optimize --files "dist/**/*.d.ts"
228+
```
229+
230+
#### Convert Types
231+
232+
Convert TypeScript types to different schema formats:
233+
234+
```bash
235+
dtsx convert --format zod
236+
dtsx convert --format json-schema
237+
dtsx convert --format valibot
238+
```
239+
240+
#### LSP Server
241+
242+
Start the Language Server Protocol server for IDE integration:
243+
244+
```bash
245+
dtsx lsp
246+
```
247+
248+
#### Read from Stdin
249+
250+
Accept TypeScript code from stdin:
251+
252+
```bash
253+
echo "export function foo(): string { return 'bar' }" | dtsx stdin
122254
```
123255

124-
_Available options:_
256+
### CLI Options
257+
258+
#### Global Options
125259

126260
- `--cwd <path>`: Set the current working directory _(default: current directory)_
261+
- `--verbose`: Enable verbose output _(default: false)_
262+
- `--help`: Show help information
263+
- `--version`: Show version number
264+
265+
#### Generate Options
266+
127267
- `--root <path>`: Specify the root directory of the project _(default: './src')_
128268
- `--entrypoints <files>`: Define entry point files _(comma-separated, default: '**/*.ts')_
129269
- `--outdir <path>`: Set the output directory for generated .d.ts files _(default: './dist')_
130270
- `--keep-comments`: Keep comments in generated .d.ts files _(default: true)_
131271
- `--clean`: Clean output directory before generation _(default: false)_
132272
- `--tsconfig <path>`: Specify the path to tsconfig.json _(default: 'tsconfig.json')_
133-
- `--verbose`: Enable verbose output _(default: false)_
273+
- `--incremental`: Enable incremental builds _(default: false)_
274+
- `--parallel`: Enable parallel processing _(default: false)_
275+
- `--concurrency <n>`: Number of parallel workers _(default: 4)_
276+
- `--dry-run`: Show what would be generated without writing files
277+
- `--diff`: Show differences from existing .d.ts files
278+
- `--validate`: Validate generated .d.ts against TypeScript compiler
279+
- `--stats`: Show generation statistics
280+
- `--progress`: Show progress during generation
281+
- `--output-format <format>`: Output format: 'text' or 'json' _(default: 'text')_
282+
283+
#### Watch Options
284+
285+
- `--debounce <ms>`: Debounce delay in milliseconds _(default: 100)_
286+
287+
#### Bundle Options
288+
289+
- `--output <file>`: Output filename _(default: 'index.d.ts')_
290+
- `--banner <text>`: Add banner comment to output
291+
- `--footer <text>`: Add footer comment to output
134292

135293
To learn more, head over to the [documentation](https://dtsx.stacksjs.org/).
136294

295+
## Build Tool Integration
296+
297+
dtsx provides plugins for popular build tools:
298+
299+
### Vite
300+
301+
```ts
302+
// vite.config.ts
303+
import { dts } from '@stacksjs/dtsx/vite'
304+
305+
export default {
306+
plugins: [dts()],
307+
}
308+
```
309+
310+
### esbuild
311+
312+
```ts
313+
// build.ts
314+
import { dtsx } from '@stacksjs/dtsx/esbuild'
315+
316+
await esbuild.build({
317+
plugins: [dtsx()],
318+
})
319+
```
320+
321+
### webpack
322+
323+
```ts
324+
// webpack.config.js
325+
const { DtsxWebpackPlugin } = require('@stacksjs/dtsx/webpack')
326+
327+
module.exports = {
328+
plugins: [new DtsxWebpackPlugin()],
329+
}
330+
```
331+
332+
### tsup
333+
334+
```ts
335+
// tsup.config.ts
336+
import { dtsxPlugin } from '@stacksjs/dtsx/tsup'
337+
338+
export default {
339+
plugins: [dtsxPlugin()],
340+
}
341+
```
342+
343+
### Bun
344+
345+
```ts
346+
// build.ts
347+
import { dts } from '@stacksjs/dtsx/bun'
348+
349+
await Bun.build({
350+
plugins: [dts()],
351+
})
352+
```
353+
354+
## Documentation
355+
356+
- [Architecture Guide](../../ARCHITECTURE.md) - How dtsx works internally
357+
- [Contributing Guide](../../CONTRIBUTING.md) - How to contribute to dtsx
358+
- [Performance Guide](../../PERFORMANCE.md) - Tips for optimizing large codebases
359+
- [Migration Guide](../../MIGRATION.md) - Migrating from other tools
360+
- [Troubleshooting](../../TROUBLESHOOTING.md) - Common issues and solutions
361+
137362
## Testing
138363

139364
```bash
@@ -160,7 +385,7 @@ For casual chit-chat with others using this package:
160385

161386
## Postcardware
162387

163-
Software that is free, but hopes for a postcard. We love receiving postcards from around the world showing where `dtsx` is being used! We showcase them on our website too.
388+
"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where `dtsx` is being used! We showcase them on our website too.
164389

165390
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎
166391

packages/dtsx/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@
2828
"types": "./dist/index.d.ts",
2929
"import": "./dist/src/index.js"
3030
},
31+
"./vite": {
32+
"types": "./dist/src/plugins/vite.d.ts",
33+
"import": "./dist/src/plugins/vite.js"
34+
},
35+
"./bun": {
36+
"types": "./dist/src/plugins/bun.d.ts",
37+
"import": "./dist/src/plugins/bun.js"
38+
},
39+
"./esbuild": {
40+
"types": "./dist/src/plugins/esbuild.d.ts",
41+
"import": "./dist/src/plugins/esbuild.js"
42+
},
43+
"./tsup": {
44+
"types": "./dist/src/plugins/tsup.d.ts",
45+
"import": "./dist/src/plugins/tsup.js"
46+
},
47+
"./webpack": {
48+
"types": "./dist/src/plugins/webpack.d.ts",
49+
"import": "./dist/src/plugins/webpack.js"
50+
},
51+
"./plugins": {
52+
"types": "./dist/src/plugins/index.d.ts",
53+
"import": "./dist/src/plugins/index.js"
54+
},
3155
"./*": {
3256
"types": "./dist/*.d.ts",
3357
"import": "./dist/*"

0 commit comments

Comments
 (0)