Skip to content

Commit 19a451e

Browse files
committed
Fix broken link in case of multiple version of html document
- fix broken link in case of multiple version of html document - enhance getRenderData: sorting versions - version change: 3.0.0-next.0 > 3.0.0-next.1
1 parent 8500a1c commit 19a451e

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "erdia",
3-
"version": "3.0.0-next.0",
3+
"version": "3.0.0-next.1",
44
"description": "CLI to generate mermaid.js ER diagram using TypeORM entity",
55
"scripts": {
66
"clean": "rimraf dist artifact",
7-
"clean:dts": "rimraf dist/cjs/src dist/esm/src dist/src",
7+
"clean:dts": "rimraf dist/cjs/src dist/esm/src dist/src dist/examples",
88
"debug": "node -r ts-node/register -r tsconfig-paths/register --inspect-brk src/cli.ts",
99
"prettier": "prettier --write src/**/*.ts",
1010
"dev": "ts-node src/cli.ts",
@@ -18,8 +18,10 @@
1818
"build": "tsc --incremental",
1919
"prerollup:prod": "run-s clean lint",
2020
"rollup:prod": "rollup --config ./.configs/rollup.config.prod.ts --configPlugin typescript --bundleConfigAsCjs",
21+
"postrollup:prod": "run-s clean:dts",
2122
"prerollup:dev": "run-s clean lint",
2223
"rollup:dev": "rollup --config ./.configs/rollup.config.dev.ts --configPlugin typescript --bundleConfigAsCjs",
24+
"postrollup:dev": "run-s clean:dts",
2325
"prepub": "npm run rollup:prod",
2426
"pub": "NODE_ENV=production npm publish --registry http://localhost:8901 --force",
2527
"unpub": "npm unpublish erdia@latest --registry http://localhost:8901 --force",

src/creators/getRenderData.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type IRelationRecord from '#databases/interfaces/IRelationRecord';
77
import type IRenderData from '#databases/interfaces/IRenderData';
88
import type TDatabaseRecord from '#databases/interfaces/TDatabaseRecord';
99
import alasql from 'alasql';
10+
import { compareVersions } from 'compare-versions';
1011

1112
export default async function getRenderData(
1213
records: TDatabaseRecord[],
@@ -17,7 +18,11 @@ export default async function getRenderData(
1718
version: string;
1819
}[];
1920

20-
const versions = versionRows.map((version) => version.version);
21+
const unSortedVersions = versionRows.map((version) => version.version);
22+
const versions =
23+
option.versionFrom === 'timestamp'
24+
? unSortedVersions.sort((l, r) => r.localeCompare(l))
25+
: unSortedVersions.sort((l, r) => compareVersions(r, l));
2126

2227
const renderDatas = await Promise.all(
2328
versions.map(async (version) => {

src/template/html/document-toc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const documentToC = `<aside class="bd-aside sticky-xl-top text-body-secondary al
88
<ul class="list-unstyled">
99
<% version.entities.forEach((entity) => { %>
1010
<li class="my-2">
11-
<a class="anchor-link" href="#<%= entity.dbName %>-<%= entity.name %>" aria-label="Link to this section: <%= entity.dbName %>(<%= entity.name %>)">
11+
<a class="anchor-link" href="#<%= version.version.replaceAll('.', '-') %>-<%= entity.dbName %>-<%= entity.name %>" aria-label="Link to this section: <%= entity.dbName %>(<%= entity.name %>)">
1212
<%= entity.dbName %>
1313
</a>
1414
</li>

src/template/html/document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const htmlDocument = `<!DOCTYPE html>
6767
hide
6868
<% } %>">
6969
<h2><%= metadata.name %> <%= version.version %></h2>
70-
<%- include('${CE_TEMPLATE_NAME.HTML_TABLE}', { entities: version.entities, option, metadata }); %>
70+
<%- include('${CE_TEMPLATE_NAME.HTML_TABLE}', { version, option, metadata }); %>
7171
</section>
7272
<% }) %>
7373
</div>

src/template/html/table.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const htmlTable = `<div class="container-fluid">
2-
<% entities.forEach((entity) => { -%>
2+
<% version.entities.forEach((entity) => { -%>
33
<div class="container-fluid">
4-
<h2 id="<%= entity.dbName %>-<%= entity.name %>" class="title is-3">
4+
<h2 id="<%= version.version.replaceAll('.', '-') %>-<%= entity.dbName %>-<%= entity.name %>" class="title is-3">
55
<% if (entity.change === 'add') { -%>
66
<span class="badge text-bg-success">Add</span><%= -%>
77
<% } else if (entity.change === 'change') { -%>
@@ -11,7 +11,7 @@ const htmlTable = `<div class="container-fluid">
1111
<% } -%>
1212
<%= entity.dbName %>
1313
<small class="text-body-secondary">(<%= entity.name %>)</small>
14-
<a class="anchor-link" href="#<%= entity.dbName %>-<%= entity.name %>" aria-label="Link to this section: <%= entity.dbName %>(<%= entity.name %>)">#</a>
14+
<a class="anchor-link" href="#<%= version.version.replaceAll('.', '-') %>-<%= entity.dbName %>-<%= entity.name %>" aria-label="Link to this section: <%= entity.dbName %>(<%= entity.name %>)">#</a>
1515
</h2>
1616
1717
<table class="table table-striped table-hover">
@@ -38,12 +38,12 @@ const htmlTable = `<div class="container-fluid">
3838
<span class="badge text-bg-danger">Delete</span><%= -%>
3939
<% } -%>
4040
</td>
41-
<td id="<%= entity.dbName %>-<%= entity.name %>-<%= column.dbName %>">
42-
<a class="anchor-link" href="#<%= entity.dbName %>-<%= entity.name %>-<%= column.dbName %>" aria-label="Link to this section: <%= column.dbName %> in <%= entity.dbName %>(<%= entity.name %>)">#</a>
41+
<td id="<%= version.version.replaceAll('.', '-') %>-<%= entity.dbName %>-<%= entity.name %>-<%= column.dbName %>">
42+
<a class="anchor-link" href="#<%= version.version.replaceAll('.', '-') %>-<%= entity.dbName %>-<%= entity.name %>-<%= column.dbName %>" aria-label="Link to this section: <%= column.dbName %> in <%= entity.dbName %>(<%= entity.name %>)">#</a>
4343
<span><%= column.dbName %></span>
4444
</td>
45-
<td id="<%= entity.dbName %>-<%= entity.name %>-<%= column.name %>">
46-
<a class="anchor-link" href="#<%= entity.dbName %>-<%= entity.name %>-<%= column.name %>" aria-label="Link to this section: <%= column.name %> in <%= entity.dbName %>(<%= entity.name %>)">#</a>
45+
<td id="<%= version.version.replaceAll('.', '-') %>-<%= entity.dbName %>-<%= entity.name %>-<%= column.name %>">
46+
<a class="anchor-link" href="#<%= version.version.replaceAll('.', '-') %>-<%= entity.dbName %>-<%= entity.name %>-<%= column.name %>" aria-label="Link to this section: <%= column.name %> in <%= entity.dbName %>(<%= entity.name %>)">#</a>
4747
<span><%= column.name %></span>
4848
</td>
4949
<td><span><%= column.attributeKey.join(',') %></span></td>

0 commit comments

Comments
 (0)