drizzle-docs-generator 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # drizzle-docs-generator
2
2
 
3
- [![npm version](https://badge.fury.io/js/drizzle-docs-generator.svg)](https://www.npmjs.com/package/drizzle-docs-generator)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
3
+ [![NPM](https://nodei.co/npm/drizzle-docs-generator.svg?style=shields&data=v,d&color=brightgreen)](https://nodei.co/npm/drizzle-docs-generator/)
5
4
 
6
- Drizzle ORM スキーマから DBML を生成する CLI。JSDoc コメントを Note 句として出力できる。
5
+ Drizzle ORM スキーマから DBML Markdown ドキュメントを生成する CLI。JSDoc コメントを Note 句として出力できる。
7
6
 
8
7
  **機能:**
9
8
 
@@ -18,10 +17,26 @@ Drizzle ORM スキーマから DBML を生成する CLI。JSDoc コメントを
18
17
 
19
18
  ## インストール
20
19
 
20
+ ### ローカルインストール(推奨)
21
+
22
+ ```bash
23
+ # 開発依存関係としてインストール
24
+ npm install --save-dev drizzle-docs-generator
25
+ # or
26
+ pnpm add -D drizzle-docs-generator
27
+
28
+ # npx で実行
29
+ npx drizzle-docs generate ./src/db/schema.ts -d postgresql
30
+ ```
31
+
32
+ ### グローバルインストール
33
+
21
34
  ```bash
22
35
  npm install -g drizzle-docs-generator
23
36
  # or
24
37
  pnpm add -g drizzle-docs-generator
38
+
39
+ drizzle-docs generate ./src/db/schema.ts -d postgresql
25
40
  ```
26
41
 
27
42
  ## 使い方
@@ -38,9 +53,6 @@ drizzle-docs generate ./src/db/schema/ -d postgresql
38
53
  # ファイル出力
39
54
  drizzle-docs generate ./src/db/schema.ts -d postgresql -o schema.dbml
40
55
 
41
- # relations() を使う
42
- drizzle-docs generate ./src/db/schema.ts -d postgresql -r
43
-
44
56
  # watch モード
45
57
  drizzle-docs generate ./src/db/schema.ts -d postgresql -w
46
58
  ```
@@ -65,12 +77,20 @@ drizzle-docs generate ./src/db/schema.ts -d postgresql -f markdown --no-er-diagr
65
77
  | `-o, --output <path>` | 出力ファイルまたはディレクトリパス |
66
78
  | `-d, --dialect <dialect>` | DB 種別: `postgresql` (デフォルト), `mysql`, `sqlite` |
67
79
  | `-f, --format <format>` | 出力形式: `dbml` (デフォルト), `markdown` |
68
- | `-r, --relational` | relations() 定義からリファレンスを生成 |
69
80
  | `-w, --watch` | ファイル変更時に自動再生成 |
70
81
  | `--single-file` | Markdown を単一ファイルで出力 (markdown のみ) |
71
82
  | `--no-er-diagram` | ER 図を Markdown 出力から除外 |
72
83
  | `--force` | 確認なしで既存ファイルを上書き |
73
84
 
85
+ ### リレーション検出
86
+
87
+ リレーションはスキーマから**自動検出**されます:
88
+
89
+ - **v1 API** (`defineRelations()`): スキーマオブジェクトから実行時に検出
90
+ - **v0 API** (`relations()`): ソースファイルを解析して検出
91
+
92
+ 設定不要 - リレーション定義があれば使用し、なければ外部キー制約にフォールバックします。
93
+
74
94
  ## 例
75
95
 
76
96
  ```typescript
@@ -111,38 +131,6 @@ Table users {
111
131
 
112
132
  詳細なサンプル出力は [examples/](./examples/) を参照してください。
113
133
 
114
- ## API
115
-
116
- ```typescript
117
- import { pgGenerate } from "drizzle-docs-generator";
118
- import * as schema from "./schema";
119
-
120
- const dbml = pgGenerate({
121
- schema,
122
- source: "./schema.ts",
123
- relational: false,
124
- out: "./output.dbml", // optional
125
- });
126
- ```
127
-
128
- `mysqlGenerate`, `sqliteGenerate` も同様。
129
-
130
- ## 動作環境
131
-
132
- - Node.js >= 24
133
- - Drizzle ORM v1 beta (1.0.0-beta.10+)
134
- - ES Modules (ESM): プロジェクトで ESM を使用していること (`package.json` に `"type": "module"`)
135
-
136
- ## 仕組み
137
-
138
- このツールは [tsx](https://github.com/privatenumber/tsx) を使用してスキーマファイルを読み込むため:
139
-
140
- ✅ **拡張子なしのインポートが動作**: `import { users } from './users'`
141
- ✅ **TypeScript ファイルを直接読み込み**: コンパイル不要
142
- ✅ **ディレクトリインポート**: ディレクトリ内のすべてのスキーマファイルを自動読み込み
143
-
144
- スキーマファイルでは、ファイル拡張子を気にせず標準的な TypeScript のモジュール解決を使用できます。
145
-
146
134
  ## License
147
135
 
148
136
  MIT
package/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # drizzle-docs-generator
2
2
 
3
- [![npm version](https://badge.fury.io/js/drizzle-docs-generator.svg)](https://www.npmjs.com/package/drizzle-docs-generator)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
3
+ [![NPM](https://nodei.co/npm/drizzle-docs-generator.svg?style=shields&data=v,d&color=brightgreen)](https://nodei.co/npm/drizzle-docs-generator/)
5
4
 
6
- CLI tool to generate DBML from Drizzle ORM schemas. Extracts JSDoc comments and outputs them as Note clauses.
5
+ CLI tool to generate DBML and Markdown documentation from Drizzle ORM schemas. Extracts JSDoc comments and outputs them as Note clauses.
7
6
 
8
7
  **Features:**
9
8
 
@@ -18,10 +17,26 @@ CLI tool to generate DBML from Drizzle ORM schemas. Extracts JSDoc comments and
18
17
 
19
18
  ## Install
20
19
 
20
+ ### Local Install (recommended)
21
+
22
+ ```bash
23
+ # As a dev dependency
24
+ npm install --save-dev drizzle-docs-generator
25
+ # or
26
+ pnpm add -D drizzle-docs-generator
27
+
28
+ # Then use with npx
29
+ npx drizzle-docs generate ./src/db/schema.ts -d postgresql
30
+ ```
31
+
32
+ ### Global Install
33
+
21
34
  ```bash
22
35
  npm install -g drizzle-docs-generator
23
36
  # or
24
37
  pnpm add -g drizzle-docs-generator
38
+
39
+ drizzle-docs generate ./src/db/schema.ts -d postgresql
25
40
  ```
26
41
 
27
42
  ## Usage
@@ -38,9 +53,6 @@ drizzle-docs generate ./src/db/schema/ -d postgresql
38
53
  # Output to file
39
54
  drizzle-docs generate ./src/db/schema.ts -d postgresql -o schema.dbml
40
55
 
41
- # Use relations() definitions
42
- drizzle-docs generate ./src/db/schema.ts -d postgresql -r
43
-
44
56
  # Watch mode
45
57
  drizzle-docs generate ./src/db/schema.ts -d postgresql -w
46
58
  ```
@@ -65,12 +77,20 @@ drizzle-docs generate ./src/db/schema.ts -d postgresql -f markdown --no-er-diagr
65
77
  | `-o, --output <path>` | Output file or directory path |
66
78
  | `-d, --dialect <dialect>` | Database: `postgresql` (default), `mysql`, `sqlite` |
67
79
  | `-f, --format <format>` | Output format: `dbml` (default), `markdown` |
68
- | `-r, --relational` | Generate refs from relations() definitions |
69
80
  | `-w, --watch` | Regenerate on file changes |
70
81
  | `--single-file` | Output Markdown as a single file (markdown only) |
71
82
  | `--no-er-diagram` | Exclude ER diagram from Markdown output |
72
83
  | `--force` | Overwrite existing files without confirmation |
73
84
 
85
+ ### Relation Detection
86
+
87
+ Relations are **automatically detected** from your schema:
88
+
89
+ - **v1 API** (`defineRelations()`): Detected from schema objects at runtime
90
+ - **v0 API** (`relations()`): Detected by parsing source files
91
+
92
+ No configuration needed - the tool will use relation definitions when present, or fall back to foreign key constraints.
93
+
74
94
  ## Example
75
95
 
76
96
  ```typescript
@@ -111,38 +131,6 @@ Users table
111
131
 
112
132
  See [examples/](./examples/) for more detailed output samples.
113
133
 
114
- ## API
115
-
116
- ```typescript
117
- import { pgGenerate } from "drizzle-docs-generator";
118
- import * as schema from "./schema";
119
-
120
- const dbml = pgGenerate({
121
- schema,
122
- source: "./schema.ts",
123
- relational: false,
124
- out: "./output.dbml", // optional
125
- });
126
- ```
127
-
128
- `mysqlGenerate`, `sqliteGenerate` are also available.
129
-
130
- ## Requirements
131
-
132
- - Node.js >= 24
133
- - Drizzle ORM v1 beta (1.0.0-beta.10+)
134
- - ES Modules (ESM): Your project must use ESM (`"type": "module"` in package.json)
135
-
136
- ## How It Works
137
-
138
- This tool uses [tsx](https://github.com/privatenumber/tsx) to load your schema files, which means:
139
-
140
- ✅ **Extensionless imports work**: `import { users } from './users'`
141
- ✅ **TypeScript files are loaded directly**: No need to compile first
142
- ✅ **Directory imports**: Load all schema files from a directory automatically
143
-
144
- Your schema files can use standard TypeScript module resolution without worrying about file extensions.
145
-
146
134
  ## License
147
135
 
148
136
  MIT
package/dist/cli/index.js CHANGED
@@ -1,27 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command as D } from "commander";
3
- import { readFileSync as q, existsSync as l, mkdirSync as g, writeFileSync as f, watch as v, lstatSync as S, readdirSync as G } from "node:fs";
3
+ import { readFileSync as q, existsSync as l, mkdirSync as g, writeFileSync as u, watch as v, lstatSync as S, readdirSync as G } from "node:fs";
4
4
  import { join as m, dirname as p, resolve as y } from "node:path";
5
5
  import { pathToFileURL as $ } from "node:url";
6
6
  import { PgGenerator as O, pgGenerate as j } from "../generator/pg.js";
7
7
  import { MySqlGenerator as z, mysqlGenerate as P } from "../generator/mysql.js";
8
- import { SqliteGenerator as T, sqliteGenerate as U } from "../generator/sqlite.js";
9
- import "drizzle-orm";
10
- import "drizzle-orm/pg-core";
11
- import "drizzle-orm/mysql-core";
12
- import "drizzle-orm/sqlite-core";
13
- import "typescript";
8
+ import { SqliteGenerator as T, sqliteGenerate as R } from "../generator/sqlite.js";
14
9
  import { MarkdownFormatter as F } from "../formatter/markdown.js";
15
10
  import { MermaidErDiagramFormatter as k } from "../formatter/mermaid.js";
16
- import { register as R } from "tsx/esm/api";
17
- const W = R(), h = new D(), C = m(import.meta.dirname, "../../package.json"), w = JSON.parse(q(C, "utf-8"));
11
+ import { register as U } from "tsx/esm/api";
12
+ const W = U(), h = new D(), C = m(import.meta.dirname, "../../package.json"), w = JSON.parse(q(C, "utf-8"));
18
13
  h.name("drizzle-docs").description(w.description).version(w.version);
19
14
  function E(r) {
20
15
  switch (r) {
21
16
  case "mysql":
22
17
  return P;
23
18
  case "sqlite":
24
- return U;
19
+ return R;
25
20
  default:
26
21
  return j;
27
22
  }
@@ -53,7 +48,6 @@ async function L(r, e) {
53
48
  if (e.format === "markdown") {
54
49
  const a = x(e.dialect), s = new a({
55
50
  schema: n,
56
- relational: e.relational,
57
51
  source: r
58
52
  }).toIntermediateSchema();
59
53
  if (!e.singleFile && e.output) {
@@ -64,7 +58,6 @@ async function L(r, e) {
64
58
  } else
65
59
  return E(e.dialect)({
66
60
  schema: n,
67
- relational: e.relational,
68
61
  source: r
69
62
  });
70
63
  }
@@ -92,7 +85,6 @@ function N(r) {
92
85
  function B(r, e, o) {
93
86
  return E(o.dialect)({
94
87
  schema: r,
95
- relational: o.relational,
96
88
  source: e[0]
97
89
  }) || "";
98
90
  }
@@ -129,10 +121,10 @@ ${s}
129
121
  \`\`\`
130
122
  `;
131
123
  }
132
- f(m(e, "README.md"), a, "utf-8");
133
- for (const i of r.tables) {
134
- const s = t.generateTableDoc(i, r), c = `${i.name}.md`;
135
- f(m(e, c), `# ${i.name}
124
+ u(m(e, "README.md"), a, "utf-8");
125
+ for (const c of r.tables) {
126
+ const s = t.generateTableDoc(c, r), i = `${c.name}.md`;
127
+ u(m(e, i), `# ${c.name}
136
128
 
137
129
  ${s}
138
130
  `, "utf-8");
@@ -140,7 +132,7 @@ ${s}
140
132
  }
141
133
  function J(r, e) {
142
134
  const o = p(e);
143
- g(o, { recursive: !0 }), f(e, r.endsWith(`
135
+ g(o, { recursive: !0 }), u(e, r.endsWith(`
144
136
  `) ? r : r + `
145
137
  `, "utf-8");
146
138
  }
@@ -149,9 +141,9 @@ async function A(r, e) {
149
141
  try {
150
142
  const t = {};
151
143
  for (const n of o) {
152
- const a = $(n).href, i = e.watch ? `?t=${Date.now()}` : "";
144
+ const a = $(n).href, c = e.watch ? `?t=${Date.now()}` : "";
153
145
  try {
154
- const s = await import(a + i);
146
+ const s = await import(a + c);
155
147
  Object.assign(t, s);
156
148
  } catch (s) {
157
149
  throw s instanceof Error && (console.error(`Error importing ${n}: ${s.message}`), console.error(`
@@ -159,30 +151,29 @@ Possible causes:`), console.error("- Syntax error in the schema file"), console.
159
151
  }
160
152
  }
161
153
  if (e.format === "markdown") {
162
- const n = x(e.dialect), i = new n({
154
+ const n = x(e.dialect), c = new n({
163
155
  schema: t,
164
- relational: e.relational,
165
156
  source: o[0]
166
157
  }).toIntermediateSchema();
167
158
  if (e.singleFile) {
168
- const s = d(i, e);
159
+ const s = d(c, e);
169
160
  e.output ? (!e.force && l(e.output) && (console.error(
170
161
  `Error: Output file already exists: ${e.output}
171
162
  Use --force to overwrite existing files.`
172
163
  ), process.exit(1)), J(s, e.output), console.log(`Markdown generated: ${e.output}`)) : console.log(s);
173
164
  } else if (e.output) {
174
165
  if (!e.force) {
175
- const s = i.tables.map((u) => u.name), c = I(e.output, s);
176
- c.length > 0 && (console.error(
166
+ const s = c.tables.map((f) => f.name), i = I(e.output, s);
167
+ i.length > 0 && (console.error(
177
168
  `Error: The following files already exist:
178
- ${c.map((u) => ` - ${u}`).join(`
169
+ ${i.map((f) => ` - ${f}`).join(`
179
170
  `)}
180
171
  Use --force to overwrite existing files.`
181
172
  ), process.exit(1));
182
173
  }
183
- M(i, e.output, e), console.log(`Markdown generated: ${e.output}/`);
174
+ M(c, e.output, e), console.log(`Markdown generated: ${e.output}/`);
184
175
  } else {
185
- const s = d(i, e);
176
+ const s = d(c, e);
186
177
  console.log(s);
187
178
  }
188
179
  } else {
@@ -193,7 +184,7 @@ Use --force to overwrite existing files.`
193
184
  Use --force to overwrite existing files.`
194
185
  ), process.exit(1));
195
186
  const a = p(e.output);
196
- g(a, { recursive: !0 }), f(e.output, n.endsWith(`
187
+ g(a, { recursive: !0 }), u(e.output, n.endsWith(`
197
188
  `) ? n : n + `
198
189
  `, "utf-8"), console.log(`DBML generated: ${e.output}`);
199
190
  } else
@@ -212,12 +203,12 @@ function V(r, e) {
212
203
  console.log(`
213
204
  File changed, regenerating...`);
214
205
  try {
215
- const a = await L(o, e), i = e.format === "markdown" ? "Markdown" : "DBML", s = e.format === "markdown" && !e.singleFile && e.output;
206
+ const a = await L(o, e), c = e.format === "markdown" ? "Markdown" : "DBML", s = e.format === "markdown" && !e.singleFile && e.output;
216
207
  if (!e.output && a)
217
208
  console.log(a);
218
209
  else if (e.output) {
219
- const c = s ? `${e.output}/` : e.output;
220
- console.log(`${i} regenerated: ${c}`);
210
+ const i = s ? `${e.output}/` : e.output;
211
+ console.log(`${c} regenerated: ${i}`);
221
212
  }
222
213
  } catch (a) {
223
214
  a instanceof Error ? console.error(`Error: ${a.message}`) : console.error("Error:", a);
@@ -225,7 +216,7 @@ File changed, regenerating...`);
225
216
  }, 100));
226
217
  });
227
218
  }
228
- h.command("generate").description("Generate documentation from Drizzle schema files").argument("<schema>", "Path to Drizzle schema file or directory").option("-o, --output <path>", "Output file or directory path").option("-d, --dialect <dialect>", "Database dialect (postgresql, mysql, sqlite)", "postgresql").option("-f, --format <format>", "Output format (dbml, markdown)", "dbml").option("-r, --relational", "Use relations() definitions instead of foreign keys").option("-w, --watch", "Watch for file changes and regenerate").option("--single-file", "Output Markdown as a single file (for markdown format)").option("--no-er-diagram", "Exclude ER diagram from Markdown output").option("--force", "Overwrite existing files without confirmation").action(async (r, e) => {
219
+ h.command("generate").description("Generate documentation from Drizzle schema files").argument("<schema>", "Path to Drizzle schema file or directory").option("-o, --output <path>", "Output file or directory path").option("-d, --dialect <dialect>", "Database dialect (postgresql, mysql, sqlite)", "postgresql").option("-f, --format <format>", "Output format (dbml, markdown)", "dbml").option("-w, --watch", "Watch for file changes and regenerate").option("--single-file", "Output Markdown as a single file (for markdown format)").option("--no-er-diagram", "Exclude ER diagram from Markdown output").option("--force", "Overwrite existing files without confirmation").action(async (r, e) => {
229
220
  const o = ["postgresql", "mysql", "sqlite"];
230
221
  o.includes(e.dialect) || (console.error(
231
222
  `Error: Invalid dialect "${e.dialect}". Valid options: ${o.join(", ")}`
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * CLI for drizzle-docs-generator\n *\n * Generates DBML files from Drizzle ORM schema definitions.\n */\n\nimport { Command } from \"commander\";\nimport {\n existsSync,\n lstatSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n watch,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { pgGenerate, mysqlGenerate, sqliteGenerate } from \"../generator/index\";\nimport { PgGenerator, MySqlGenerator, SqliteGenerator } from \"../generator/index\";\nimport { MarkdownFormatter } from \"../formatter/markdown\";\nimport { MermaidErDiagramFormatter } from \"../formatter/mermaid\";\nimport { register } from \"tsx/esm/api\";\nimport type { IntermediateSchema } from \"../types\";\n\n// Register tsx loader to support TypeScript and extensionless imports\nconst unregister = register();\n\nconst program = new Command();\n\n// Use import.meta.dirname (Node 20.11+) to resolve package.json\n// This works correctly even after bundling\nconst packageJsonPath = join(import.meta.dirname, \"../../package.json\");\nconst packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf-8\")) as {\n version: string;\n description: string;\n};\n\nprogram.name(\"drizzle-docs\").description(packageJson.description).version(packageJson.version);\n\ntype Dialect = \"postgresql\" | \"mysql\" | \"sqlite\";\ntype OutputFormat = \"dbml\" | \"markdown\";\n\ninterface GenerateCommandOptions {\n output?: string;\n dialect: Dialect;\n relational?: boolean;\n watch?: boolean;\n format: OutputFormat;\n singleFile?: boolean;\n erDiagram: boolean; // commander uses --no-er-diagram which sets erDiagram to false\n force?: boolean; // skip overwrite confirmation for existing files\n}\n\n/**\n * Get the generate function based on dialect\n */\nfunction getGenerateFunction(dialect: Dialect) {\n switch (dialect) {\n case \"mysql\":\n return mysqlGenerate;\n case \"sqlite\":\n return sqliteGenerate;\n case \"postgresql\":\n default:\n return pgGenerate;\n }\n}\n\n/**\n * Get the generator class based on dialect\n */\nfunction getGeneratorClass(dialect: Dialect) {\n switch (dialect) {\n case \"mysql\":\n return MySqlGenerator;\n case \"sqlite\":\n return SqliteGenerator;\n case \"postgresql\":\n default:\n return PgGenerator;\n }\n}\n\n/**\n * Check if output directory has existing files\n */\nfunction hasExistingFiles(outputDir: string, tableNames: string[]): string[] {\n const existingFiles: string[] = [];\n\n if (!existsSync(outputDir)) {\n return existingFiles;\n }\n\n const readmePath = join(outputDir, \"README.md\");\n if (existsSync(readmePath)) {\n existingFiles.push(readmePath);\n }\n\n for (const tableName of tableNames) {\n const tablePath = join(outputDir, `${tableName}.md`);\n if (existsSync(tablePath)) {\n existingFiles.push(tablePath);\n }\n }\n\n return existingFiles;\n}\n\n/**\n * Generate output from a schema file (for watch mode)\n * Returns the generated output string for single-file formats,\n * or writes multiple files directly for multi-file markdown\n */\nasync function generateFromSchema(\n schemaPath: string,\n options: GenerateCommandOptions,\n): Promise<string | undefined> {\n // Use file URL for dynamic import (required for ESM)\n const schemaUrl = pathToFileURL(schemaPath).href;\n\n // Dynamic import with cache busting for watch mode\n const cacheBuster = options.watch ? `?t=${Date.now()}` : \"\";\n const schemaModule = (await import(schemaUrl + cacheBuster)) as Record<string, unknown>;\n\n if (options.format === \"markdown\") {\n const GeneratorClass = getGeneratorClass(options.dialect);\n const generator = new GeneratorClass({\n schema: schemaModule,\n relational: options.relational,\n source: schemaPath,\n });\n const intermediateSchema = generator.toIntermediateSchema();\n\n // Handle multi-file output in watch mode\n if (!options.singleFile && options.output) {\n writeMarkdownMultipleFiles(intermediateSchema, options.output, options);\n return undefined;\n }\n\n return generateMarkdownOutput(intermediateSchema, options);\n } else {\n const generate = getGenerateFunction(options.dialect);\n return generate({\n schema: schemaModule,\n relational: options.relational,\n source: schemaPath,\n });\n }\n}\n\n/**\n * Find all TypeScript schema files in a directory\n */\nfunction findSchemaFiles(dirPath: string): string[] {\n const files: string[] = [];\n\n try {\n const entries = readdirSync(dirPath, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = join(dirPath, entry.name);\n\n if (entry.isDirectory()) {\n // Recursively search subdirectories\n files.push(...findSchemaFiles(fullPath));\n } else if (entry.isFile() && /\\.(ts|js|mts|mjs|cts|cjs)$/.test(entry.name)) {\n files.push(fullPath);\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error reading directory ${dirPath}: ${error.message}`);\n }\n }\n\n return files;\n}\n\n/**\n * Resolve schema path (file or directory)\n */\nfunction resolveSchemaPath(schema: string): string[] {\n const schemaPath = resolve(process.cwd(), schema);\n\n // Check if path exists\n if (!existsSync(schemaPath)) {\n console.error(`Error: Schema path not found: ${schemaPath}`);\n process.exit(1);\n }\n\n // Check if it's a directory\n const stats = lstatSync(schemaPath);\n if (stats.isDirectory()) {\n const schemaFiles = findSchemaFiles(schemaPath);\n if (schemaFiles.length === 0) {\n console.error(`Error: No schema files found in directory: ${schemaPath}`);\n process.exit(1);\n }\n return schemaFiles;\n }\n\n // Single file\n return [schemaPath];\n}\n\n/**\n * Generate DBML format output\n */\nfunction generateDbmlOutput(\n mergedSchema: Record<string, unknown>,\n schemaPaths: string[],\n options: GenerateCommandOptions,\n): string {\n const generate = getGenerateFunction(options.dialect);\n return (\n generate({\n schema: mergedSchema,\n relational: options.relational,\n source: schemaPaths[0],\n }) || \"\"\n );\n}\n\n/**\n * Generate Markdown format output\n */\nfunction generateMarkdownOutput(\n intermediateSchema: IntermediateSchema,\n options: GenerateCommandOptions,\n): string {\n const markdownFormatter = new MarkdownFormatter();\n const markdown = markdownFormatter.format(intermediateSchema);\n\n // Include ER diagram unless --no-er-diagram is specified\n if (options.erDiagram) {\n const mermaidFormatter = new MermaidErDiagramFormatter();\n const erDiagram = mermaidFormatter.format(intermediateSchema);\n\n return `${markdown}\\n\\n---\\n\\n## ER Diagram\\n\\n\\`\\`\\`mermaid\\n${erDiagram}\\n\\`\\`\\``;\n }\n\n return markdown;\n}\n\n/**\n * Write Markdown to multiple files (one per table)\n */\nfunction writeMarkdownMultipleFiles(\n intermediateSchema: IntermediateSchema,\n outputDir: string,\n options: GenerateCommandOptions,\n): void {\n // Ensure output directory exists\n mkdirSync(outputDir, { recursive: true });\n\n const markdownFormatter = new MarkdownFormatter({ linkFormat: \"file\" });\n\n // Write README.md with index\n const index = markdownFormatter.generateIndex(intermediateSchema);\n let readme = `${index}\\n`;\n\n // Add ER diagram to README unless disabled\n if (options.erDiagram) {\n const mermaidFormatter = new MermaidErDiagramFormatter();\n const erDiagram = mermaidFormatter.format(intermediateSchema);\n readme += `\\n---\\n\\n## ER Diagram\\n\\n\\`\\`\\`mermaid\\n${erDiagram}\\n\\`\\`\\`\\n`;\n }\n\n writeFileSync(join(outputDir, \"README.md\"), readme, \"utf-8\");\n\n // Write individual table files\n for (const table of intermediateSchema.tables) {\n const tableDoc = markdownFormatter.generateTableDoc(table, intermediateSchema);\n const fileName = `${table.name}.md`;\n writeFileSync(join(outputDir, fileName), `# ${table.name}\\n\\n${tableDoc}\\n`, \"utf-8\");\n }\n}\n\n/**\n * Write single Markdown file\n */\nfunction writeSingleMarkdownFile(content: string, outputPath: string): void {\n const dir = dirname(outputPath);\n mkdirSync(dir, { recursive: true });\n writeFileSync(outputPath, content.endsWith(\"\\n\") ? content : content + \"\\n\", \"utf-8\");\n}\n\n/**\n * Run the generate command\n */\nasync function runGenerate(schema: string, options: GenerateCommandOptions): Promise<void> {\n const schemaPaths = resolveSchemaPath(schema);\n\n try {\n // Merge all schema modules\n const mergedSchema: Record<string, unknown> = {};\n\n for (const schemaPath of schemaPaths) {\n const schemaUrl = pathToFileURL(schemaPath).href;\n const cacheBuster = options.watch ? `?t=${Date.now()}` : \"\";\n\n try {\n const schemaModule = (await import(schemaUrl + cacheBuster)) as Record<string, unknown>;\n Object.assign(mergedSchema, schemaModule);\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error importing ${schemaPath}: ${error.message}`);\n console.error(\"\\nPossible causes:\");\n console.error(\"- Syntax error in the schema file\");\n console.error(\"- Missing dependencies (make sure drizzle-orm is installed)\");\n console.error(\"- Circular dependencies between schema files\");\n }\n throw error;\n }\n }\n\n if (options.format === \"markdown\") {\n // Generate Markdown format\n const GeneratorClass = getGeneratorClass(options.dialect);\n const generator = new GeneratorClass({\n schema: mergedSchema,\n relational: options.relational,\n source: schemaPaths[0],\n });\n const intermediateSchema = generator.toIntermediateSchema();\n\n if (options.singleFile) {\n // Single file Markdown output\n const content = generateMarkdownOutput(intermediateSchema, options);\n\n if (options.output) {\n // Check for existing file if --force is not specified\n if (!options.force && existsSync(options.output)) {\n console.error(\n `Error: Output file already exists: ${options.output}\\nUse --force to overwrite existing files.`,\n );\n process.exit(1);\n }\n writeSingleMarkdownFile(content, options.output);\n console.log(`Markdown generated: ${options.output}`);\n } else {\n console.log(content);\n }\n } else {\n // Multiple files Markdown output\n if (!options.output) {\n // If no output specified, default to stdout with single file format\n const content = generateMarkdownOutput(intermediateSchema, options);\n console.log(content);\n } else {\n // Check for existing files if --force is not specified\n if (!options.force) {\n const tableNames = intermediateSchema.tables.map((t) => t.name);\n const existingFiles = hasExistingFiles(options.output, tableNames);\n if (existingFiles.length > 0) {\n console.error(\n `Error: The following files already exist:\\n${existingFiles.map((f) => ` - ${f}`).join(\"\\n\")}\\nUse --force to overwrite existing files.`,\n );\n process.exit(1);\n }\n }\n writeMarkdownMultipleFiles(intermediateSchema, options.output, options);\n console.log(`Markdown generated: ${options.output}/`);\n }\n }\n } else {\n // Generate DBML format (default)\n const dbml = generateDbmlOutput(mergedSchema, schemaPaths, options);\n\n if (options.output) {\n // Check for existing file if --force is not specified\n if (!options.force && existsSync(options.output)) {\n console.error(\n `Error: Output file already exists: ${options.output}\\nUse --force to overwrite existing files.`,\n );\n process.exit(1);\n }\n const dir = dirname(options.output);\n mkdirSync(dir, { recursive: true });\n writeFileSync(options.output, dbml.endsWith(\"\\n\") ? dbml : dbml + \"\\n\", \"utf-8\");\n console.log(`DBML generated: ${options.output}`);\n } else {\n console.log(dbml);\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error generating output: ${error.message}`);\n } else {\n console.error(\"Error generating output:\", error);\n }\n process.exit(1);\n }\n}\n\n/**\n * Watch mode: regenerate on file changes\n */\nfunction watchSchema(schema: string, options: GenerateCommandOptions): void {\n const schemaPath = resolve(process.cwd(), schema);\n\n console.log(`Watching for changes: ${schemaPath}`);\n\n let debounceTimer: NodeJS.Timeout | null = null;\n\n watch(schemaPath, async (eventType) => {\n if (eventType === \"change\") {\n // Debounce to avoid multiple triggers\n if (debounceTimer) {\n clearTimeout(debounceTimer);\n }\n\n debounceTimer = setTimeout(async () => {\n console.log(\"\\nFile changed, regenerating...\");\n try {\n const output = await generateFromSchema(schemaPath, options);\n const formatLabel = options.format === \"markdown\" ? \"Markdown\" : \"DBML\";\n const isMultiFile =\n options.format === \"markdown\" && !options.singleFile && options.output;\n\n if (!options.output && output) {\n console.log(output);\n } else if (options.output) {\n const outputLabel = isMultiFile ? `${options.output}/` : options.output;\n console.log(`${formatLabel} regenerated: ${outputLabel}`);\n }\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error: ${error.message}`);\n } else {\n console.error(\"Error:\", error);\n }\n }\n }, 100);\n }\n });\n}\n\nprogram\n .command(\"generate\")\n .description(\"Generate documentation from Drizzle schema files\")\n .argument(\"<schema>\", \"Path to Drizzle schema file or directory\")\n .option(\"-o, --output <path>\", \"Output file or directory path\")\n .option(\"-d, --dialect <dialect>\", \"Database dialect (postgresql, mysql, sqlite)\", \"postgresql\")\n .option(\"-f, --format <format>\", \"Output format (dbml, markdown)\", \"dbml\")\n .option(\"-r, --relational\", \"Use relations() definitions instead of foreign keys\")\n .option(\"-w, --watch\", \"Watch for file changes and regenerate\")\n .option(\"--single-file\", \"Output Markdown as a single file (for markdown format)\")\n .option(\"--no-er-diagram\", \"Exclude ER diagram from Markdown output\")\n .option(\"--force\", \"Overwrite existing files without confirmation\")\n .action(async (schema: string, options: GenerateCommandOptions) => {\n // Validate dialect\n const validDialects: Dialect[] = [\"postgresql\", \"mysql\", \"sqlite\"];\n if (!validDialects.includes(options.dialect)) {\n console.error(\n `Error: Invalid dialect \"${options.dialect}\". Valid options: ${validDialects.join(\", \")}`,\n );\n process.exit(1);\n }\n\n // Validate format\n const validFormats: OutputFormat[] = [\"dbml\", \"markdown\"];\n if (!validFormats.includes(options.format)) {\n console.error(\n `Error: Invalid format \"${options.format}\". Valid options: ${validFormats.join(\", \")}`,\n );\n process.exit(1);\n }\n\n // Warn if --single-file or --no-er-diagram used with non-markdown format\n if (options.format !== \"markdown\") {\n if (options.singleFile) {\n console.warn(\"Warning: --single-file is only applicable with --format markdown\");\n }\n if (!options.erDiagram) {\n console.warn(\"Warning: --no-er-diagram is only applicable with --format markdown\");\n }\n }\n\n // Initial generation\n await runGenerate(schema, options);\n\n // Start watch mode if requested\n if (options.watch) {\n watchSchema(schema, options);\n }\n });\n\nprogram.parse();\n\n// Cleanup: Unregister tsx loader when process exits\nprocess.on(\"exit\", () => {\n unregister();\n});\n"],"names":["unregister","register","program","Command","packageJsonPath","join","packageJson","readFileSync","getGenerateFunction","dialect","mysqlGenerate","sqliteGenerate","pgGenerate","getGeneratorClass","MySqlGenerator","SqliteGenerator","PgGenerator","hasExistingFiles","outputDir","tableNames","existingFiles","existsSync","readmePath","tableName","tablePath","generateFromSchema","schemaPath","options","schemaUrl","pathToFileURL","cacheBuster","schemaModule","GeneratorClass","intermediateSchema","writeMarkdownMultipleFiles","generateMarkdownOutput","findSchemaFiles","dirPath","files","entries","readdirSync","entry","fullPath","error","resolveSchemaPath","schema","resolve","lstatSync","schemaFiles","generateDbmlOutput","mergedSchema","schemaPaths","markdown","MarkdownFormatter","erDiagram","MermaidErDiagramFormatter","mkdirSync","markdownFormatter","readme","writeFileSync","table","tableDoc","fileName","writeSingleMarkdownFile","content","outputPath","dir","dirname","runGenerate","t","f","dbml","watchSchema","debounceTimer","watch","eventType","output","formatLabel","isMultiFile","outputLabel","validDialects","validFormats"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAMA,IAAaC,EAAA,GAEbC,IAAU,IAAIC,EAAA,GAIdC,IAAkBC,EAAK,YAAY,SAAS,oBAAoB,GAChEC,IAAc,KAAK,MAAMC,EAAaH,GAAiB,OAAO,CAAC;AAKrEF,EAAQ,KAAK,cAAc,EAAE,YAAYI,EAAY,WAA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AAO,MACzC,QAAQ;AAAA,IACN,2BAA2BA,EAAQ,OAAO,qBAAqBqD,EAAc,KAAK,IAAI,CAAC;AAAA,EAAA,GAEzF,QAAQ,KAAK,CAAC;AAIhB,QAAMC,IAA+B,CAAC,QAAQ,UAAU;AACxD,EAAKA,EAAa,SAAStD,EAAQ,MAAM,MACvC,QAAQ;AAAA,IACN,0BAA0BA,EAAQ,MAAM,qBAAqBsD,EAAa,KAAK,IAAI,CAAC;AAAA,EAAA,GAEtF,QAAQ,KAAK,CAAC,IAIZtD,EAAQ,WAAW,eACjBA,EAAQ,cACV,QAAQ,KAAK,kEAAkE,GAE5EA,EAAQ,aACX,QAAQ,KAAK,oEAAoE,IAKrF,MAAMyC,EAAYvB,GAAQlB,CAAO,GAG7BA,EAAQ,SACV6C,EAAY3B,GAAQlB,CAAO;AAE/B,CAAC;AAEHzB,EAAQ,MAAA;AAGR,QAAQ,GAAG,QAAQ,MAAM;AACvB,EAAAF,EAAA;AACF,CAAC;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * CLI for drizzle-docs-generator\n *\n * Generates DBML files from Drizzle ORM schema definitions.\n */\n\nimport { Command } from \"commander\";\nimport {\n existsSync,\n lstatSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n watch,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { pgGenerate } from \"../generator/pg\";\nimport { mysqlGenerate } from \"../generator/mysql\";\nimport { sqliteGenerate } from \"../generator/sqlite\";\nimport { PgGenerator } from \"../generator/pg\";\nimport { MySqlGenerator } from \"../generator/mysql\";\nimport { SqliteGenerator } from \"../generator/sqlite\";\nimport { MarkdownFormatter } from \"../formatter/markdown\";\nimport { MermaidErDiagramFormatter } from \"../formatter/mermaid\";\nimport { register } from \"tsx/esm/api\";\nimport type { IntermediateSchema } from \"../types\";\n\n// Register tsx loader to support TypeScript and extensionless imports\nconst unregister = register();\n\nconst program = new Command();\n\n// Use import.meta.dirname (Node 20.11+) to resolve package.json\n// This works correctly even after bundling\nconst packageJsonPath = join(import.meta.dirname, \"../../package.json\");\nconst packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf-8\")) as {\n version: string;\n description: string;\n};\n\nprogram.name(\"drizzle-docs\").description(packageJson.description).version(packageJson.version);\n\ntype Dialect = \"postgresql\" | \"mysql\" | \"sqlite\";\ntype OutputFormat = \"dbml\" | \"markdown\";\n\ninterface GenerateCommandOptions {\n output?: string;\n dialect: Dialect;\n watch?: boolean;\n format: OutputFormat;\n singleFile?: boolean;\n erDiagram: boolean; // commander uses --no-er-diagram which sets erDiagram to false\n force?: boolean; // skip overwrite confirmation for existing files\n}\n\n/**\n * Get the generate function based on dialect\n */\nfunction getGenerateFunction(dialect: Dialect) {\n switch (dialect) {\n case \"mysql\":\n return mysqlGenerate;\n case \"sqlite\":\n return sqliteGenerate;\n case \"postgresql\":\n default:\n return pgGenerate;\n }\n}\n\n/**\n * Get the generator class based on dialect\n */\nfunction getGeneratorClass(dialect: Dialect) {\n switch (dialect) {\n case \"mysql\":\n return MySqlGenerator;\n case \"sqlite\":\n return SqliteGenerator;\n case \"postgresql\":\n default:\n return PgGenerator;\n }\n}\n\n/**\n * Check if output directory has existing files\n */\nfunction hasExistingFiles(outputDir: string, tableNames: string[]): string[] {\n const existingFiles: string[] = [];\n\n if (!existsSync(outputDir)) {\n return existingFiles;\n }\n\n const readmePath = join(outputDir, \"README.md\");\n if (existsSync(readmePath)) {\n existingFiles.push(readmePath);\n }\n\n for (const tableName of tableNames) {\n const tablePath = join(outputDir, `${tableName}.md`);\n if (existsSync(tablePath)) {\n existingFiles.push(tablePath);\n }\n }\n\n return existingFiles;\n}\n\n/**\n * Generate output from a schema file (for watch mode)\n * Returns the generated output string for single-file formats,\n * or writes multiple files directly for multi-file markdown\n */\nasync function generateFromSchema(\n schemaPath: string,\n options: GenerateCommandOptions,\n): Promise<string | undefined> {\n // Use file URL for dynamic import (required for ESM)\n const schemaUrl = pathToFileURL(schemaPath).href;\n\n // Dynamic import with cache busting for watch mode\n const cacheBuster = options.watch ? `?t=${Date.now()}` : \"\";\n const schemaModule = (await import(schemaUrl + cacheBuster)) as Record<string, unknown>;\n\n if (options.format === \"markdown\") {\n const GeneratorClass = getGeneratorClass(options.dialect);\n const generator = new GeneratorClass({\n schema: schemaModule,\n source: schemaPath,\n });\n const intermediateSchema = generator.toIntermediateSchema();\n\n // Handle multi-file output in watch mode\n if (!options.singleFile && options.output) {\n writeMarkdownMultipleFiles(intermediateSchema, options.output, options);\n return undefined;\n }\n\n return generateMarkdownOutput(intermediateSchema, options);\n } else {\n const generate = getGenerateFunction(options.dialect);\n return generate({\n schema: schemaModule,\n source: schemaPath,\n });\n }\n}\n\n/**\n * Find all TypeScript schema files in a directory\n */\nfunction findSchemaFiles(dirPath: string): string[] {\n const files: string[] = [];\n\n try {\n const entries = readdirSync(dirPath, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = join(dirPath, entry.name);\n\n if (entry.isDirectory()) {\n // Recursively search subdirectories\n files.push(...findSchemaFiles(fullPath));\n } else if (entry.isFile() && /\\.(ts|js|mts|mjs|cts|cjs)$/.test(entry.name)) {\n files.push(fullPath);\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error reading directory ${dirPath}: ${error.message}`);\n }\n }\n\n return files;\n}\n\n/**\n * Resolve schema path (file or directory)\n */\nfunction resolveSchemaPath(schema: string): string[] {\n const schemaPath = resolve(process.cwd(), schema);\n\n // Check if path exists\n if (!existsSync(schemaPath)) {\n console.error(`Error: Schema path not found: ${schemaPath}`);\n process.exit(1);\n }\n\n // Check if it's a directory\n const stats = lstatSync(schemaPath);\n if (stats.isDirectory()) {\n const schemaFiles = findSchemaFiles(schemaPath);\n if (schemaFiles.length === 0) {\n console.error(`Error: No schema files found in directory: ${schemaPath}`);\n process.exit(1);\n }\n return schemaFiles;\n }\n\n // Single file\n return [schemaPath];\n}\n\n/**\n * Generate DBML format output\n */\nfunction generateDbmlOutput(\n mergedSchema: Record<string, unknown>,\n schemaPaths: string[],\n options: GenerateCommandOptions,\n): string {\n const generate = getGenerateFunction(options.dialect);\n return (\n generate({\n schema: mergedSchema,\n source: schemaPaths[0],\n }) || \"\"\n );\n}\n\n/**\n * Generate Markdown format output\n */\nfunction generateMarkdownOutput(\n intermediateSchema: IntermediateSchema,\n options: GenerateCommandOptions,\n): string {\n const markdownFormatter = new MarkdownFormatter();\n const markdown = markdownFormatter.format(intermediateSchema);\n\n // Include ER diagram unless --no-er-diagram is specified\n if (options.erDiagram) {\n const mermaidFormatter = new MermaidErDiagramFormatter();\n const erDiagram = mermaidFormatter.format(intermediateSchema);\n\n return `${markdown}\\n\\n---\\n\\n## ER Diagram\\n\\n\\`\\`\\`mermaid\\n${erDiagram}\\n\\`\\`\\``;\n }\n\n return markdown;\n}\n\n/**\n * Write Markdown to multiple files (one per table)\n */\nfunction writeMarkdownMultipleFiles(\n intermediateSchema: IntermediateSchema,\n outputDir: string,\n options: GenerateCommandOptions,\n): void {\n // Ensure output directory exists\n mkdirSync(outputDir, { recursive: true });\n\n const markdownFormatter = new MarkdownFormatter({ linkFormat: \"file\" });\n\n // Write README.md with index\n const index = markdownFormatter.generateIndex(intermediateSchema);\n let readme = `${index}\\n`;\n\n // Add ER diagram to README unless disabled\n if (options.erDiagram) {\n const mermaidFormatter = new MermaidErDiagramFormatter();\n const erDiagram = mermaidFormatter.format(intermediateSchema);\n readme += `\\n---\\n\\n## ER Diagram\\n\\n\\`\\`\\`mermaid\\n${erDiagram}\\n\\`\\`\\`\\n`;\n }\n\n writeFileSync(join(outputDir, \"README.md\"), readme, \"utf-8\");\n\n // Write individual table files\n for (const table of intermediateSchema.tables) {\n const tableDoc = markdownFormatter.generateTableDoc(table, intermediateSchema);\n const fileName = `${table.name}.md`;\n writeFileSync(join(outputDir, fileName), `# ${table.name}\\n\\n${tableDoc}\\n`, \"utf-8\");\n }\n}\n\n/**\n * Write single Markdown file\n */\nfunction writeSingleMarkdownFile(content: string, outputPath: string): void {\n const dir = dirname(outputPath);\n mkdirSync(dir, { recursive: true });\n writeFileSync(outputPath, content.endsWith(\"\\n\") ? content : content + \"\\n\", \"utf-8\");\n}\n\n/**\n * Run the generate command\n */\nasync function runGenerate(schema: string, options: GenerateCommandOptions): Promise<void> {\n const schemaPaths = resolveSchemaPath(schema);\n\n try {\n // Merge all schema modules\n const mergedSchema: Record<string, unknown> = {};\n\n for (const schemaPath of schemaPaths) {\n const schemaUrl = pathToFileURL(schemaPath).href;\n const cacheBuster = options.watch ? `?t=${Date.now()}` : \"\";\n\n try {\n const schemaModule = (await import(schemaUrl + cacheBuster)) as Record<string, unknown>;\n Object.assign(mergedSchema, schemaModule);\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error importing ${schemaPath}: ${error.message}`);\n console.error(\"\\nPossible causes:\");\n console.error(\"- Syntax error in the schema file\");\n console.error(\"- Missing dependencies (make sure drizzle-orm is installed)\");\n console.error(\"- Circular dependencies between schema files\");\n }\n throw error;\n }\n }\n\n if (options.format === \"markdown\") {\n // Generate Markdown format\n const GeneratorClass = getGeneratorClass(options.dialect);\n const generator = new GeneratorClass({\n schema: mergedSchema,\n source: schemaPaths[0],\n });\n const intermediateSchema = generator.toIntermediateSchema();\n\n if (options.singleFile) {\n // Single file Markdown output\n const content = generateMarkdownOutput(intermediateSchema, options);\n\n if (options.output) {\n // Check for existing file if --force is not specified\n if (!options.force && existsSync(options.output)) {\n console.error(\n `Error: Output file already exists: ${options.output}\\nUse --force to overwrite existing files.`,\n );\n process.exit(1);\n }\n writeSingleMarkdownFile(content, options.output);\n console.log(`Markdown generated: ${options.output}`);\n } else {\n console.log(content);\n }\n } else {\n // Multiple files Markdown output\n if (!options.output) {\n // If no output specified, default to stdout with single file format\n const content = generateMarkdownOutput(intermediateSchema, options);\n console.log(content);\n } else {\n // Check for existing files if --force is not specified\n if (!options.force) {\n const tableNames = intermediateSchema.tables.map((t) => t.name);\n const existingFiles = hasExistingFiles(options.output, tableNames);\n if (existingFiles.length > 0) {\n console.error(\n `Error: The following files already exist:\\n${existingFiles.map((f) => ` - ${f}`).join(\"\\n\")}\\nUse --force to overwrite existing files.`,\n );\n process.exit(1);\n }\n }\n writeMarkdownMultipleFiles(intermediateSchema, options.output, options);\n console.log(`Markdown generated: ${options.output}/`);\n }\n }\n } else {\n // Generate DBML format (default)\n const dbml = generateDbmlOutput(mergedSchema, schemaPaths, options);\n\n if (options.output) {\n // Check for existing file if --force is not specified\n if (!options.force && existsSync(options.output)) {\n console.error(\n `Error: Output file already exists: ${options.output}\\nUse --force to overwrite existing files.`,\n );\n process.exit(1);\n }\n const dir = dirname(options.output);\n mkdirSync(dir, { recursive: true });\n writeFileSync(options.output, dbml.endsWith(\"\\n\") ? dbml : dbml + \"\\n\", \"utf-8\");\n console.log(`DBML generated: ${options.output}`);\n } else {\n console.log(dbml);\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error generating output: ${error.message}`);\n } else {\n console.error(\"Error generating output:\", error);\n }\n process.exit(1);\n }\n}\n\n/**\n * Watch mode: regenerate on file changes\n */\nfunction watchSchema(schema: string, options: GenerateCommandOptions): void {\n const schemaPath = resolve(process.cwd(), schema);\n\n console.log(`Watching for changes: ${schemaPath}`);\n\n let debounceTimer: NodeJS.Timeout | null = null;\n\n watch(schemaPath, async (eventType) => {\n if (eventType === \"change\") {\n // Debounce to avoid multiple triggers\n if (debounceTimer) {\n clearTimeout(debounceTimer);\n }\n\n debounceTimer = setTimeout(async () => {\n console.log(\"\\nFile changed, regenerating...\");\n try {\n const output = await generateFromSchema(schemaPath, options);\n const formatLabel = options.format === \"markdown\" ? \"Markdown\" : \"DBML\";\n const isMultiFile =\n options.format === \"markdown\" && !options.singleFile && options.output;\n\n if (!options.output && output) {\n console.log(output);\n } else if (options.output) {\n const outputLabel = isMultiFile ? `${options.output}/` : options.output;\n console.log(`${formatLabel} regenerated: ${outputLabel}`);\n }\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error: ${error.message}`);\n } else {\n console.error(\"Error:\", error);\n }\n }\n }, 100);\n }\n });\n}\n\nprogram\n .command(\"generate\")\n .description(\"Generate documentation from Drizzle schema files\")\n .argument(\"<schema>\", \"Path to Drizzle schema file or directory\")\n .option(\"-o, --output <path>\", \"Output file or directory path\")\n .option(\"-d, --dialect <dialect>\", \"Database dialect (postgresql, mysql, sqlite)\", \"postgresql\")\n .option(\"-f, --format <format>\", \"Output format (dbml, markdown)\", \"dbml\")\n .option(\"-w, --watch\", \"Watch for file changes and regenerate\")\n .option(\"--single-file\", \"Output Markdown as a single file (for markdown format)\")\n .option(\"--no-er-diagram\", \"Exclude ER diagram from Markdown output\")\n .option(\"--force\", \"Overwrite existing files without confirmation\")\n .action(async (schema: string, options: GenerateCommandOptions) => {\n // Validate dialect\n const validDialects: Dialect[] = [\"postgresql\", \"mysql\", \"sqlite\"];\n if (!validDialects.includes(options.dialect)) {\n console.error(\n `Error: Invalid dialect \"${options.dialect}\". Valid options: ${validDialects.join(\", \")}`,\n );\n process.exit(1);\n }\n\n // Validate format\n const validFormats: OutputFormat[] = [\"dbml\", \"markdown\"];\n if (!validFormats.includes(options.format)) {\n console.error(\n `Error: Invalid format \"${options.format}\". Valid options: ${validFormats.join(\", \")}`,\n );\n process.exit(1);\n }\n\n // Warn if --single-file or --no-er-diagram used with non-markdown format\n if (options.format !== \"markdown\") {\n if (options.singleFile) {\n console.warn(\"Warning: --single-file is only applicable with --format markdown\");\n }\n if (!options.erDiagram) {\n console.warn(\"Warning: --no-er-diagram is only applicable with --format markdown\");\n }\n }\n\n // Initial generation\n await runGenerate(schema, options);\n\n // Start watch mode if requested\n if (options.watch) {\n watchSchema(schema, options);\n }\n });\n\nprogram.parse();\n\n// Cleanup: Unregister tsx loader when process exits\nprocess.on(\"exit\", () => {\n unregister();\n});\n"],"names":["unregister","register","program","Command","packageJsonPath","join","packageJson","readFileSync","getGenerateFunction","dialect","mysqlGenerate","sqliteGenerate","pgGenerate","getGeneratorClass","MySqlGenerator","SqliteGenerator","PgGenerator","hasExistingFiles","outputDir","tableNames","existingFiles","existsSync","readmePath","tableName","tablePath","generateFromSchema","schemaPath","options","schemaUrl","pathToFileURL","cacheBuster","schemaModule","GeneratorClass","intermediateSchema","writeMarkdownMultipleFiles","generateMarkdownOutput","findSchemaFiles","dirPath","files","entries","readdirSync","entry","fullPath","error","resolveSchemaPath","schema","resolve","lstatSync","schemaFiles","generateDbmlOutput","mergedSchema","schemaPaths","markdown","MarkdownFormatter","erDiagram","MermaidErDiagramFormatter","mkdirSync","markdownFormatter","readme","writeFileSync","table","tableDoc","fileName","writeSingleMarkdownFile","content","outputPath","dir","dirname","runGenerate","t","dbml","watchSchema","debounceTimer","watch","eventType","output","formatLabel","isMultiFile","outputLabel","validDialects","validFormats"],"mappings":";;;;;;;;;;;AAgCA,MAAMA,IAAaC,EAAA,GAEbC,IAAU,IAAIC,EAAA,GAIdC,IAAkBC,EAAK,YAAY,SAAS,oBAAoB,GAChEC,IAAc,KAAK,MAAMC,EAAaH,GAAiB,OAAO,CAAC;AAKrEF,EAAQ,KAAK,cAAc,EAAE,YAAYI,EAAY,WAAW,EAAE,QAAQA,EAAY,OAAO;AAkB7F,SAASE,EAAoBC,GAAkB;AAC7C,UAAQA,GAAA;AAAA,IACN,KAAK;AACH,aAAOC;AAAA,IACT,KAAK;AACH,aAAOC;AAAA,IAET;AACE,aAAOC;AAAA,EAAA;AAEb;AAKA,SAASC,EAAkBJ,GAAkB;AAC3C,UAAQA,GAAA;AAAA,IACN,KAAK;AACH,aAAOK;AAAA,IACT,KAAK;AACH,aAAOC;AAAA,IAET;AACE,aAAOC;AAAA,EAAA;AAEb;AAKA,SAASC,EAAiBC,GAAmBC,GAAgC;AAC3E,QAAMC,IAA0B,CAAA;AAEhC,MAAI,CAACC,EAAWH,CAAS;AACvB,WAAOE;AAGT,QAAME,IAAajB,EAAKa,GAAW,WAAW;AAC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 -3,7 +3,7 @@ import { OutputFormatter, FormatterOptions } from './types';
3
3
  /**
4
4
  * Link format for table references
5
5
  */
6
- export type LinkFormat = "anchor" | "file";
6
+ type LinkFormat = "anchor" | "file";
7
7
  /**
8
8
  * Options for MarkdownFormatter
9
9
  */
@@ -119,7 +119,14 @@ export declare class MarkdownFormatter implements OutputFormatter {
119
119
  private createTableLink;
120
120
  /**
121
121
  * Escape special Markdown characters in a string
122
+ * Converts newlines to spaces for use in table cells
122
123
  */
123
124
  private escapeMarkdown;
125
+ /**
126
+ * Escape special Markdown characters and convert newlines to <br> tags
127
+ * Used for better readability in text sections (not in tables)
128
+ */
129
+ private escapeMarkdownWithBreaks;
124
130
  }
131
+ export {};
125
132
  //# sourceMappingURL=markdown.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/formatter/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EAMhB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAaD;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,YAAW,eAAe;IACvD,OAAO,CAAC,OAAO,CAAqC;IAEpD;;;;OAIG;gBACS,OAAO,GAAE,wBAA6B;IAIlD;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAyB1C;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IA4BjD;;;;;;OAMG;IACH,gBAAgB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IAIlD;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAyB1C;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IA4BjD;;;;;;OAMG;IACH,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAsC5E;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA6C5B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAoBhC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAqB5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAiC9B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAoB5B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAazB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAelC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;OAEG;IACH,OAAO,CAAC,OAAO;IAOf;;OAEG;IACH,OAAO,CAAC,eAAe;IAQvB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAItB;;;OAGG;IACH,OAAO,CAAC,wBAAwB;CAGjC"}
@@ -59,7 +59,7 @@ class T {
59
59
  */
60
60
  generateTableDoc(e, n) {
61
61
  const t = [];
62
- t.push(`## ${e.name}`), t.push(""), this.options.includeComments && e.comment && (t.push(this.escapeMarkdown(e.comment)), t.push("")), t.push(this.generateColumnsTable(e.columns, e.name, n)), this.options.includeConstraints && e.constraints.length > 0 && (t.push(""), t.push(this.generateConstraintsTable(e.constraints))), this.options.includeIndexes && e.indexes.length > 0 && (t.push(""), t.push(this.generateIndexesTable(e.indexes)));
62
+ t.push(`## ${e.name}`), t.push(""), this.options.includeComments && e.comment && (t.push(this.escapeMarkdownWithBreaks(e.comment)), t.push("")), t.push(this.generateColumnsTable(e.columns, e.name, n)), this.options.includeConstraints && e.constraints.length > 0 && (t.push(""), t.push(this.generateConstraintsTable(e.constraints))), this.options.includeIndexes && e.indexes.length > 0 && (t.push(""), t.push(this.generateIndexesTable(e.indexes)));
63
63
  const s = this.getTableRelations(e.name, n.relations);
64
64
  return s.length > 0 && (t.push(""), t.push(this.generateRelationsTable(s, e.name))), t.join(`
65
65
  `);
@@ -224,10 +224,19 @@ class T {
224
224
  }
225
225
  /**
226
226
  * Escape special Markdown characters in a string
227
+ * Converts newlines to spaces for use in table cells
227
228
  */
228
229
  escapeMarkdown(e) {
229
230
  return e.replace(/\|/g, "\\|").replace(/\n/g, " ");
230
231
  }
232
+ /**
233
+ * Escape special Markdown characters and convert newlines to <br> tags
234
+ * Used for better readability in text sections (not in tables)
235
+ */
236
+ escapeMarkdownWithBreaks(e) {
237
+ return e.replace(/\|/g, "\\|").replace(/\n/g, `
238
+ `);
239
+ }
231
240
  }
232
241
  export {
233
242
  T as MarkdownFormatter