imjuni / erdia

CLI to generate mermaid.js ER diagram using TypeORM entity
https://imjuni.github.io/erdia/
MIT License
31 stars 0 forks source link

Templating not working #63

Closed markim closed 5 months ago

markim commented 5 months ago

Hi, first, thanks for the awesome package :)

I am having issues getting the templating working.

I have an .erdiarc config file

It points to "template" as the template location.

I ejected the template, so it has the markdown, html, image folders.

I select to generate markdown with the CLI. It makes the markdown file.

I try to update the template file "template/markdown/document.eta" and add "test" at the top. I regenerate the markdown file, but it doesn't have test at the top. It looks like the templates are being ignored.

{
  // directory for output files
  "output": "docusaurus/src/pages",

  // typeorm dataSourcePath
  "data-source-path": "src/config/data-source-erd.ts",

  // type of generated document
  "components": ["table", "er"],

  // kind of document name
  // - db: database name from TypeORM
  // - app: application name from package.json
  "project-name": "db",

  // custom template file path. erdia are using [ETA](https://eta.js.org/) template engine
  "template-path": "template",

  // erdia entity database file path
  "database-path": "src/entity",

  // erdia entity database file path
  // "route-base-path": "",

  // document version using package.json version or timestamp
  "version-from": "package.json",

  // If the versionFrom option set file, read the file from this path
  "version-path": "undefined",

  // output format of generated documents
  // - html
  // - markdown
  // - pdf
  // - image
  "format": "md",

  // skip image file attachment in html document
  "skipImageInHtml": false,

  // mermaid.js plugin theme configuration
  // @url https://mermaid-js.github.io/mermaid/#/Setup?id=theme
  "theme": "dark"

  // prettier config path
  "prettier-config": ".prettierrc",

  // title tag content that inside of html document
  // "title": "set title tag content in html document",

  // ER diagram width, it will be set width css attribute
  // @format pdf, image
  // "width": "100%",

  // puppeteer viewport width
  // @format pdf, image
  // "viewport-width": 1280,

  // puppeteer viewport height
  // @format pdf, image
  // "viewport-height":  1440,

  // puppeteer config file path
  // @format pdf, image
  // "puppeteer-config-path": "set your puppeteer configuration file path",

  // Background color. Example: transparent, red, '#F0F0F0'. Optional. Default: white
  // @format pdf, image
  // "background-color": "#FFFFFF",

  // ER diagram export image file format
  // @format image
  // "image-format": "svg",
}
...
"scripts": {
    "erdia": "TS_NODE_PROJECT='./tsconfig.json' ts-node -r tsconfig-paths/register ./node_modules/.bin/erdia build -c .erdiarc",
...

Any ideas?

imjuni commented 5 months ago

@markim Thanks for the feedback, could you please provide a reproducible repo?

markim commented 5 months ago

No problem, here's the repo I was able to come up with. It uses the basic typeorm init script for an express server, then I added the erdia package.

https://github.com/markim/testerdiarepo

Special note to template/markdown/document.eta and erdiaoutput/test.md. Let me dive into your code real quick and see if anything pops out... It looks like it's just not loading the templates, always using the one found in (i'm guessing node_modules/erdia ? Thanks for your time.

imjuni commented 5 months ago

@markim Thanks for your participation. I've been looking at the code, and it looks like the problem is in the management of the template while bundling with esbuild. I'm working on fixing the bug, but it's taking some time due to issues related to improving the development environment, updating dependent library versions, etc. I'll let you know with a mention when it's done, thanks.

markim commented 5 months ago

Oh great! I tried taking a look but I would need more time to debug it properly, but it sounds like you got it triaged pretty well. I definitely know how it goes with the Rube Goldberg of problems like that, haha! Thanks for the fast reply, excited to hear back.

imjuni commented 5 months ago

@markim Hello

Thank you for your participant, I was fixed this problem 3.6.1. Use 3.6.1, Thank you :)

markim commented 5 months ago

Hi @imjuni thank you for your work!

I am still having troubles, however. I updated to the new package, deleted the old templates, deleted the old .erdiarc file, then ran erdia init. Some things I noticed:

1.) .erdiarc now uses absolute paths instead of relative ones. This probably should be relative paths so we can share erdia configs in code repositories.

e.g.

  // directory for output files
  "output": "/Users/mark/code/testerdiarepo/erdiaoutput",

2.) The template path is the root folder by default instead of ./templates (if I remember right from 3.5.0). So it adds all the template folders markdown html etc to the root location of package.json.

3.) Here is the error I get when trying to generate from the test repo with the new changes

███████╗██████╗ ██████╗ ██╗ █████╗ 
██╔════╝██╔══██╗██╔══██╗██║██╔══██╗
█████╗  ██████╔╝██║  ██║██║███████║
██╔══╝  ██╔══██╗██║  ██║██║██╔══██║
███████╗██║  ██║██████╔╝██║██║  ██║
╚══════╝╚═╝  ╚═╝╚═════╝ ╚═╝╚═╝  ╚═╝

