diff --git a/src/index.ts b/src/index.ts index ab0e0d1..9491259 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ * Created by xiamx on 2016-08-10. */ -import { generateEnumType, generateTableTypes, generateTableInterface } from './typescript' +import { generateEnumType, generateTableTypes, generateTableInterface, generateExports } from './typescript' import { getDatabase, Database } from './schema' import Options, { OptionValues } from './options' import { processString } from 'typescript-formatter' @@ -71,6 +71,8 @@ export async function typescriptOfTable (db: Database|string, let tableTypes = await db.getTableTypes(table, schema, options) interfaces += generateTableTypes(table, tableTypes, options) interfaces += generateTableInterface(table, tableTypes, options) + interfaces += generateExports(table, tableTypes, options) + return interfaces } diff --git a/src/typescript.ts b/src/typescript.ts index 6a8a60e..539a99b 100644 --- a/src/typescript.ts +++ b/src/typescript.ts @@ -33,7 +33,7 @@ export function generateTableInterface (tableNameRaw: string, tableDefinition: T }) return ` - export interface ${normalizeName(tableName, options)} { + interface ${normalizeName(tableName, options)}Meta { ${members} } ` @@ -79,3 +79,19 @@ export function generateTableTypes (tableNameRaw: string, tableDefinition: Table } ` } + +export function generateExports (tableNameRaw: string, tableDefinition: TableDefinition, options: Options) { + const tableName = options.transformTypeName(tableNameRaw) + + if (options.isVerbose()) { + // If in verbose mode, simply rename