Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.

Feat:support \ to path splitting and add a parameter --tsconfig #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const cli = cac('vue-dts-gen')
cli
.command('[...vue files]', 'Generate .d.ts for .vue files')
.option('--outDir <dir>', 'Output directory')
.action(async (input, flags: { outDir?: string }) => {
.option('--tsconfig <dir>','specified tsconfig.json with absolute 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)
Expand Down
28 changes: 24 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import glob from 'fast-glob'
export type Options = {
input: string | string[]
outDir?: string
tsconfig?:string
}

let vueCompiler: typeof import('@vue/compiler-sfc')
Expand All @@ -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,
Expand Down