From e410bd2b9adc2bef9964dff38a4a784c5dd9944b Mon Sep 17 00:00:00 2001 From: ByungJoon Lee Date: Thu, 11 Apr 2024 23:26:51 +0900 Subject: [PATCH] feat(interface): change programming interface - change programming interface: `build`, `clean`, `eject`, `init` - enhance documentation: `README.md`, etc --- .prettierrc | 2 +- README.md | 101 +- assets/html/erdia.svg | 1 + assets/html/index.html | 8342 +++++++++++++++++++++++ assets/html/mermaid.html | 406 ++ docs/DETAIL_BUILD_COMMAND_OPTION.md | 60 + docs/DETAIL_CLEAN_COMMAND_OPTION.md | 24 + docs/DETAIL_EJECT_COMMAND_OPTION.md | 20 + docs/DETAIL_TYPESCRIPT.md | 86 + src/creators/createHtml.ts | 9 +- src/creators/createImageHtml.ts | 2 +- src/creators/createMarkdown.ts | 2 +- src/creators/createPdfHtml.ts | 5 +- src/creators/getRenderData.ts | 2 +- src/creators/writeToImage.ts | 7 +- src/creators/writeToPdf.ts | 11 +- src/databases/interfaces/IRenderData.ts | 2 +- src/modules/commands/building.ts | 7 +- src/modules/commands/ejecting.ts | 4 +- src/modules/commands/initializing.ts | 4 +- src/modules/loggers/Logger.ts | 4 +- src/modules/loggers/createLogger.ts | 4 +- src/typeorm/columns/getColumnRecord.ts | 2 +- src/typeorm/getDataSource.ts | 2 +- 24 files changed, 9058 insertions(+), 51 deletions(-) create mode 100644 assets/html/erdia.svg create mode 100644 assets/html/index.html create mode 100644 assets/html/mermaid.html create mode 100644 docs/DETAIL_BUILD_COMMAND_OPTION.md create mode 100644 docs/DETAIL_CLEAN_COMMAND_OPTION.md create mode 100644 docs/DETAIL_EJECT_COMMAND_OPTION.md create mode 100644 docs/DETAIL_TYPESCRIPT.md diff --git a/.prettierrc b/.prettierrc index 85d2346..a751380 100644 --- a/.prettierrc +++ b/.prettierrc @@ -7,7 +7,7 @@ "plugins": ["prettier-plugin-organize-imports"], "overrides": [ { - "files": "*.md", + "files": "**/*.md", "options": { "parser": "markdown" } diff --git a/README.md b/README.md index c045321..3386ba0 100644 --- a/README.md +++ b/README.md @@ -14,37 +14,38 @@ erdia is create ER Diagram and Entity schema specification using by TypeORM and Why `erdia` ? -`erdia` automatic generate DB entity specification, ER diagram. DB entity specification, ER diagram important document that are maintainence and develop process. But not so easy keep freshness. `erdia` help to easily keep freshness and easily generate beautiful document using [ETA](https://eta.js.org/) template engine. +`erdia` is a cli tool that allows you to automatically generate DB specifications and ER diagram documents using TypeORM. It is very hard to be diligent about updating DB specifications and ER diagrams whenever code and DB changes. `erdia` automatically generates DB statement and ER diagram documents using information provided by TypeORM whenever the code changes. By automatically generating documents using TypeORM code, you can maintain the freshness of your documents with minimal effort. Summary, 1. ER diagram generate using [mermaid.js](http://mermaid.js.org/) syntax. -1. Every document generate using [ETA](https://eta.js.org/) template engine -1. Use [TypeORM](https://typeorm.io/) +2. Every document generate using [ETA](https://eta.js.org/) template engine +3. Use [TypeORM](https://typeorm.io/) Automate your database ER diagram drawing! ## Table of Contents -- [Getting started](#getting-started) - [How it works?](#how-it-works) -- [Installation](#installation) +- [Getting started](#getting-started) + - [Installation](#installation) + - [Confuguration](#confuguration) + - [Generation](#generation) - [Usage](#usage) + - [Commands](#commands) + - [CLI Options](#cli-options) +- [Programming Interfaces](#programming-interfaces) + - [Interfaces](#interfaces) + - [Function Options](#function-options) - [Requirement](#requirement) - [Example](#example) - [Showcase](#showcase) - [Documents](#documents) - [Output Format](#output-format) - [Template](#template) -- [TypeScript and Re-Map Paths](#typescript-and-re-map-paths) - -## Getting started - -```sh -npm install erdia --save-dev -npx erdia init -npx erdia build -``` +- [TypeScript](#typescript) +- [License](#license) +- [References](#references) `erdia` support initialization command. And you execute `build` command. @@ -65,26 +66,64 @@ D-->G[pdf] D-->H[image] ``` -## Installation +## Getting started -installation +### Installation ```bash -npm i erdia --save-dev +npm install erdia --save-dev ``` -initialization +### Confuguration ```bash npx erdia init ``` -## Usage +### Generation -```sh +```bash erdia build -d [your dataSource path] -o dist/entity --format html ``` +## Usage + +### Commands + +`erdia` supports the `build`, `clean`, `init`, and `eject` commands. + +| Command | Description | +| ------- | ----------------------------------------------------------- | +| build | Builds the erdiagram document. | +| init | Generates a configuration file for creating erdiagrams. | +| eject | Generates a template document file for creating erdiagrams. | +| clean | Deletes the previously built erdiagram document. | + +### CLI Options + +- [build options](./docs/DETAIL_BUILD_COMMAND_OPTION.md#build-command-cli-options) +- init options +- [eject options](./docs/DETAIL_EJECT_COMMAND_OPTION.md#eject-command-cli-options) +- [clean options](./docs/DETAIL_CLEAN_COMMAND_OPTION.md#clean-command-cli-options) + +## Programming Interfaces + +### Interfaces + +| Command | Description | +| ------------ | ----------------------------------------------------------- | +| building | Builds the erdiagram document. | +| initializing | Generates a configuration file for creating erdiagrams. | +| ejecting | Generates a template document file for creating erdiagrams. | +| cleaning | Deletes the previously built erdiagram document. | + +### Function Options + +- [build options](./docs/DETAIL_BUILD_COMMAND_OPTION.md#building-function-options) +- init options +- [eject options](./docs/DETAIL_EJECT_COMMAND_OPTION.md#eject-function-options) +- [clean options](./docs/DETAIL_CLEAN_COMMAND_OPTION.md#clean-function-options) + ## Requirement - TypeORM 0.3.x @@ -97,6 +136,7 @@ erdia build -d [your dataSource path] -o dist/entity --format html ### Documents +- [ER diagram html format](./assets/html/index.html) - [ER diagram png image format](./assets/erdiagram.png) - [ER diagram & table pdf format](./assets/erdiagram.pdf) @@ -104,7 +144,7 @@ erdia build -d [your dataSource path] -o dist/entity --format html `erdia` support html, markdown, pdf, svg, png. Database entity specification table only support html, markdown, pdf format. -```sh +```bash # PDF document generate erdia build -d [your dataSourcePath] -o dist/entity --format pdf ``` @@ -119,10 +159,19 @@ npx erdia eject Detached template can change and every document customizable. The template can be found [here](https://github.com/imjuni/erdia/tree/master/src/template). -## TypeScript and Re-Map Paths +## TypeScript -```sh -TS_NODE_PROJECT="./tsconfig.json" ts-node -r tsconfig-paths/register ./node_modules/.bin/erdia er -d [your dataSource path] -``` +If you are using TypeScript, you must use `ts-node` or `tsx` to run `erdia`. This is because the TypeORM Entity file is written in TypeScript. + +- [ts-node](./docs/DETAIL_TYPESCRIPT.md#ts-node) +- [tsx](./docs/DETAIL_TYPESCRIPT.md#tsx) +- [scripts](./docs/DETAIL_TYPESCRIPT.md#using-programming-interfaces) + +## License + +This software is licensed under the [MIT](LICENSE). + +## References -`erdia` load dataSource file using TypeORM module. If you use module resolution need additional parameter need for successfully execution. You have to pass tsconfig-paths/register. See ts-node [paths and baseUrl](https://github.com/TypeStrong/ts-node#paths-and-baseurl) section +- [TypeORM](https://typeorm.io/) +- [ER Diagram](https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model) diff --git a/assets/html/erdia.svg b/assets/html/erdia.svg new file mode 100644 index 0000000..2dc4cb4 --- /dev/null +++ b/assets/html/erdia.svg @@ -0,0 +1 @@ +tbl_user(User)*intidPK*varchar(256)firstNameuser firstname*varchar(256)lastName*booleanisActiveline1<br/>line2<br/>line3intphotoFKtbl_photo(Photo)*intidPK*varchar(512)titlephoto title*varchar(2048)descriptionphoto description*intwidth*intheighttbl_license(License)*intidPK*varchar(512)titleUKorganization title*double-precisionweightsort weight*varchar(200)codeUKorganization code*varchar(2048)descriptionorganization description*datetimeexpireintuserFKtbl_organization(Organization)*intidPK*varchar(512)titleorganization title*varchar(2048)descriptionorganization description*simple-jsonsupportsorganization supports other organization*datetimeexpiretbl_mtm_license_organization(tbl_mtm_license_organization)*intlicense_idFK,PK*intorganization_idFK,PKphoto_iduser_idlicense_id,organization_idlicense_idorganization_id \ No newline at end of file diff --git a/assets/html/index.html b/assets/html/index.html new file mode 100644 index 0000000..8349615 --- /dev/null +++ b/assets/html/index.html @@ -0,0 +1,8342 @@ + + + + erdia entity specification + + + + + + + + + + + + +
+
+ +
+ +
+

erdia 3.6.0

+
+
+

+ tbl_user (User) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_user(User) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + first_name + + # + firstName + +
+
+ *varchar(256) +
+
+ +
+
+ utf8mb4 +
+
+ user firstname +
+
+ Update + + # + last_name + + # + lastName + +
+
+ *varchar(256) +
+
+ +
+
+ utf8mb4 +
+
+ +
+
+ Update + + # + is_active + + # + isActive + +
+
+ *boolean +
+
+ +
+
+ +
+
+ line1
line2
line3
+
+
+ # + photo_id + + # + photo + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+
+
+
+

+ tbl_photo (Photo) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_photo(Photo) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ photo title +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ photo description +
+
+ Update + + # + width + + # + width + +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + height + + # + height + +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+
+
+

+ tbl_license (License) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + + UK +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ organization title +
+
+ # + weight + + # + weight + + *double-precision + + + + sort weight +
+ Update + + # + code + + # + code + + UK +
+
+ *varchar(200) +
+
+ +
+
+ utf8mb4 +
+
+ organization code +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ organization description +
+
+ Update + + # + expire + + # + expire + +
+
+ *datetime +
+
+ +
+
+ +
+
+ +
+
+ # + user_id + + # + user + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + indices +
 Database NameProperty NameUniqueColumns
+ # + uk_license_code + + # + uk_license_code + + Unique + +
    +
  • code
  • +
  • title
  • +
+
+
+
+
+
+

+ tbl_organization + (Organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ organization title +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ organization description +
+
+ # + supports + + # + supports + + *simple-json + + + + organization supports other organization +
+ Update + + # + expire + + # + expire + +
+
+ *datetime +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + idx_organization_title + + # + idx_organization_title + +
    +
  • title
  • +
  • description
  • +
+
+
+
+
+
+

+ tbl_mtm_license_organization + (tbl_mtm_license_organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + license_id + + # + license_id + + PK + FK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + organization_id + + # + organization_id + + PK + FK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + IDX_5baaf0c98029c3d9aea96e3aaf + + # + IDX_5baaf0c98029c3d9aea96e3aaf + +
    +
  • license_id
  • +
+
+ # + IDX_8e1605d88a692638e20e0a4111 + + # + IDX_8e1605d88a692638e20e0a4111 + +
    +
  • organization_id
  • +
+
+
+
+
+
+
+
+

erdia 3.5.0

+
+
+

+ tbl_user (User) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_user(User) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + first_name + + # + firstName + +
+
+ *varchar(256) +
+
+ +
+
+ utf8mb4 +
+
+ user firstname +
+
+ Update + + # + last_name + + # + lastName + +
+
+ *varchar(256) +
+
+ +
+
+ utf8mb4 +
+
+ +
+
+ Update + + # + is_active + + # + isActive + +
+
+ *boolean +
+
+ +
+
+ +
+
+ line1
line2
line3
+
+
+ # + photo_id + + # + photo + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+
+
+
+

+ tbl_photo (Photo) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_photo(Photo) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ photo title +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ photo description +
+
+ Update + + # + width + + # + width + +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + height + + # + height + +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+
+
+

+ tbl_license (License) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + + UK +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ organization title +
+
+ # + weight + + # + weight + + *double-precision + + + + sort weight +
+ Update + + # + code + + # + code + + UK +
+
+ *varchar(200) +
+
+ +
+
+ utf8mb4 +
+
+ organization code +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ organization description +
+
+ Update + + # + expire + + # + expire + +
+
+ *datetime +
+
+ +
+
+ +
+
+ +
+
+ # + user_id + + # + user + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + indices +
 Database NameProperty NameUniqueColumns
+ # + uk_license_code + + # + uk_license_code + + Unique + +
    +
  • code
  • +
  • title
  • +
+
+
+
+
+
+

+ tbl_organization + (Organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ organization title +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ organization description +
+
+ # + supports + + # + supports + + *simple-json + + + + organization supports other organization +
+ Update + + # + expire + + # + expire + +
+
+ *datetime +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + idx_organization_title + + # + idx_organization_title + +
    +
  • title
  • +
  • description
  • +
+
+
+
+
+
+

+ tbl_mtm_license_organization + (tbl_mtm_license_organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + license_id + + # + license_id + + PK + FK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + organization_id + + # + organization_id + + PK + FK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + IDX_5baaf0c98029c3d9aea96e3aaf + + # + IDX_5baaf0c98029c3d9aea96e3aaf + +
    +
  • license_id
  • +
+
+ # + IDX_8e1605d88a692638e20e0a4111 + + # + IDX_8e1605d88a692638e20e0a4111 + +
    +
  • organization_id
  • +
+
+
+
+
+
+
+
+

erdia 3.4.1

+
+
+

+ tbl_user (User) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_user(User) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + first_name + + # + firstName + +
+
+ *varchar(256) +
+
+ +
+
+ utf8mb4 +
+
+ user firstname +
+
+ Update + + # + last_name + + # + lastName + +
+
+ *varchar(256) +
+
+ +
+
+ utf8mb4 +
+
+ +
+
+ Update + + # + is_active + + # + isActive + +
+
+ *boolean +
+
+ +
+
+ +
+
+ line1
line2
line3
+
+
+ # + photo_id + + # + photo + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+
+
+
+

+ tbl_photo (Photo) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_photo(Photo) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ photo title +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ photo description +
+
+ Update + + # + width + + # + width + +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + height + + # + height + +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+
+
+

+ tbl_license (License) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + + UK +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ organization title +
+
+ # + weight + + # + weight + + *double-precision + + + + sort weight +
+ Update + + # + code + + # + code + + UK +
+
+ *varchar(200) +
+
+ +
+
+ utf8mb4 +
+
+ organization code +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ organization description +
+
+ Update + + # + expire + + # + expire + +
+
+ *datetime +
+
+ +
+
+ +
+
+ +
+
+ # + user_id + + # + user + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + indices +
 Database NameProperty NameUniqueColumns
+ # + uk_license_code + + # + uk_license_code + + Unique + +
    +
  • code
  • +
  • title
  • +
+
+
+
+
+
+

+ tbl_organization + (Organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + +
+
+ *varchar(512) +
+
+ +
+
+ utf8mb4 +
+
+ organization title +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+
+ +
+
+ utf8mb4 +
+
+ organization description +
+
+ # + supports + + # + supports + + *simple-json + + + + organization supports other organization +
+ Update + + # + expire + + # + expire + +
+
+ *datetime +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + idx_organization_title + + # + idx_organization_title + +
    +
  • title
  • +
  • description
  • +
+
+
+
+
+
+

+ tbl_mtm_license_organization + (tbl_mtm_license_organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + license_id + + # + license_id + + PK + FK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+ Update + + # + organization_id + + # + organization_id + + PK + FK +
+
+ *int +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + IDX_5baaf0c98029c3d9aea96e3aaf + + # + IDX_5baaf0c98029c3d9aea96e3aaf + +
    +
  • license_id
  • +
+
+ # + IDX_8e1605d88a692638e20e0a4111 + + # + IDX_8e1605d88a692638e20e0a4111 + +
    +
  • organization_id
  • +
+
+
+
+
+
+
+
+

erdia 3.4.0

+
+
+

+ tbl_user (User) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_user(User) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+ int +
+ +
+
+ +
+
+ +
+
+ Update + + # + first_name + + # + firstName + +
+
+ *varchar(256) +
+ varchar(256) +
+ +
+
+ utf8mb4 +
+
+ user firstname +
+
+ Update + + # + last_name + + # + lastName + +
+
+ *varchar(256) +
+ varchar(256) +
+ +
+
+ utf8mb4 +
+
+ +
+
+ Update + + # + is_active + + # + isActive + +
+
+ *boolean +
+ boolean +
+ +
+
+ +
+
+ line1
line2
line3
+
+
+ # + photo_id + + # + photo + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+
+
+
+

+ tbl_photo (Photo) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_photo(Photo) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+ int +
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + +
+
+ *varchar(512) +
+ varchar(512) +
+ +
+
+ utf8mb4 +
+
+ photo title +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+ varchar(2048) +
+ +
+
+ utf8mb4 +
+
+ photo description +
+
+ Update + + # + width + + # + width + +
+
+ *int +
+ int +
+ +
+
+ +
+
+ +
+
+ Update + + # + height + + # + height + +
+
+ *int +
+ int +
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+
+
+

+ tbl_license (License) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+ int +
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + + UK +
+
+ *varchar(512) +
+ varchar(512) +
+ +
+
+ utf8mb4 +
+
+ organization title +
+
+ Add + + # + weight + + # + weight + + *double-precision + + + + sort weight +
+ Update + + # + code + + # + code + + UK +
+
+ *varchar(200) +
+ varchar(200) +
+ +
+
+ utf8mb4 +
+
+ organization code +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+ varchar(2048) +
+ +
+
+ utf8mb4 +
+
+ organization description +
+
+ Update + + # + expire + + # + expire + +
+
+ *datetime +
+ datetime +
+ +
+
+ +
+
+ +
+
+ # + user_id + + # + user + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + indices +
 Database NameProperty NameUniqueColumns
+ # + uk_license_code + + # + uk_license_code + + Unique + +
    +
  • code
  • +
  • title
  • +
+
+
+
+
+
+

+ tbl_organization + (Organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + id + + # + id + + PK +
+
+ *int +
+ int +
+ +
+
+ +
+
+ +
+
+ Update + + # + title + + # + title + +
+
+ *varchar(512) +
+ varchar(512) +
+ +
+
+ utf8mb4 +
+
+ organization title +
+
+ Update + + # + description + + # + description + +
+
+ *varchar(2048) +
+ varchar(2048) +
+ +
+
+ utf8mb4 +
+
+ organization description +
+
+ Add + + # + supports + + # + supports + + *simple-json + + + + organization supports other organization +
+ Update + + # + expire + + # + expire + +
+
+ *datetime +
+ datetime +
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + idx_organization_title + + # + idx_organization_title + +
    +
  • title
  • +
  • description
  • +
+
+
+
+
+
+

+ tbl_mtm_license_organization + (tbl_mtm_license_organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ Update + + # + license_id + + # + license_id + + PK + FK +
+
+ *int +
+ int +
+ +
+
+ +
+
+ +
+
+ Update + + # + organization_id + + # + organization_id + + PK + FK +
+
+ *int +
+ int +
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + IDX_5baaf0c98029c3d9aea96e3aaf + + # + IDX_5baaf0c98029c3d9aea96e3aaf + +
    +
  • license_id
  • +
+
+ # + IDX_8e1605d88a692638e20e0a4111 + + # + IDX_8e1605d88a692638e20e0a4111 + +
    +
  • organization_id
  • +
+
+
+
+
+
+
+
+

erdia 3.3.1

+
+
+

+ tbl_user (User) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_user(User) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ # + id + + # + id + + PK + + int + + + + +
+ # + first_name + + # + firstName + + varchar(256) + + utf8mb4 + + user firstname +
+ # + last_name + + # + lastName + + varchar(256) + + utf8mb4 + + +
+ # + is_active + + # + isActive + + boolean + + + + line1
line2
line3
+
+ # + photo_id + + # + photo + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+
+
+
+

+ tbl_photo (Photo) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_photo(Photo) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ # + id + + # + id + + PK + + int + + + + +
+ # + title + + # + title + + varchar(512) + + utf8mb4 + + photo title +
+ # + description + + # + description + + varchar(2048) + + utf8mb4 + + photo description +
+ # + width + + # + width + + int + + + + +
+ # + height + + # + height + + int + + + + +
+
+ +
+ +
+
+
+
+

+ tbl_license (License) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ # + id + + # + id + + PK + + int + + + + +
+ # + title + + # + title + + UK + + varchar(512) + + utf8mb4 + + organization title +
+ # + code + + # + code + + UK + + varchar(200) + + utf8mb4 + + organization code +
+ # + description + + # + description + + varchar(2048) + + utf8mb4 + + organization description +
+ # + expire + + # + expire + + datetime + + + + +
+ # + user_id + + # + user + + FK + + int + + NULLABLE + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_license(License) + indices +
 Database NameProperty NameUniqueColumns
+ # + uk_license_code + + # + uk_license_code + + Unique + +
    +
  • code
  • +
  • title
  • +
+
+
+
+
+
+

+ tbl_organization + (Organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ # + id + + # + id + + PK + + int + + + + +
+ # + title + + # + title + + varchar(512) + + utf8mb4 + + organization title +
+ # + description + + # + description + + varchar(2048) + + utf8mb4 + + organization description +
+ # + expire + + # + expire + + datetime + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_organization(Organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + idx_organization_title + + # + idx_organization_title + +
    +
  • title
  • +
  • description
  • +
+
+
+
+
+
+

+ tbl_mtm_license_organization + (tbl_mtm_license_organization) + # +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + columns +
 Database NameProperty NameAttributeTypeNullableCharsetComment
+ # + license_id + + # + license_id + + PK + FK + + int + + + + +
+ # + organization_id + + # + organization_id + + PK + FK + + int + + + + +
+ # + organization_id + + # + organization_id + + PK + FK + + int + + + + +
+ # + license_id + + # + license_id + + PK + FK + + int + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + tbl_mtm_license_organization(tbl_mtm_license_organization) + indices +
 Database NameProperty NameUniqueColumns
+ # + IDX_5baaf0c98029c3d9aea96e3aaf + + # + IDX_5baaf0c98029c3d9aea96e3aaf + +
    +
  • license_id
  • +
+
+ # + IDX_8e1605d88a692638e20e0a4111 + + # + IDX_8e1605d88a692638e20e0a4111 + +
    +
  • organization_id
  • +
+
+
+
+
+
+
+
+ + + + diff --git a/assets/html/mermaid.html b/assets/html/mermaid.html new file mode 100644 index 0000000..c0e6afb --- /dev/null +++ b/assets/html/mermaid.html @@ -0,0 +1,406 @@ + + + + erdia entity specification + + + + + + + + + + + + + +
+
+

+ ER Diagram + # +

+ +

Diagram

+
+
+                %%{init: {'theme':'dark'}}%%
+
+erDiagram
+
+"tbl_user(User)" {
+  *int id    PK    
+  *varchar(256) firstName      "user firstname"  
+  *varchar(256) lastName    
+  *boolean isActive      "line1
line2
line3" + int photo FK +} + + +"tbl_user(User)" |o -- o| "tbl_photo(Photo)": "photo_id" + +"tbl_photo(Photo)" { + *int id PK + *varchar(512) title "photo title" + *varchar(2048) description "photo description" + *int width + *int height +} + + + +"tbl_license(License)" { + *int id PK + *varchar(512) title UK "organization title" + *double-precision weight "sort weight" + *varchar(200) code UK "organization code" + *varchar(2048) description "organization description" + *datetime expire + int user FK +} + + +"tbl_license(License)" }o -- o| "tbl_user(User)": "user_id" +"tbl_license(License)" }o -- o{ "tbl_organization(Organization)": "license_id,organization_id" + +"tbl_organization(Organization)" { + *int id PK + *varchar(512) title "organization title" + *varchar(2048) description "organization description" + *simple-json supports "organization supports other organization" + *datetime expire +} + + + +"tbl_mtm_license_organization(tbl_mtm_license_organization)" { + *int license_id FK,PK + *int organization_id FK,PK +} + + +"tbl_mtm_license_organization(tbl_mtm_license_organization)" }| -- || "tbl_license(License)": "license_id" +"tbl_mtm_license_organization(tbl_mtm_license_organization)" }| -- || "tbl_organization(Organization)": "organization_id" + +
+
+ +

+ Image +

+
+ +
+ +
+

+ Mermaid source code + # +

+ + +
+ +
+
+ + + diff --git a/docs/DETAIL_BUILD_COMMAND_OPTION.md b/docs/DETAIL_BUILD_COMMAND_OPTION.md new file mode 100644 index 0000000..d9d14be --- /dev/null +++ b/docs/DETAIL_BUILD_COMMAND_OPTION.md @@ -0,0 +1,60 @@ +# Document Building + +## Table of Contents + +- [build command cli options](#build-command-cli-options) +- [building function options](#building-function-options) + +## build command cli options + +| name | required | default | format | description | +| ------------------ | -------- | ------------ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------- | +| config | | | html, markdown, pdf, image | Defines the path to the configuration file: `.erdiarc`. | +| output | required | | html, markdown, pdf, image | Defines the directory to output files. | +| data-source-path | required | | html, markdown, pdf, image | Defines the path to TypeORM data source file. | +| show-logo | | false | html, markdown, pdf, image | Defines whether to display the logo on the CLI interface. | +| components | | er, table | html, markdown, pdf | Defines the output component(s) to include in the built documents. | +| project-name | | package.json | html, markdown, pdf | Defines whether the project name will come from the `package.json` name field or the database name. | +| database-path | | erdiadb.json | html, markdown, pdf | Defines the directory to store `erdiadb.json`. | +| template-path | | | html, markdown, pdf, image | Defines the directory to ETA templates. `erdia` uses [ETA](https://eta.js.org/) template engine. | +| skip-image-in-html | | false | html | Enables skipping the attachment of the ER diagram image file to the HTML document. | +| format | | html | html, markdown, pdf, image | Defines the output format(s) for the built documents. | +| version-from | | | html, markdown, pdf, image | Defines whether the document version will come from the `package.json` version field, a specific file, or a timestamp. | +| version-path | | package.json | html, markdown, pdf, image | If the versionFrom option is set to `file`, specifies the path to read the file from. | +| theme | | dark | html, markdown, pdf, image | Defines the theme for the mermaid.js plugin. | +| route-base-path | | | html | Defines the route base path. Used as the base path for navbar anchor when generating HTML documents. | +| title | | | html | Defines the content of the HTML document title tag. | +| prettier-config | | | html, markdown, pdf, image | Defines the path to the prettier configuration file. | +| puppeteer-config | | | pdf, image | Defines the path to the puppeteer configuration file. | +| width | | 100% | pdf, image | Defines the ER diagram width. The width is defined by the HTML document CSS attribute width. | +| viewport-width | | 1280 | pdf, image | Defines the viewport width to puppeteer. The width is defined by the HTML document CSS attribute width. | +| viewport-height | | 1440 | pdf, image | Defines the viewport height to puppeteer. The height is defined by the HTML document CSS attribute height. | +| background-color | | | pdf, image | Defines the background color to HTML documents. Examples: transparent, red, '#F0F0F0'. | +| image-format | | svg | html, image | Defines the format to save image files in. Can be either 'png' or 'svg'. | + +## building function options + +| name | required | default | format | description | +| ---------------------- | -------- | ------------ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------- | +| option.output | required | | html, markdown, pdf, image | Defines the directory to output files. | +| option.dataSourcePath | required | | html, markdown, pdf, image | Defines the path to TypeORM data source file. | +| option.showLogo | | false | html, markdown, pdf, image | Defines whether to display the logo on the CLI interface. | +| option.components | | er, table | html, markdown, pdf | Defines the output component(s) to include in the built documents. | +| option.projectName | | package.json | html, markdown, pdf | Defines whether the project name will come from the `package.json` name field or the database name. | +| option.databasePath | | erdiadb.json | html, markdown, pdf | Defines the directory to store `erdiadb.json`. | +| option.templatePath | | | html, markdown, pdf, image | Defines the directory to ETA templates. `erdia` uses [ETA](https://eta.js.org/) template engine. | +| option.skipImageInHtml | | false | html | Enables skipping the attachment of the ER diagram image file to the HTML document. | +| option.format | | html | html, markdown, pdf, image | Defines the output format(s) for the built documents. | +| option.versionFrom | | | html, markdown, pdf, image | Defines whether the document version will come from the `package.json` version field, a specific file, or a timestamp. | +| option.versionPath | | package.json | html, markdown, pdf, image | If the versionFrom option is set to `file`, specifies the path to read the file from. | +| option.theme | | dark | html, markdown, pdf, image | Defines the theme for the mermaid.js plugin. | +| option.routeBasePath | | | html | Defines the route base path. Used as the base path for navbar anchor when generating HTML documents. | +| option.title | | | html | Defines the content of the HTML document title tag. | +| option.prettierConfig | | | html, markdown, pdf, image | Defines the path to the prettier configuration file. | +| option.puppeteerConfig | | | pdf, image | Defines the path to the puppeteer configuration file. | +| option.width | | 100% | pdf, image | Defines the ER diagram width. The width is defined by the HTML document CSS attribute width. | +| option.viewportWidth | | 1280 | pdf, image | Defines the viewport width to puppeteer. The width is defined by the HTML document CSS attribute width. | +| option.viewportHeight | | 1440 | pdf, image | Defines the viewport height to puppeteer. The height is defined by the HTML document CSS attribute height. | +| option.backgroundColor | | | pdf, image | Defines the background color to HTML documents. Examples: transparent, red, '#F0F0F0'. | +| option.imageFormat | | svg | html, image | Defines the format to save image files in. Can be either 'png' or 'svg'. | +| logging | | | | Display console message | diff --git a/docs/DETAIL_CLEAN_COMMAND_OPTION.md b/docs/DETAIL_CLEAN_COMMAND_OPTION.md new file mode 100644 index 0000000..4b83b39 --- /dev/null +++ b/docs/DETAIL_CLEAN_COMMAND_OPTION.md @@ -0,0 +1,24 @@ +# Document cleaning + +## Table of Contents + +- [clean command cli options](#clean-command-cli-options) +- [clean function options](#clean-function-options) + +## clean command cli options + +| Options | required | default | format | Description | +| ---------------- | -------- | ------- | -------------------------- | --------------------------------------------------------- | +| config | | | html, markdown, pdf, image | Defines the path to the configuration file: `.erdiarc`. | +| output | | | html, markdown, pdf, image | Defines the directory to output files. | +| data-source-path | required | | html, markdown, pdf, image | Defines the path to TypeORM data source file. | +| show-logo | | false | html, markdown, pdf, image | Defines whether to display the logo on the CLI interface. | + +## clean function options + +| Options | required | default | format | Description | +| -------------- | -------- | ------- | -------------------------- | --------------------------------------------------------- | +| config | | | html, markdown, pdf, image | Defines the path to the configuration file: `.erdiarc`. | +| output | | | html, markdown, pdf, image | Defines the directory to output files. | +| dataSourcePath | required | | html, markdown, pdf, image | Defines the path to TypeORM data source file. | +| showLogo | | false | html, markdown, pdf, image | Defines whether to display the logo on the CLI interface. | diff --git a/docs/DETAIL_EJECT_COMMAND_OPTION.md b/docs/DETAIL_EJECT_COMMAND_OPTION.md new file mode 100644 index 0000000..481d31f --- /dev/null +++ b/docs/DETAIL_EJECT_COMMAND_OPTION.md @@ -0,0 +1,20 @@ +# Template ejects + +## Table of Contents + +- [eject command cli options](#eject-command-cli-options) +- [eject function options](#eject-function-options) + +## eject command cli options + +| Options | required | default | format | Description | +| --------- | -------- | ------- | -------------------------- | --------------------------------------------------------- | +| output | required | | html, markdown, pdf, image | Defines the directory to output files. | +| show-logo | | false | html, markdown, pdf, image | Defines whether to display the logo on the CLI interface. | + +## eject function options + +| Options | required | default | format | Description | +| -------- | -------- | ------- | -------------------------- | --------------------------------------------------------- | +| output | required | | html, markdown, pdf, image | Defines the directory to output files. | +| showLogo | | false | html, markdown, pdf, image | Defines whether to display the logo on the CLI interface. | diff --git a/docs/DETAIL_TYPESCRIPT.md b/docs/DETAIL_TYPESCRIPT.md new file mode 100644 index 0000000..8a66b87 --- /dev/null +++ b/docs/DETAIL_TYPESCRIPT.md @@ -0,0 +1,86 @@ +# Run `Erdia` using TypeScript + +## Table of Contents + +- [ts-node](#ts-node) + - [ts-node without Re-Map Path](#ts-node-without-re-map-path) + - [ts-node with Re-Map Path](#ts-node-with-re-map-path) +- [tsx](#tsx) + - [tsx without Re-Map Path](#tsx-without-re-map-path) + - [tsx with Re-Map Path](#tsx-with-re-map-path) +- [Using Programming Interfaces](#using-programming-interfaces) + +## ts-node + +### ts-node without Re-Map Path + +If you are not using Re-Map Path, run it using `ts-node` as shown in the example below. + +```bash +npx ts-node node_modules/erdia/dist/cjs/cli.cjs build -d [your dataSource path] -o erdiagram +``` + +### ts-node with [Re-Map Path](https://github.com/TypeStrong/ts-node#paths-and-baseurl) + +If you are using Re-Map Path, run it using `ts-node` as shown in the example below. + +```bash +TS_NODE_PROJECT=tsconfig.json npx ts-node -r tsconfig-paths/register node_modules/erdia/dist/cjs/cli.cjs build -d [your dataSource path] -o erdiagram +``` + +## tsx + +### tsx without Re-Map Path + +If you are not using Re-Map Path, run it using `tsx` as shown in the example below. + +```bash +npx tsx node_modules/erdia/dist/cjs/cli.cjs build -d [your dataSource path] -o erdiagram +``` + +### tsx with [Re-Map Path](https://github.com/TypeStrong/ts-node#paths-and-baseurl) + +If you are using Re-Map Path, run it using `tsx` as shown in the example below. + +```bash +TS_NODE_PROJECT=tsconfig.json npx node -r tsx/cjs -r tsconfig-paths/register node_modules/erdia/dist/cjs/cli.cjs build -d [your dataSource path] -o erdiagram +``` + +## Using Programming Interfaces + +You can use ts-node or tsx, but you could use a simple script to extract the erdiagram. You can use this approach if you are using a monorepo or if your entities are scattered across multiple directories. + +```ts +// generate-erdia.ts +import { building, CE_ENTITY_VERSION_FROM, CE_OUTPUT_COMPONENT, CE_PROJECT_NAME_FROM } from 'erdia'; + +export async function handle() { + console.log('Start erdia'); + + await building( + { + config: '', + dataSourcePath: 'src/databases/data-sources/PetStoreMysqlDataSource.ts', + format: 'html', + output: 'dist/html', + components: [CE_OUTPUT_COMPONENT.TABLE, CE_OUTPUT_COMPONENT.ER], + projectName: CE_PROJECT_NAME_FROM.APPLICATION, + versionFrom: CE_ENTITY_VERSION_FROM.PACKAGE_JSON, + theme: 'dark', + }, + true, + ); +} + +handle().catch((caught) => { + const err = caught instanceof Error ? caught : new Error('unknown error raised'); + console.log(err.message); + console.log(err.stack); +}); +``` + +You can run the example script to generate an erdiagram. + +```bash +npx tsx generate-erdia.ts +``` diff --git a/src/creators/createHtml.ts b/src/creators/createHtml.ts index a753614..776c648 100644 --- a/src/creators/createHtml.ts +++ b/src/creators/createHtml.ts @@ -15,7 +15,7 @@ import pathe from 'pathe'; import type { AsyncReturnType } from 'type-fest'; async function getTables( - option: IBuildCommandOption, + option: Pick, renderData: AsyncReturnType, outputDir: string, ): Promise { @@ -37,7 +37,7 @@ async function getTables( } async function getDiagram( - option: IBuildCommandOption, + option: Pick, renderData: AsyncReturnType, outputDir: string, ): Promise { @@ -61,7 +61,10 @@ async function getDiagram( ]; } -export async function createHtml(option: IBuildCommandOption, renderData: AsyncReturnType) { +export async function createHtml( + option: Pick, + renderData: AsyncReturnType, +) { const outputDir = await getOutputDirectory(option, getCwd(process.env)); consola.info(`export component: ${option.components.join(', ')}`); diff --git a/src/creators/createImageHtml.ts b/src/creators/createImageHtml.ts index 21b2545..0d01ca6 100644 --- a/src/creators/createImageHtml.ts +++ b/src/creators/createImageHtml.ts @@ -13,7 +13,7 @@ import pathe from 'pathe'; import type { AsyncReturnType } from 'type-fest'; export async function createImageHtml( - option: IBuildCommandOption, + option: Pick, renderData: AsyncReturnType, ): Promise { const renderer = container.resolve(SymbolTemplateRenderer); diff --git a/src/creators/createMarkdown.ts b/src/creators/createMarkdown.ts index 9f6d8b9..e74c4b0 100644 --- a/src/creators/createMarkdown.ts +++ b/src/creators/createMarkdown.ts @@ -11,7 +11,7 @@ import pathe from 'pathe'; import type { AsyncReturnType } from 'type-fest'; export async function createMarkdown( - option: IBuildCommandOption, + option: Pick, renderData: AsyncReturnType, ): Promise { const renderer = container.resolve(SymbolTemplateRenderer); diff --git a/src/creators/createPdfHtml.ts b/src/creators/createPdfHtml.ts index 40c416b..5937dc0 100644 --- a/src/creators/createPdfHtml.ts +++ b/src/creators/createPdfHtml.ts @@ -12,7 +12,10 @@ import { randomUUID } from 'node:crypto'; import pathe from 'pathe'; import type { AsyncReturnType } from 'type-fest'; -export async function createPdfHtml(option: IBuildCommandOption, renderData: AsyncReturnType) { +export async function createPdfHtml( + option: Pick, + renderData: AsyncReturnType, +) { const renderer = container.resolve(SymbolTemplateRenderer); const rawHtml = await renderer.evaluate(CE_TEMPLATE_NAME.PDF_DOCUMENT, renderData); const prettiedHtml = await applyPrettier(rawHtml, 'html', option.prettierConfig); diff --git a/src/creators/getRenderData.ts b/src/creators/getRenderData.ts index ff32b89..016b73e 100644 --- a/src/creators/getRenderData.ts +++ b/src/creators/getRenderData.ts @@ -16,7 +16,7 @@ import { compareVersions } from 'compare-versions'; export async function getRenderData( records: TDatabaseRecord[], metadata: IRecordMetadata, - option: IBuildCommandOption, + option: Omit, ): Promise { const versionRows = (await alasql.promise('SELECT DISTINCT version FROM ?', [records])) as { version: string; diff --git a/src/creators/writeToImage.ts b/src/creators/writeToImage.ts index 73f30d5..9eb407d 100644 --- a/src/creators/writeToImage.ts +++ b/src/creators/writeToImage.ts @@ -14,14 +14,17 @@ import type { AsyncReturnType } from 'type-fest'; export async function writeToImage( document: IErdiaDocument, - option: IBuildCommandOption, + option: Pick< + IBuildCommandOption, + 'output' | 'components' | 'prettierConfig' | 'viewportWidth' | 'viewportHeight' | 'backgroundColor' | 'imageFormat' + >, renderData: AsyncReturnType, ) { let localBrowser: puppeteer.Browser | undefined; let localPage: puppeteer.Page | undefined; try { - const puppeteerConfig = await getPuppeteerConfig(option.puppeteerConfig); + const puppeteerConfig = await getPuppeteerConfig(option.prettierConfig); const browser = await puppeteer.launch({ ...puppeteerConfig, headless: true }); const page = await browser.newPage(); const puppeteerGotoOption: Parameters[1] = { diff --git a/src/creators/writeToPdf.ts b/src/creators/writeToPdf.ts index 721b239..be01e8e 100644 --- a/src/creators/writeToPdf.ts +++ b/src/creators/writeToPdf.ts @@ -12,7 +12,16 @@ import type { AsyncReturnType } from 'type-fest'; export async function writeToPdf( document: IErdiaDocument, - option: IBuildCommandOption, + option: Pick< + IBuildCommandOption, + | 'output' + | 'components' + | 'prettierConfig' + | 'puppeteerConfig' + | 'viewportWidth' + | 'viewportHeight' + | 'backgroundColor' + >, renderData: AsyncReturnType, ): Promise { let localBrowser: puppeteer.Browser | undefined; diff --git a/src/databases/interfaces/IRenderData.ts b/src/databases/interfaces/IRenderData.ts index 488b744..d0758cc 100644 --- a/src/databases/interfaces/IRenderData.ts +++ b/src/databases/interfaces/IRenderData.ts @@ -8,6 +8,6 @@ export interface IRenderData { latest: boolean; entities: IEntityWithColumnAndRelationAndIndex[]; }[]; - option: IBuildCommandOption; + option: Omit; metadata: IRecordMetadata; } diff --git a/src/modules/commands/building.ts b/src/modules/commands/building.ts index 7ff018c..0add62b 100644 --- a/src/modules/commands/building.ts +++ b/src/modules/commands/building.ts @@ -39,10 +39,11 @@ import fastSafeStringify from 'fast-safe-stringify'; import { isError, isFalse } from 'my-easy-fp'; import { isFail, isPass, type IFail, type IPass } from 'my-only-either'; import fs from 'node:fs'; +import type { SetOptional } from 'type-fest'; import type { DataSource } from 'typeorm'; -export async function building(option: IBuildCommandOption) { - createLogger(); +export async function building(option: SetOptional, logging?: boolean) { + createLogger(logging); const logger = container.resolve(SymbolLogger); try { @@ -107,7 +108,7 @@ export async function building(option: IBuildCommandOption) { logger.info(`output format: ${option.format}`); if (option.format === CE_OUTPUT_FORMAT.HTML) { - const imageOption: IBuildCommandOption = { + const imageOption: SetOptional = { ...option, format: CE_OUTPUT_FORMAT.IMAGE, imageFormat: 'svg', diff --git a/src/modules/commands/ejecting.ts b/src/modules/commands/ejecting.ts index ac20d92..56fdde9 100644 --- a/src/modules/commands/ejecting.ts +++ b/src/modules/commands/ejecting.ts @@ -16,8 +16,8 @@ import { getDirname, startSepRemove } from 'my-node-fp'; import fs from 'node:fs'; import pathe from 'pathe'; -export async function ejecting(option: Pick) { - createLogger(); +export async function ejecting(option: Pick, logging?: boolean) { + createLogger(logging); const logger = container.resolve(SymbolLogger); try { diff --git a/src/modules/commands/initializing.ts b/src/modules/commands/initializing.ts index 676855f..2aef52f 100644 --- a/src/modules/commands/initializing.ts +++ b/src/modules/commands/initializing.ts @@ -12,8 +12,8 @@ import { asValue } from 'awilix'; import fs from 'fs'; import { isError } from 'my-easy-fp'; -export async function initializing() { - createLogger(); +export async function initializing(logging?: boolean) { + createLogger(logging); const logger = container.resolve(SymbolLogger); try { diff --git a/src/modules/loggers/Logger.ts b/src/modules/loggers/Logger.ts index b7b3e3a..44cb150 100644 --- a/src/modules/loggers/Logger.ts +++ b/src/modules/loggers/Logger.ts @@ -11,8 +11,8 @@ export class Logger { this.#enable = value; } - constructor() { - this.#enable = false; + constructor(enable?: boolean) { + this.#enable = enable ?? false; } get level() { diff --git a/src/modules/loggers/createLogger.ts b/src/modules/loggers/createLogger.ts index 2f43e33..09275d5 100644 --- a/src/modules/loggers/createLogger.ts +++ b/src/modules/loggers/createLogger.ts @@ -3,9 +3,9 @@ import { SymbolLogger } from '#/modules/containers/keys/SymbolLogger'; import { Logger } from '#/modules/loggers/Logger'; import { asValue } from 'awilix'; -export function createLogger() { +export function createLogger(enable?: boolean) { if (!container.hasRegistration(SymbolLogger)) { - const logger = new Logger(); + const logger = new Logger(enable ?? false); container.register(SymbolLogger, asValue(logger)); } } diff --git a/src/typeorm/columns/getColumnRecord.ts b/src/typeorm/columns/getColumnRecord.ts index 7b714e5..8a32146 100644 --- a/src/typeorm/columns/getColumnRecord.ts +++ b/src/typeorm/columns/getColumnRecord.ts @@ -13,7 +13,7 @@ import type { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata'; export function getColumnRecord( columnMetadata: ColumnMetadata, - option: IBuildCommandOption, + option: Pick, metadata: IRecordMetadata, indices: IIndexRecord[], ): IColumnRecord { diff --git a/src/typeorm/getDataSource.ts b/src/typeorm/getDataSource.ts index 905fc96..fc99771 100644 --- a/src/typeorm/getDataSource.ts +++ b/src/typeorm/getDataSource.ts @@ -5,7 +5,7 @@ import { exists } from 'my-node-fp'; import pathe from 'pathe'; import { type DataSource } from 'typeorm'; -export async function getDataSource(options: ICommonOption): Promise { +export async function getDataSource(options: Pick): Promise { const dataSourcePath = pathe.resolve(options.dataSourcePath); if (isFalse(await exists(dataSourcePath))) {