Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 17, 2024
1 parent f2fc599 commit c81df0a
Showing 1 changed file with 49 additions and 10 deletions.
59 changes: 49 additions & 10 deletions bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
import { CAC } from '@stacksjs/cli'
import { version } from '../package.json'

// import { generate } from '../src/generate'
import { generate } from '../src/generate'
import type { DtsGenerationOption } from '../src/types'
import { resolve } from 'node:path'

const cli = new CAC('dtsx')

const defaultOptions: DtsGenerationOption = {
cwd: process.cwd(),
root: './src',
entrypoints: ['**/*.ts'],
outdir: './dist',
keepComments: true,
clean: false,
tsconfigPath: 'tsconfig.json',
}

cli
.command('generate', 'Start the Reverse Proxy Server')
.option('--from <from>', 'The URL to proxy from')
.option('--verbose', 'Enable verbose logging', { default: false })
.example('')
// .action(async (options?: DtsGenerationOption) => {
.action(async () => {
//
.command('generate', 'Generate TypeScript declaration files')
.option('--cwd <path>', 'Current working directory', { default: defaultOptions.cwd })
.option('--root <path>', 'Root directory of the project', { default: defaultOptions.root })
.option('--entrypoints <files>', 'Entry point files (comma-separated)', {
default: defaultOptions.entrypoints?.join(','),
type: [String]
})
.option('--outdir <path>', 'Output directory for generated .d.ts files', { default: defaultOptions.outdir })
.option('--keep-comments', 'Keep comments in generated .d.ts files', { default: defaultOptions.keepComments })
.option('--clean', 'Clean output directory before generation', { default: defaultOptions.clean })
.option('--tsconfig <path>', 'Path to tsconfig.json', { default: defaultOptions.tsconfigPath })
// .option('--verbose', 'Enable verbose logging', { default: false })
.example('dtsx generate')
.example('dtsx generate --entrypoints src/index.ts,src/utils.ts --outdir dist/types')
.action(async (options: DtsGenerationOption) => {
try {
const mergedOptions: DtsGenerationOption = {
...defaultOptions,
...options,
entrypoints: options.entrypoints ? options.entrypoints.split(',') : defaultOptions.entrypoints,
cwd: resolve(options.cwd || defaultOptions.cwd),
root: resolve(options.root || defaultOptions.root),
outdir: resolve(options.outdir || defaultOptions.outdir),
tsconfigPath: resolve(options.tsconfigPath || defaultOptions.tsconfigPath),
}

// if (options.verbose) {
// console.log('Using options:', mergedOptions)
// }

await generate(mergedOptions)
} catch (error) {
console.error('Error generating .d.ts files:', error)
process.exit(1)
}
})

cli.command('version', 'Show the version of the Reverse Proxy CLI').action(() => {
cli.command('version', 'Show the version of dtsx').action(() => {
console.log(version)
})

Expand Down

0 comments on commit c81df0a

Please sign in to comment.