@kubb/ts-codegen
Advanced tools
Comparing version 1.0.0-beta.9 to 1.0.0-beta.10
import ts from 'typescript'; | ||
import { TreeNodeOptions } from '@kubb/core'; | ||
import { TreeNodeOptions, File } from '@kubb/core'; | ||
@@ -52,10 +52,13 @@ declare const modifier: { | ||
}): ts.ImportDeclaration; | ||
declare function createExportDeclaration({ path }: { | ||
declare function createExportDeclaration({ path, asAlias, name }: { | ||
path: string; | ||
asAlias?: boolean; | ||
name?: string; | ||
}): ts.ExportDeclaration; | ||
declare function createEnumDeclaration({ name, typeName, enums }: { | ||
declare function createEnumDeclaration({ name, typeName, enums, type, }: { | ||
type: 'enum' | 'asConst'; | ||
name: string; | ||
typeName: string; | ||
enums: [key: string, value: string | number][]; | ||
}): (ts.TypeAliasDeclaration | ts.VariableStatement)[]; | ||
}): ts.EnumDeclaration[] | (ts.TypeAliasDeclaration | ts.VariableStatement)[]; | ||
declare function createIntersectionDeclaration({ nodes }: { | ||
@@ -67,4 +70,4 @@ nodes: ts.TypeNode[]; | ||
declare function writeIndexes(root: string, output: string, options: TreeNodeOptions): Promise<void>[] | undefined; | ||
declare function writeIndexes(root: string, output: string, options: TreeNodeOptions): File[] | undefined; | ||
export { appendJSDocToNode, createEnumDeclaration, createExportDeclaration, createImportDeclaration, createIndexSignature, createIntersectionDeclaration, createJSDoc, createParameter, createPropertySignature, createQuestionToken, createTypeAliasDeclaration, isValidIdentifier, modifier, print, questionToken, writeIndexes }; |
import { createRequire } from 'module'; | ||
import ts from 'typescript'; | ||
import pathParser from 'path'; | ||
import { TreeNode, write } from '@kubb/core'; | ||
import { TreeNode } from '@kubb/core'; | ||
@@ -108,6 +108,34 @@ createRequire(import.meta.url); | ||
} | ||
function createExportDeclaration({ path }) { | ||
function createExportDeclaration({ path, asAlias, name }) { | ||
if (asAlias) { | ||
return factory.createExportDeclaration( | ||
void 0, | ||
false, | ||
factory.createNamespaceExport(factory.createIdentifier(name)), | ||
factory.createStringLiteral(path), | ||
void 0 | ||
); | ||
} | ||
return factory.createExportDeclaration(void 0, false, void 0, factory.createStringLiteral(path), void 0); | ||
} | ||
function createEnumDeclaration({ name, typeName, enums }) { | ||
function createEnumDeclaration({ | ||
name, | ||
typeName, | ||
enums, | ||
type | ||
}) { | ||
if (type === "enum") { | ||
return [ | ||
factory.createEnumDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword)], | ||
factory.createIdentifier(typeName), | ||
enums.map(([key, value]) => { | ||
return factory.createEnumMember( | ||
factory.createStringLiteral(`${key}`), | ||
typeof value === "number" ? factory.createNumericLiteral(value) : factory.createStringLiteral(`${value}`) | ||
); | ||
}) | ||
) | ||
]; | ||
} | ||
return [ | ||
@@ -217,3 +245,3 @@ factory.createVariableStatement( | ||
const files = fileReducer([], tree); | ||
return files.map((file) => write(file.source, file.path)); | ||
return files; | ||
} | ||
@@ -220,0 +248,0 @@ |
{ | ||
"name": "@kubb/ts-codegen", | ||
"version": "1.0.0-beta.9", | ||
"version": "1.0.0-beta.10", | ||
"description": "Generator ts-codegen", | ||
@@ -45,3 +45,3 @@ "repository": { | ||
"dependencies": { | ||
"@kubb/core": "1.0.0-beta.9", | ||
"@kubb/core": "1.0.0-beta.10", | ||
"typescript": "^5.0.3" | ||
@@ -48,0 +48,0 @@ }, |
@@ -146,7 +146,42 @@ import ts from 'typescript' | ||
export function createExportDeclaration({ path }: { path: string }) { | ||
export function createExportDeclaration({ path, asAlias, name }: { path: string; asAlias?: boolean; name?: string }) { | ||
if (asAlias) { | ||
return factory.createExportDeclaration( | ||
undefined, | ||
false, | ||
factory.createNamespaceExport(factory.createIdentifier(name!)), | ||
factory.createStringLiteral(path), | ||
undefined | ||
) | ||
} | ||
return factory.createExportDeclaration(undefined, false, undefined, factory.createStringLiteral(path), undefined) | ||
} | ||
export function createEnumDeclaration({ name, typeName, enums }: { name: string; typeName: string; enums: [key: string, value: string | number][] }) { | ||
export function createEnumDeclaration({ | ||
name, | ||
typeName, | ||
enums, | ||
type, | ||
}: { | ||
type: 'enum' | 'asConst' | ||
name: string | ||
typeName: string | ||
enums: [key: string, value: string | number][] | ||
}) { | ||
if (type === 'enum') { | ||
return [ | ||
factory.createEnumDeclaration( | ||
[factory.createToken(ts.SyntaxKind.ExportKeyword)], | ||
factory.createIdentifier(typeName), | ||
enums.map(([key, value]) => { | ||
return factory.createEnumMember( | ||
factory.createStringLiteral(`${key}`), | ||
typeof value === 'number' ? factory.createNumericLiteral(value) : factory.createStringLiteral(`${value}`) | ||
) | ||
}) | ||
), | ||
] | ||
} | ||
return [ | ||
@@ -153,0 +188,0 @@ factory.createVariableStatement( |
import pathParser from 'path' | ||
import type { File, Path, PathMode, TreeNodeOptions } from '@kubb/core' | ||
import { TreeNode, write } from '@kubb/core' | ||
import { TreeNode } from '@kubb/core' | ||
@@ -76,3 +76,3 @@ import { createExportDeclaration } from './codegen' | ||
return files.map((file) => write(file.source, file.path)) | ||
return files | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
65900
863
+ Added@kubb/core@1.0.0-beta.10(transitive)
- Removed@kubb/core@1.0.0-beta.9(transitive)
Updated@kubb/core@1.0.0-beta.10