Skip to content

Commit

Permalink
Update v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yiy0ung committed Oct 14, 2023
1 parent 91cfcde commit 228df00
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand All @@ -37,12 +35,16 @@ Options:
-o, --output <dir_path> Directory path where the erd document will be output (default: "./")
-t, --title <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
Expand All @@ -67,7 +69,7 @@ class User {}
class UserProfile {}

/**
* Only description on Blog chapter.
* Only erd on Blog chapter.
*
* @erd Blog
*/
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/writers/internal/sectionCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
24 changes: 19 additions & 5 deletions src/writers/markdown.writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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}\``;
Expand Down
30 changes: 15 additions & 15 deletions test/erd.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Community
# My Blog

- [Blog](#Blog)
- [Default](#Default)
- [User](#User)
- [Default](#Default)

## Blog
```mermaid
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -178,3 +165,16 @@ user {
>
> 삭제일이 있다는 것은 탈퇴를 의미한다.
## Default
```mermaid
erDiagram
empty_entity {
uuid id PK
}
```
### empty_entity
Empty Entity.

**Columns**
- `id`

0 comments on commit 228df00

Please sign in to comment.