From aa864a06e6d59f1a34205ba8ca4a6f9d404d898d Mon Sep 17 00:00:00 2001
From: wingdust <995315823@qq.com>
Date: Sun, 9 May 2021 22:58:00 +0800
Subject: [PATCH 1/3] feat: support posix path and param to tsconfig
---
src/cli.ts | 5 +++--
src/index.ts | 30 +++++++++++++++++++++++++-----
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/src/cli.ts b/src/cli.ts
index 1d3a228..aed29fc 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -7,9 +7,10 @@ const cli = cac('vue-dts-gen')
cli
.command('[...vue files]', 'Generate .d.ts for .vue files')
.option('--outDir
', 'Output directory')
- .action(async (input, flags: { outDir?: string }) => {
+ .option('--tsconfig ','specified tsconfig.json path')
+ .action(async (input, flags: { outDir?: string,tsconfig?:string }) => {
const { build } = await import('./')
- await build({ input, outDir: flags.outDir })
+ await build({ input, outDir: flags.outDir,tsconfig:flags.tsconfig })
})
cli.version(version)
diff --git a/src/index.ts b/src/index.ts
index 7e4d56e..dab8ce4 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,11 +1,12 @@
import path from 'path'
import fs from 'fs'
-import { Project, SourceFile } from 'ts-morph'
+import { Project, SourceFile, ts } from 'ts-morph'
import glob from 'fast-glob'
export type Options = {
input: string | string[]
outDir?: string
+ tsconfig?:string
}
let vueCompiler: typeof import('@vue/compiler-sfc')
@@ -25,11 +26,30 @@ const getVueCompiler = () => {
return vueCompiler
}
-export async function build({ input, outDir }: Options) {
+export async function build({ input, outDir,tsconfig }: Options) {
const vueCompiler = getVueCompiler()
- const tsConfigFilePath = fs.existsSync('tsconfig.json')
- ? 'tsconfig.json'
- : undefined
+ if (Array.isArray(input)) {
+ input = input.map((v)=>{
+ v=v.split(path.sep).join('/');
+ return v;
+ })
+ }
+ else{
+ input = input.split(path.sep).join('/')
+ }
+ let tsConfigFilePath:string|undefined
+ if (tsconfig){
+ tsConfigFilePath = tsconfig
+ if (!fs.existsSync(tsConfigFilePath)) {
+ tsConfigFilePath = undefined
+ }
+ tsConfigFilePath ? console.log('Using tsconfig:',tsConfigFilePath):console.log('tsconfig don\'t exist');
+ }
+ else {
+ tsConfigFilePath = fs.existsSync('tsconfig.json')
+ ? 'tsconfig.json'
+ : undefined
+ }
const project = new Project({
compilerOptions: {
allowJs: true,
From 86c7792a8a558e71529e35f804d7051fe6e3fd6a Mon Sep 17 00:00:00 2001
From: wingdust <995315823@qq.com>
Date: Sun, 9 May 2021 23:05:28 +0800
Subject: [PATCH 2/3] fixed: info helper fixed
---
src/cli.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cli.ts b/src/cli.ts
index aed29fc..cba75e8 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -7,7 +7,7 @@ const cli = cac('vue-dts-gen')
cli
.command('[...vue files]', 'Generate .d.ts for .vue files')
.option('--outDir ', 'Output directory')
- .option('--tsconfig ','specified tsconfig.json path')
+ .option('--tsconfig ','specified tsconfig.json with absolute path')
.action(async (input, flags: { outDir?: string,tsconfig?:string }) => {
const { build } = await import('./')
await build({ input, outDir: flags.outDir,tsconfig:flags.tsconfig })
From 9052924b55e8817170f097368d333a7413839720 Mon Sep 17 00:00:00 2001
From: wingdust <995315823@qq.com>
Date: Sun, 9 May 2021 23:09:54 +0800
Subject: [PATCH 3/3] fixed: remove unused import
---
src/index.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/index.ts b/src/index.ts
index dab8ce4..ee0f416 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,6 +1,6 @@
import path from 'path'
import fs from 'fs'
-import { Project, SourceFile, ts } from 'ts-morph'
+import { Project, SourceFile } from 'ts-morph'
import glob from 'fast-glob'
export type Options = {