From 53da13e043d3ddd256be275087950a7fc9b5ddde Mon Sep 17 00:00:00 2001 From: David Castro Date: Fri, 20 Dec 2019 16:51:24 -0800 Subject: [PATCH 1/4] Provide main entrypoint and generated typings to use the core as a library --- package.json | 2 ++ src/library.ts | 19 +++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/library.ts diff --git a/package.json b/package.json index d70caee..acdce5f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,8 @@ "version": "0.3.5", "description": "Generates models for TypeORM from existing databases.", "bin": "bin/typeorm-model-generator", + "main": "./dist/src/library.js", + "types": "./dist/src/library.d.ts", "scripts": { "start": "ts-node ./src/index.ts", "build": "npm run clean && tsc && ncp src/templates/ dist/src/templates/ && ncp package.json dist/package.json", diff --git a/src/library.ts b/src/library.ts new file mode 100644 index 0000000..cc700ea --- /dev/null +++ b/src/library.ts @@ -0,0 +1,19 @@ +import { Column } from "./models/Column"; +import { Entity } from "./models/Entity"; +import { Index } from "./models/Index"; +import { Relation } from "./models/Relation"; +import { RelationId } from "./models/RelationId"; + +// models exports - there may be a more succinct way to export default classes, +// but this was the only one I could find that seemed happy +export type Column = Column; +export type Entity = Entity; +export type Index = Index; +export type Relation = Relation; +export type RelationId = RelationId; + +export * from "./Engine"; +export * from "./IConnectionOptions"; +export * from "./IGenerationOptions"; +export * from "./NamingStrategy"; +export * from "./Utils"; diff --git a/tsconfig.json b/tsconfig.json index 93cff05..f141ecc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": true, - "declaration": false, + "declaration": true, "noFallthroughCasesInSwitch": true, "noImplicitReturns": true, "stripInternal": true, From 0d16f0e6fc01f8910426cdb42185e16e925b1234 Mon Sep 17 00:00:00 2001 From: David Castro Date: Sat, 21 Dec 2019 21:40:51 -0800 Subject: [PATCH 2/4] adjustment for entrypoint to import classes as different names to avoid collisions on export names --- src/library.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/library.ts b/src/library.ts index cc700ea..f054312 100644 --- a/src/library.ts +++ b/src/library.ts @@ -1,16 +1,16 @@ -import { Column } from "./models/Column"; -import { Entity } from "./models/Entity"; -import { Index } from "./models/Index"; -import { Relation } from "./models/Relation"; -import { RelationId } from "./models/RelationId"; +import { Column as ColumnModel } from "./models/Column"; +import { Entity as EntityModel } from "./models/Entity"; +import { Index as IndexModel } from "./models/Index"; +import { Relation as RelationModel } from "./models/Relation"; +import { RelationId as RelationIdModel } from "./models/RelationId"; // models exports - there may be a more succinct way to export default classes, // but this was the only one I could find that seemed happy -export type Column = Column; -export type Entity = Entity; -export type Index = Index; -export type Relation = Relation; -export type RelationId = RelationId; +export type Column = ColumnModel; +export type Entity = EntityModel; +export type Index = IndexModel; +export type Relation = RelationModel; +export type RelationId = RelationIdModel; export * from "./Engine"; export * from "./IConnectionOptions"; From 018200e78dc640b1c0dbe7cadc9aee159cc68755 Mon Sep 17 00:00:00 2001 From: David Castro Date: Sat, 21 Dec 2019 22:03:19 -0800 Subject: [PATCH 3/4] ignore generated type definitions from lint'ng --- .eslintignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintignore b/.eslintignore index 44ccaa3..2cb6327 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,4 +2,5 @@ test/integration/defaultValues/**/*.ts test/integration/entityTypes/**/*.ts test/integration/examples/**/*.ts -test/integration/github-issues/**/*.ts \ No newline at end of file +test/integration/github-issues/**/*.ts +dist/**/*.d.ts From 0e3d766e7383ce667d81028fd13cafd5a4b50a22 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sat, 28 Dec 2019 12:01:52 +0100 Subject: [PATCH 4/4] avoid name colisions in tomg exports --- src/library.ts | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/library.ts b/src/library.ts index f054312..a7d8584 100644 --- a/src/library.ts +++ b/src/library.ts @@ -1,19 +1,18 @@ -import { Column as ColumnModel } from "./models/Column"; -import { Entity as EntityModel } from "./models/Entity"; -import { Index as IndexModel } from "./models/Index"; -import { Relation as RelationModel } from "./models/Relation"; -import { RelationId as RelationIdModel } from "./models/RelationId"; +import * as Engine from "./Engine"; +import * as IConnectionOptions from "./IConnectionOptions"; +import * as IGenerationOptions from "./IGenerationOptions"; +import * as NamingStrategy from "./NamingStrategy"; +import * as Utils from "./Utils"; -// models exports - there may be a more succinct way to export default classes, -// but this was the only one I could find that seemed happy -export type Column = ColumnModel; -export type Entity = EntityModel; -export type Index = IndexModel; -export type Relation = RelationModel; -export type RelationId = RelationIdModel; - -export * from "./Engine"; -export * from "./IConnectionOptions"; -export * from "./IGenerationOptions"; -export * from "./NamingStrategy"; -export * from "./Utils"; +export { Column } from "./models/Column"; +export { Entity } from "./models/Entity"; +export { Index } from "./models/Index"; +export { Relation } from "./models/Relation"; +export { RelationId } from "./models/RelationId"; +export { + Engine, + IConnectionOptions, + IGenerationOptions, + NamingStrategy, + Utils +};