From c81df0a8b12ed95f4bc442ec485e559c348253dd Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 17 Oct 2024 23:00:15 +0200 Subject: [PATCH] chore: wip --- bin/cli.ts | 59 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/bin/cli.ts b/bin/cli.ts index 8b8d394..95c9274 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -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 ', '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 ', 'Current working directory', { default: defaultOptions.cwd }) + .option('--root ', 'Root directory of the project', { default: defaultOptions.root }) + .option('--entrypoints ', 'Entry point files (comma-separated)', { + default: defaultOptions.entrypoints?.join(','), + type: [String] + }) + .option('--outdir ', '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 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) })