From 228df00018d580217db49551803123e1f390bbeb Mon Sep 17 00:00:00 2001 From: wlsdud2194 Date: Sat, 14 Oct 2023 16:05:21 +0900 Subject: [PATCH] Update v1.0.0 --- README.md | 16 +++++++------ package.json | 5 ++-- src/writers/internal/sectionCollector.ts | 2 +- src/writers/markdown.writer.ts | 24 +++++++++++++++---- test/erd.md | 30 ++++++++++++------------ 5 files changed, 47 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 32cddb5..1929955 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,9 @@ TypeORM markdown documents generator. -This package is inspired by [prisma-markdown](https://github.com/samchon/prisma-markdown), so it has similar usage. - - Mermaid ERD diagrams - Descriptions by JSDoc -- Separations by @namespace comments +- Separations by `@namespace` comments If you want to see how markdown document being generated, visit below examples: @@ -28,7 +26,7 @@ npm i -D typeorm-markdown ### Command Line Interface ``` -typeorm-markdown version 0.1.0 +typeorm-markdown version 1.0.0 Usage: typeorm-markdown [options] Options: @@ -37,12 +35,16 @@ Options: -o, --output Directory path where the erd document will be output (default: "./") -t, --title Title of the generated erd document (default: "ERD") --project <project_path> Use --project to explicitly specify the path to a tsconfig.json (default: "tsconfig.json") - -h, --help display help for command display help for command + -h, --help display help for command ``` ## Comment Tags -- `@namespace <name>`: Both ERD and markdown content +This package is inspired by [prisma-markdown](https://github.com/samchon/prisma-markdown), so it has similar usage. + +- `@namespace <name>` + - Both ERD and markdown content + - If `@namespace` is not set, it will be classified into the `Default` namespace. - `@erd <name>`: Only ERD - `@describe <name>`: Only markdown content, without ERD - `@hidden`: Neither ERD nor markdown content @@ -67,7 +69,7 @@ class User {} class UserProfile {} /** - * Only description on Blog chapter. + * Only erd on Blog chapter. * * @erd Blog */ diff --git a/package.json b/package.json index d28a19f..8045e92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typeorm-markdown", - "version": "0.1.5", + "version": "1.0.0", "license": "MIT", "author": "Jinyoung Lee", "description": "TypeORM Markdown documents generator including ERD diagrams and comment descriptions", @@ -9,7 +9,8 @@ "scripts": { "prepare": "ts-patch install -s", "build": "rimraf dist && tspc", - "test": "node ./dist/src/commands/typeorm-markdown.js --title \"Community\" -i \"test/**/*.entity.ts\" -o \"test/\" --project \"test/tsconfig.json\"" + "deploy": "npm run build && npm run test && npm publish", + "test": "node ./dist/src/commands/typeorm-markdown.js --title \"My Blog\" -i \"test/**/*.entity.ts\" -o \"test/\" --project \"test/tsconfig.json\"" }, "bin": { "typeorm-markdown": "./dist/src/commands/typeorm-markdown.js" diff --git a/src/writers/internal/sectionCollector.ts b/src/writers/internal/sectionCollector.ts index 0bfab5d..85343c6 100644 --- a/src/writers/internal/sectionCollector.ts +++ b/src/writers/internal/sectionCollector.ts @@ -2,7 +2,7 @@ import { ISectionCollection } from '@src/structures/ISectionCollection'; import { ITable } from '@src/structures/ITable'; export namespace SectionCollector { - const DEFAULT_NAMESPACE = 'Default'; + export const DEFAULT_NAMESPACE = 'Default'; const NAMESPACE_TAG: string = 'namespace'; const ERD_TAG: string = 'erd'; diff --git a/src/writers/markdown.writer.ts b/src/writers/markdown.writer.ts index 30c9580..54b02fc 100644 --- a/src/writers/markdown.writer.ts +++ b/src/writers/markdown.writer.ts @@ -18,11 +18,7 @@ export namespace MarkdownWriter { // TITLE markdown += `# ${config.title}\n\n`; - const sectionNames = Object.keys(collection).sort((a, b) => { - if (a < b) return -1; - if (a > b) return 1; - return 0; - }); + const sectionNames = getOrderedSectionNames(collection); // INDEX LIST sectionNames.map(sectionName => { @@ -51,6 +47,22 @@ export namespace MarkdownWriter { fs.writeFileSync(path.join(config.output, FILE_NAME), markdown); } + function getOrderedSectionNames(collection: ISectionCollection) { + const sectionNames = Object.keys(collection).sort((a, b) => { + if (a < b) return -1; + if (a > b) return 1; + return 0; + }); + + const defaultSectionIndex = sectionNames.indexOf(SectionCollector.DEFAULT_NAMESPACE); + if (defaultSectionIndex !== -1) { + sectionNames.splice(defaultSectionIndex, 1); + sectionNames.push(SectionCollector.DEFAULT_NAMESPACE); + } + + return sectionNames; + } + function writeERDiagram(tables: ITable[]): string { let schemaContent: string = ''; let relationContent: string = ''; @@ -100,6 +112,8 @@ export namespace MarkdownWriter { markdownContent += `### ${table.name}\n`; markdownContent += `${table.description}\n`; + if (table.database) markdownContent += `- Database: ${table.database}\n`; + markdownContent += `**Columns**\n`; table.columns.forEach(column => { let columnDesc = `- \`${column.name}\``; diff --git a/test/erd.md b/test/erd.md index 928912f..065328b 100644 --- a/test/erd.md +++ b/test/erd.md @@ -1,8 +1,8 @@ -# Community +# My Blog - [Blog](#Blog) -- [Default](#Default) - [User](#User) +- [Default](#Default) ## Blog ```mermaid @@ -137,19 +137,6 @@ BlogPost, BlogCategory N:M 테이블 - `updatedAt`: 수정일 - `deletedAt`: 삭제일 -## Default -```mermaid -erDiagram -empty_entity { - uuid id PK -} -``` -### empty_entity -Empty Entity. - -**Columns** -- `id` - ## User ```mermaid erDiagram @@ -178,3 +165,16 @@ user { > > 삭제일이 있다는 것은 탈퇴를 의미한다. +## Default +```mermaid +erDiagram +empty_entity { + uuid id PK +} +``` +### empty_entity +Empty Entity. + +**Columns** +- `id` +