Skip to content

Commit

Permalink
feat: support export default config
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed May 11, 2020
1 parent 61b496d commit e8d8d73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demo/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateTypescriptOfFunctionParameter, TypeDeclaration } from '../dist/core'

export = (typeDeclarations: TypeDeclaration[]) => {
export default (typeDeclarations: TypeDeclaration[]): string => {
const result = []
for (const declaration of typeDeclarations) {
if (declaration.kind === 'function') {
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ async function executeCommandLine() {
if (configFilePath.endsWith('.ts')) {
require('ts-node/register/transpile-only')
}
const action = require(configFilePath) as (typeDeclarations: TypeDeclaration[], modules: typeof typescriptGenerator) => string
type Action = (typeDeclarations: TypeDeclaration[], modules: typeof typescriptGenerator) => string
// eslint-disable-next-line @typescript-eslint/no-var-requires
let action: Action & { default?: Action } = require(configFilePath)
if (action.default) {
action = action.default
}
const customContent = action(generator.declarations, typescriptGenerator)
fs.writeFileSync(customPath, customContent)
}
Expand Down

0 comments on commit e8d8d73

Please sign in to comment.