ℹ connection initialize: "/Users/mark/code/testerdiarepo/src/data-source.ts"                                                                                                                                 9:27:29 AM
✔ connection initialized                                                                                                                                                                                     9:27:29 AM
ℹ version: 0.0.1                                                                                                                                                                                             9:27:29 AM
ℹ extract entities in test                                                                                                                                                                                   9:27:29 AM
✔ complete extraction                                                                                                                                                                                        9:27:29 AM
ℹ Database open and processing                                                                                                                                                                               9:27:29 AM
✔ Database open and processing completed                                                                                                                                                                     9:27:29 AM
ℹ output format: md                                                                                                                                                                                          9:27:29 AM

 ERROR  template: markdown-document { versions: [ { version: '0.0.1', entities: [Array], latest: true } ],                                                                                                    9:27:29 AM
  option:
   { _: [ 'build' ],
     c: '.erdiarc',
     config: '.erdiarc',
     output: '/Users/mark/code/testerdiarepo/erdiaoutput',
     o: '/Users/mark/code/testerdiarepo/erdiaoutput',
     'data-source-path': '/Users/mark/code/testerdiarepo/src/data-source.ts',
     d: '/Users/mark/code/testerdiarepo/src/data-source.ts',
     dataSourcePath: '/Users/mark/code/testerdiarepo/src/data-source.ts',
     components: [ 'table', 'er' ],
     t: [ 'table', 'er' ],
     'project-name': 'db',
     projectName: 'db',
     'template-path': '',
     templatePath: '',
     'database-path': '/Users/mark/code/testerdiarepo/src/entity',
     databasePath: '/Users/mark/code/testerdiarepo/src/entity',
     'version-from': 'package.json',
     versionFrom: 'package.json',
     format: 'md',
     skipImageInHtml: false,
     'skip-image-in-html': false,
     theme: 'default',
     'show-logo': false,
     showLogo: false,
     'version-path': undefined,
     versionPath: undefined,
     'route-base-path': undefined,
     routeBasePath: undefined,
     title: undefined,
     'prettier-config': undefined,
     prettierConfig: undefined,
     width: '100%',
     'viewport-width': 1280,
     viewportWidth: 1280,
     'viewport-height': 1440,
     viewportHeight: 1440,
     'image-format': 'svg',
     imageFormat: 'svg',
     'background-color': 'white',
     backgroundColor: 'white',
     '$0': 'node_modules/.bin/erdia' },
  metadata:
   { name: 'test',
     title: undefined,
     version: '0.0.1',
     createdAt: '2024-04-11T09:27:29-07:00',
     updatedAt: '2024-04-11T09:27:29-07:00' } }

 ERROR  Cannot read properties of undefined (reading 'forEach')                                                                                                                                               9:27:29 AM

  at Eta.eval (eval at compile (node_modules/eta/src/compile.ts:29:12), <anonymous>:17:13)
  at Eta.call [as render] (node_modules/eta/src/render.ts:58:26)
  at include (eval at compile (node_modules/eta/src/compile.ts:29:12), <anonymous>:4:40)
  at eval (eval at compile (node_modules/eta/src/compile.ts:29:12), <anonymous>:25:12)
  at Array.forEach (<anonymous>)
  at Eta.eval (eval at compile (node_modules/eta/src/compile.ts:29:12), <anonymous>:17:49)
  at Eta.render (node_modules/eta/src/render.ts:58:26)
  at TemplateRenderer.evaluate (node_modules/erdia/src/templates/TemplateRenderer.ts:26:34)
  at createMarkdown (node_modules/erdia/src/creators/createMarkdown.ts:18:38)
  at building (node_modules/erdia/src/modules/commands/building.ts:136:30)

 ERROR  Cannot read properties of undefined (reading 'forEach')                                                                                                                                               9:27:29 AM

  at Eta.eval (eval at compile (node_modules/eta/src/compile.ts:29:12), <anonymous>:17:13)
  at Eta.call [as render] (node_modules/eta/src/render.ts:58:26)
  at include (eval at compile (node_modules/eta/src/compile.ts:29:12), <anonymous>:4:40)
  at eval (eval at compile (node_modules/eta/src/compile.ts:29:12), <anonymous>:25:12)
  at Array.forEach (<anonymous>)
  at Eta.eval (eval at compile (node_modules/eta/src/compile.ts:29:12), <anonymous>:17:49)
  at Eta.render (node_modules/eta/src/render.ts:58:26)
  at TemplateRenderer.evaluate (node_modules/erdia/src/templates/TemplateRenderer.ts:26:34)
  at createMarkdown (node_modules/erdia/src/creators/createMarkdown.ts:18:38)
  at building (node_modules/erdia/src/modules/commands/building.ts:136:30)

I commited this all to the test repo https://github.com/markim/testerdiarepo for debugging.

Thanks, let me know what you think. Looks like something is undefined and the templating engine is trying to iterate over it...

imjuni commented 5 months ago

@markim Hi,

Thank you for participating. I fixed this issue in v3.7.0, thank you.

markim commented 5 months ago

@imjuni Thank you! I was out this weekend, but finally got a chance to test and it looks great.

Thanks again, have a great Summer.