-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename generateDts to generateDtsFile & move to generateDts…
…File.ts
- Loading branch information
Showing
5 changed files
with
59 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { CreateDtsOptions, createDts } from './createDts'; | ||
import { writeFile } from './writeFile'; | ||
|
||
type GenerateDtsFileOptions = Partial<{ | ||
fileName: string; | ||
output: (dts: string) => unknown; | ||
createDts: CreateDtsOptions; | ||
}>; | ||
|
||
type Parser = () => Promise<object> | object; | ||
|
||
export type GenerateDtsFileParams = { | ||
name: string; | ||
parser: Parser; | ||
directory: string; | ||
options?: GenerateDtsFileOptions; | ||
}; | ||
|
||
export const generateDtsFile = async ({ | ||
name, | ||
directory, | ||
parser, | ||
options = {}, | ||
}: GenerateDtsFileParams) => { | ||
const fileName = options.fileName || name; | ||
|
||
const parsed = await parser(); | ||
const dts = createDts(fileName, parsed, options.createDts); | ||
|
||
if (options.output) { | ||
options.output(dts); | ||
return; | ||
} | ||
|
||
await writeFile(`${directory}/${fileName}.d.ts`, dts); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1 @@ | ||
import { CreateDtsOptions, createDts } from './core/createDts'; | ||
import { writeFile } from './core/writeFile'; | ||
|
||
type GenerateDtsOptions = Partial<{ | ||
fileName: string; | ||
output: (dts: string) => unknown; | ||
createDts: CreateDtsOptions; | ||
}>; | ||
|
||
type Parser = () => Promise<object> | object; | ||
|
||
export type GenerateDtsParams = { | ||
name: string; | ||
parser: Parser; | ||
directory: string; | ||
options?: GenerateDtsOptions; | ||
}; | ||
|
||
export const generateDts = async ({ | ||
name, | ||
directory, | ||
parser, | ||
options = {}, | ||
}: GenerateDtsParams) => { | ||
const fileName = options.fileName || name; | ||
|
||
const parsed = await parser(); | ||
const dts = createDts(fileName, parsed, options.createDts); | ||
|
||
if (options.output) { | ||
options.output(dts); | ||
return; | ||
} | ||
|
||
await writeFile(`${directory}/${fileName}.d.ts`, dts); | ||
}; | ||
export { generateDtsFile } from './core/generateDtsFile'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters