@dbml/cli 8.0.0-alpha.12 → 8.0.0-alpha.15

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.
Files changed (92) hide show
  1. package/__tests__/db2dbml/mssql/dbml-error.log +70 -0
  2. package/__tests__/db2dbml/mysql/dbml-error.log +91 -0
  3. package/__tests__/db2dbml/oracle/dbml-error.log +98 -0
  4. package/__tests__/db2dbml/postgres/dbml-error.log +49 -0
  5. package/__tests__/dbml2sql/filename --mysql --out-file/out-files/schema.sql +1 -1
  6. package/__tests__/dbml2sql/filename --oracle --out-file/out-files/schema.sql +1 -1
  7. package/__tests__/dbml2sql/filename --out-file/out-files/schema.sql +1 -1
  8. package/__tests__/dbml2sql/filename --postgres --out-file/out-files/schema.sql +1 -1
  9. package/__tests__/dbml2sql/filenames --mysql --out-file/out-files/schema.sql +1 -1
  10. package/__tests__/dbml2sql/filenames --oracle --out-file/out-files/schema.sql +1 -1
  11. package/__tests__/dbml2sql/filenames --out-file/out-files/schema.sql +1 -1
  12. package/__tests__/dbml2sql/filenames --postgres --out-file/out-files/schema.sql +1 -1
  13. package/__tests__/dbml2sql/multifile aliased import stdout/dbml-error.log +0 -0
  14. package/__tests__/dbml2sql/multifile aliased import stdout/in-files/auth.dbml +4 -0
  15. package/__tests__/dbml2sql/multifile aliased import stdout/in-files/main.dbml +6 -0
  16. package/__tests__/dbml2sql/multifile aliased import stdout/options.json +3 -0
  17. package/__tests__/dbml2sql/multifile aliased import stdout/stdout.txt +12 -0
  18. package/__tests__/dbml2sql/multifile circular import stdout/dbml-error.log +0 -0
  19. package/__tests__/dbml2sql/multifile circular import stdout/in-files/a.dbml +6 -0
  20. package/__tests__/dbml2sql/multifile circular import stdout/in-files/b.dbml +6 -0
  21. package/__tests__/dbml2sql/multifile circular import stdout/options.json +3 -0
  22. package/__tests__/dbml2sql/multifile circular import stdout/stdout.txt +14 -0
  23. package/__tests__/dbml2sql/multifile error entry-syntax-error/dbml-error.log +92 -0
  24. package/__tests__/dbml2sql/multifile error entry-syntax-error/in-files/lib.dbml +4 -0
  25. package/__tests__/dbml2sql/multifile error entry-syntax-error/in-files/main.dbml +6 -0
  26. package/__tests__/dbml2sql/multifile error entry-syntax-error/options.json +3 -0
  27. package/__tests__/dbml2sql/multifile error entry-syntax-error/stdout.txt +5 -0
  28. package/__tests__/dbml2sql/multifile error import-not-found/dbml-error.log +5280 -0
  29. package/__tests__/dbml2sql/multifile error import-not-found/in-files/main.dbml +5 -0
  30. package/__tests__/dbml2sql/multifile error import-not-found/options.json +3 -0
  31. package/__tests__/dbml2sql/multifile error import-not-found/stdout.txt +4 -0
  32. package/__tests__/dbml2sql/multifile error imported-syntax-error/dbml-error.log +23 -0
  33. package/__tests__/dbml2sql/multifile error imported-syntax-error/in-files/broken.dbml +4 -0
  34. package/__tests__/dbml2sql/multifile error imported-syntax-error/in-files/main.dbml +6 -0
  35. package/__tests__/dbml2sql/multifile error imported-syntax-error/options.json +3 -0
  36. package/__tests__/dbml2sql/multifile error imported-syntax-error/stdout.txt +5 -0
  37. package/__tests__/dbml2sql/multifile error transitive-use-not-visible/dbml-error.log +24 -0
  38. package/__tests__/dbml2sql/multifile error transitive-use-not-visible/in-files/base.dbml +6 -0
  39. package/__tests__/dbml2sql/multifile error transitive-use-not-visible/in-files/main.dbml +3 -0
  40. package/__tests__/dbml2sql/multifile error transitive-use-not-visible/in-files/types.dbml +4 -0
  41. package/__tests__/dbml2sql/multifile error transitive-use-not-visible/options.json +3 -0
  42. package/__tests__/dbml2sql/multifile error transitive-use-not-visible/stdout.txt +4 -0
  43. package/__tests__/dbml2sql/multifile records pulling stdout/dbml-error.log +0 -0
  44. package/__tests__/dbml2sql/multifile records pulling stdout/in-files/base.dbml +9 -0
  45. package/__tests__/dbml2sql/multifile records pulling stdout/in-files/main.dbml +6 -0
  46. package/__tests__/dbml2sql/multifile records pulling stdout/options.json +3 -0
  47. package/__tests__/dbml2sql/multifile records pulling stdout/stdout.txt +23 -0
  48. package/__tests__/dbml2sql/multifile refs across files stdout/dbml-error.log +0 -0
  49. package/__tests__/dbml2sql/multifile refs across files stdout/in-files/main.dbml +2 -0
  50. package/__tests__/dbml2sql/multifile refs across files stdout/in-files/orders.dbml +8 -0
  51. package/__tests__/dbml2sql/multifile refs across files stdout/in-files/users.dbml +4 -0
  52. package/__tests__/dbml2sql/multifile refs across files stdout/options.json +3 -0
  53. package/__tests__/dbml2sql/multifile refs across files stdout/stdout.txt +12 -0
  54. package/__tests__/dbml2sql/multifile schema pulling stdout/dbml-error.log +0 -0
  55. package/__tests__/dbml2sql/multifile schema pulling stdout/in-files/auth.dbml +9 -0
  56. package/__tests__/dbml2sql/multifile schema pulling stdout/in-files/main.dbml +3 -0
  57. package/__tests__/dbml2sql/multifile schema pulling stdout/options.json +3 -0
  58. package/__tests__/dbml2sql/multifile schema pulling stdout/stdout.txt +14 -0
  59. package/__tests__/dbml2sql/multifile tablegroup pulling stdout/dbml-error.log +0 -0
  60. package/__tests__/dbml2sql/multifile tablegroup pulling stdout/in-files/base.dbml +14 -0
  61. package/__tests__/dbml2sql/multifile tablegroup pulling stdout/in-files/main.dbml +1 -0
  62. package/__tests__/dbml2sql/multifile tablegroup pulling stdout/options.json +3 -0
  63. package/__tests__/dbml2sql/multifile tablegroup pulling stdout/stdout.txt +12 -0
  64. package/__tests__/dbml2sql/multifile transitive reuse stdout/dbml-error.log +0 -0
  65. package/__tests__/dbml2sql/multifile transitive reuse stdout/in-files/base.dbml +6 -0
  66. package/__tests__/dbml2sql/multifile transitive reuse stdout/in-files/main.dbml +7 -0
  67. package/__tests__/dbml2sql/multifile transitive reuse stdout/in-files/types.dbml +4 -0
  68. package/__tests__/dbml2sql/multifile transitive reuse stdout/options.json +3 -0
  69. package/__tests__/dbml2sql/multifile transitive reuse stdout/stdout.txt +20 -0
  70. package/__tests__/dbml2sql/multiple_schema_mssql/out-files/multiple_schema.out.sql +1 -1
  71. package/__tests__/dbml2sql/multiple_schema_mysql/out-files/multiple_schema.out.sql +1 -1
  72. package/__tests__/dbml2sql/multiple_schema_oracle/out-files/multiple_schema.out.sql +1 -1
  73. package/__tests__/dbml2sql/multiple_schema_pg/out-files/multiple_schema.out.sql +1 -1
  74. package/__tests__/dbml2sql/single file stdout/dbml-error.log +0 -0
  75. package/__tests__/dbml2sql/single file stdout/in-files/schema.dbml +11 -0
  76. package/__tests__/dbml2sql/single file stdout/options.json +3 -0
  77. package/__tests__/dbml2sql/single file stdout/stdout.txt +14 -0
  78. package/__tests__/dbml2sql/syntax-error/dbml-error.log +96 -0
  79. package/__tests__/sql2dbml/custom-error-alter-table-column-not-found --oracle/dbml-error.log +28 -0
  80. package/__tests__/sql2dbml/custom-error-alter-table-table-not-found --oracle/dbml-error.log +28 -0
  81. package/__tests__/sql2dbml/custom-error-column-comment-column-not-found --oracle/dbml-error.log +28 -0
  82. package/__tests__/sql2dbml/custom-error-column-comment-table-not-found --oracle/dbml-error.log +28 -0
  83. package/__tests__/sql2dbml/custom-error-create-index-table-not-found --oracle/dbml-error.log +28 -0
  84. package/__tests__/sql2dbml/custom-error-table-comment-table-not-found --oracle/dbml-error.log +28 -0
  85. package/__tests__/sql2dbml/syntax-error/dbml-error.log +28 -0
  86. package/__tests__/sql2dbml/syntax-error-duplicate-endpoints --mssql/dbml-error.log +28 -0
  87. package/__tests__/sql2dbml/syntax-error-duplicate-endpoints --mysql/dbml-error.log +28 -0
  88. package/lib/index.js +25 -21
  89. package/package.json +4 -4
  90. package/src/NodeProjectLayout.ts +33 -7
  91. package/src/cli/export.ts +4 -5
  92. package/src/helpers/logger.ts +14 -5
@@ -144,3 +144,31 @@ undefined
144
144
 
145
145
  You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
146
146
 
147
+ 2026-05-14T03:41:53.317Z
148
+
149
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
150
+
151
+ 2026-05-14T03:43:55.244Z
152
+
153
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
154
+
155
+ 2026-05-14T03:45:15.351Z
156
+
157
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
158
+
159
+ 2026-05-14T08:28:24.134Z
160
+
161
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
162
+
163
+ 2026-05-14T08:29:49.707Z
164
+
165
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
166
+
167
+ 2026-05-14T08:36:36.321Z
168
+
169
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
170
+
171
+ 2026-05-14T08:47:47.513Z
172
+
173
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
174
+
@@ -144,3 +144,31 @@ undefined
144
144
 
145
145
  You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
146
146
 
147
+ 2026-05-14T03:41:54.894Z
148
+
149
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
150
+
151
+ 2026-05-14T03:43:56.772Z
152
+
153
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
154
+
155
+ 2026-05-14T03:45:16.925Z
156
+
157
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
158
+
159
+ 2026-05-14T08:28:25.510Z
160
+
161
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
162
+
163
+ 2026-05-14T08:29:51.069Z
164
+
165
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
166
+
167
+ 2026-05-14T08:36:37.746Z
168
+
169
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
170
+
171
+ 2026-05-14T08:47:48.962Z
172
+
173
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
174
+
@@ -131,3 +131,31 @@ undefined
131
131
 
132
132
  You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
133
133
 
134
+ 2026-05-14T03:42:28.003Z
135
+
136
+ You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
137
+
138
+ 2026-05-14T03:44:33.319Z
139
+
140
+ You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
141
+
142
+ 2026-05-14T03:45:49.962Z
143
+
144
+ You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
145
+
146
+ 2026-05-14T08:28:55.830Z
147
+
148
+ You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
149
+
150
+ 2026-05-14T08:30:20.740Z
151
+
152
+ You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
153
+
154
+ 2026-05-14T08:37:08.659Z
155
+
156
+ You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
157
+
158
+ 2026-05-14T08:48:19.263Z
159
+
160
+ You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
161
+
@@ -128,3 +128,31 @@ undefined
128
128
 
129
129
  You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
130
130
 
131
+ 2026-05-14T03:42:29.627Z
132
+
133
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
134
+
135
+ 2026-05-14T03:44:35.200Z
136
+
137
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
138
+
139
+ 2026-05-14T03:45:51.427Z
140
+
141
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
142
+
143
+ 2026-05-14T08:28:57.422Z
144
+
145
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
146
+
147
+ 2026-05-14T08:30:22.205Z
148
+
149
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
150
+
151
+ 2026-05-14T08:37:10.193Z
152
+
153
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
154
+
155
+ 2026-05-14T08:48:20.688Z
156
+
157
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
158
+
@@ -124,3 +124,31 @@ undefined
124
124
 
125
125
  You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
126
126
 
127
+ 2026-05-14T03:42:31.059Z
128
+
129
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
130
+
131
+ 2026-05-14T03:44:37.478Z
132
+
133
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
134
+
135
+ 2026-05-14T03:45:52.813Z
136
+
137
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
138
+
139
+ 2026-05-14T08:28:58.786Z
140
+
141
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
142
+
143
+ 2026-05-14T08:30:23.569Z
144
+
145
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
146
+
147
+ 2026-05-14T08:37:11.577Z
148
+
149
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
150
+
151
+ 2026-05-14T08:48:22.035Z
152
+
153
+ You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
154
+
package/lib/index.js CHANGED
@@ -29,8 +29,6 @@ let chalk = require("chalk");
29
29
  chalk = __toESM(chalk);
30
30
  let figures = require("figures");
31
31
  figures = __toESM(figures);
32
- let strip_ansi = require("strip-ansi");
33
- strip_ansi = __toESM(strip_ansi);
34
32
  let winston = require("winston");
35
33
  let fs = require("fs");
36
34
  fs = __toESM(fs);
@@ -38,7 +36,7 @@ let __dbml_parse = require("@dbml/parse");
38
36
  let node_fs = require("node:fs");
39
37
  const $schema = "https://json.schemastore.org/package";
40
38
  const name = "@dbml/cli";
41
- const version = "8.0.0-alpha.12";
39
+ const version = "8.0.0-alpha.15";
42
40
  const description = "";
43
41
  const main = "lib/index.js";
44
42
  const license = "Apache-2.0";
@@ -65,8 +63,8 @@ const keywords = ["dbml", "dbml-cli"];
65
63
  const dependencies = {
66
64
  "@babel/cli": "^7.21.0",
67
65
  "@dbml/connector": "^8.0.0-alpha.0",
68
- "@dbml/core": "^8.0.0-alpha.12",
69
- "@dbml/parse": "^8.0.0-alpha.12",
66
+ "@dbml/core": "^8.0.0-alpha.13",
67
+ "@dbml/parse": "^8.0.0-alpha.15",
70
68
  "bluebird": "^3.5.5",
71
69
  "chalk": "^2.4.2",
72
70
  "commander": "^2.20.0",
@@ -77,7 +75,7 @@ const dependencies = {
77
75
  "strip-ansi": "^5.2.0",
78
76
  "winston": "^3.2.1"
79
77
  };
80
- const gitHead = "53557d9ec226c4e7b8177229efce49594535502b";
78
+ const gitHead = "a28fb18cf7ea979a81ef65774ef5271f285766d2";
81
79
  const engines = { "node": ">=18" };
82
80
  var package_default = {
83
81
  $schema,
@@ -106,7 +104,7 @@ var consoleFormat = printf((info) => {
106
104
  });
107
105
  var fileFormat = printf((info) => {
108
106
  const { timestamp: ts, message, stack, rootError } = info;
109
- let logContent = `${ts}\n${(0, strip_ansi.default)(stack ?? message ?? "")}\n`;
107
+ let logContent = `${ts}\n${stack ?? message ?? ""}\n`;
110
108
  if (rootError) {
111
109
  logContent += "\nROOT_ERROR:";
112
110
  logContent += `\n${rootError.stack}`;
@@ -120,7 +118,7 @@ var consoleLogger = (0, winston.createLogger)({
120
118
  transports: [new winston.transports.Console({ level: "error" })]
121
119
  });
122
120
  var fileLogger = (0, winston.createLogger)({
123
- format: combine(timestamp(), fileFormat),
121
+ format: combine(timestamp(), winston.format.uncolorize(), fileFormat),
124
122
  transports: [new winston.transports.File({
125
123
  filename: "dbml-error.log",
126
124
  level: "error"
@@ -136,9 +134,12 @@ var logger = {
136
134
  warn(msg) {
137
135
  consoleLogger.warn(msg);
138
136
  },
139
- error(msg) {
140
- consoleLogger.error(msg);
141
- fileLogger.error(msg);
137
+ error(msg, { console: toConsole, file: toFile } = {
138
+ console: true,
139
+ file: true
140
+ }) {
141
+ if (toConsole) consoleLogger.error(msg);
142
+ if (toFile) fileLogger.error(msg);
142
143
  }
143
144
  };
144
145
  var logger_default = logger;
@@ -1187,7 +1188,8 @@ var NodeProjectLayout = class {
1187
1188
  getSource(filePath) {
1188
1189
  try {
1189
1190
  return (0, node_fs.readFileSync)(filePath.absolute, "utf-8");
1190
- } catch {
1191
+ } catch (e) {
1192
+ logger_default.error(e instanceof Error ? e : new Error(String(e)), { file: true });
1191
1193
  return;
1192
1194
  }
1193
1195
  }
@@ -1196,15 +1198,17 @@ var NodeProjectLayout = class {
1196
1198
  }
1197
1199
  isFile(filePath) {
1198
1200
  try {
1199
- return (0, node_fs.statSync)(filePath.absolute).isFile();
1200
- } catch {
1201
+ return (0, node_fs.statSync)(filePath.absolute, { throwIfNoEntry: false })?.isFile() ?? false;
1202
+ } catch (e) {
1203
+ logger_default.error(e instanceof Error ? e : new Error(String(e)), { file: true });
1201
1204
  return false;
1202
1205
  }
1203
1206
  }
1204
1207
  isDirectory(filePath) {
1205
1208
  try {
1206
- return (0, node_fs.statSync)(filePath.absolute).isDirectory();
1207
- } catch {
1209
+ return (0, node_fs.statSync)(filePath.absolute, { throwIfNoEntry: false })?.isDirectory() ?? false;
1210
+ } catch (e) {
1211
+ logger_default.error(e instanceof Error ? e : new Error(String(e)), { file: true });
1208
1212
  return false;
1209
1213
  }
1210
1214
  }
@@ -1212,7 +1216,8 @@ var NodeProjectLayout = class {
1212
1216
  const basePath = dirPath?.absolute ?? "/";
1213
1217
  try {
1214
1218
  return (0, node_fs.readdirSync)(basePath).map((entry) => basePath + entry).sort().map(__dbml_parse.Filepath.from);
1215
- } catch {
1219
+ } catch (e) {
1220
+ logger_default.error(e instanceof Error ? e : new Error(String(e)), { file: true });
1216
1221
  return [];
1217
1222
  }
1218
1223
  }
@@ -1238,16 +1243,15 @@ async function exportHandler(program$1) {
1238
1243
  validateInputFilePaths(inputPaths, validateFilePlugin);
1239
1244
  const opts = program$1.opts();
1240
1245
  const format$1 = getFormatOpt(opts);
1241
- const entryPoints = inputPaths.map((p) => new __dbml_parse.Filepath(p));
1242
- const compiler = new __dbml_parse.Compiler();
1243
- compiler.layout = new NodeProjectLayout(entryPoints);
1246
+ const entrypoints = inputPaths.map((p) => new __dbml_parse.Filepath(p));
1247
+ const compiler = new __dbml_parse.Compiler(new NodeProjectLayout(entrypoints));
1244
1248
  const outputPlugin = opts.outFile ? new outputFilePlugin_default(resolvePaths(opts.outFile), [
1245
1249
  "-- SQL dump generated using DBML (dbml.dbdiagram.io)\n",
1246
1250
  `-- Database: ${config_default[format$1].name}\n`,
1247
1251
  `-- Generated at: ${(/* @__PURE__ */ new Date()).toISOString()}\n\n`
1248
1252
  ].join("")) : outputConsolePlugin_default;
1249
1253
  let hasErrors = false;
1250
- for (const filepath of entryPoints) {
1254
+ for (const filepath of entrypoints) {
1251
1255
  const result = compiler.interpretFile(filepath);
1252
1256
  const errors = result.getErrors();
1253
1257
  if (errors.length > 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/cli",
4
- "version": "8.0.0-alpha.12",
4
+ "version": "8.0.0-alpha.15",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "license": "Apache-2.0",
@@ -33,8 +33,8 @@
33
33
  "dependencies": {
34
34
  "@babel/cli": "^7.21.0",
35
35
  "@dbml/connector": "^8.0.0-alpha.0",
36
- "@dbml/core": "^8.0.0-alpha.12",
37
- "@dbml/parse": "^8.0.0-alpha.12",
36
+ "@dbml/core": "^8.0.0-alpha.13",
37
+ "@dbml/parse": "^8.0.0-alpha.15",
38
38
  "bluebird": "^3.5.5",
39
39
  "chalk": "^2.4.2",
40
40
  "commander": "^2.20.0",
@@ -45,7 +45,7 @@
45
45
  "strip-ansi": "^5.2.0",
46
46
  "winston": "^3.2.1"
47
47
  },
48
- "gitHead": "53557d9ec226c4e7b8177229efce49594535502b",
48
+ "gitHead": "a28fb18cf7ea979a81ef65774ef5271f285766d2",
49
49
  "engines": {
50
50
  "node": ">=18"
51
51
  }
@@ -4,12 +4,20 @@ import {
4
4
  import {
5
5
  type DbmlProjectLayout, Filepath,
6
6
  } from '@dbml/parse';
7
+ import logger from './helpers/logger';
7
8
 
8
9
  /**
9
10
  * A read-only DbmlProjectLayout backed by the Node.js filesystem.
11
+ *
12
+ * getSource -> fs.readFileSync
13
+ * exists -> statSync (isFile || isDirectory)
14
+ * isFile -> statSync().isFile()
15
+ * isDirectory -> statSync().isDirectory()
16
+ * listDirectory -> fs.readdirSync
17
+ * getEntrypoints -> filtered constructor arg
10
18
  */
11
19
  export class NodeProjectLayout implements DbmlProjectLayout {
12
- private entryPoints: Filepath[];
20
+ private readonly entryPoints: Filepath[];
13
21
 
14
22
  constructor (entryPoints: Filepath[]) {
15
23
  this.entryPoints = [...entryPoints];
@@ -18,7 +26,10 @@ export class NodeProjectLayout implements DbmlProjectLayout {
18
26
  getSource (filePath: Filepath): string | undefined {
19
27
  try {
20
28
  return readFileSync(filePath.absolute, 'utf-8');
21
- } catch {
29
+ } catch (e) {
30
+ logger.error(e instanceof Error ? e : new Error(String(e)), {
31
+ file: true,
32
+ });
22
33
  return undefined;
23
34
  }
24
35
  }
@@ -29,16 +40,28 @@ export class NodeProjectLayout implements DbmlProjectLayout {
29
40
 
30
41
  isFile (filePath: Filepath): boolean {
31
42
  try {
32
- return statSync(filePath.absolute).isFile();
33
- } catch {
43
+ const stat = statSync(filePath.absolute, {
44
+ throwIfNoEntry: false,
45
+ });
46
+ return stat?.isFile() ?? false;
47
+ } catch (e) {
48
+ logger.error(e instanceof Error ? e : new Error(String(e)), {
49
+ file: true,
50
+ });
34
51
  return false;
35
52
  }
36
53
  }
37
54
 
38
55
  isDirectory (filePath: Filepath): boolean {
39
56
  try {
40
- return statSync(filePath.absolute).isDirectory();
41
- } catch {
57
+ const stat = statSync(filePath.absolute, {
58
+ throwIfNoEntry: false,
59
+ });
60
+ return stat?.isDirectory() ?? false;
61
+ } catch (e) {
62
+ logger.error(e instanceof Error ? e : new Error(String(e)), {
63
+ file: true,
64
+ });
42
65
  return false;
43
66
  }
44
67
  }
@@ -50,7 +73,10 @@ export class NodeProjectLayout implements DbmlProjectLayout {
50
73
  .map((entry) => basePath + entry)
51
74
  .sort()
52
75
  .map(Filepath.from);
53
- } catch {
76
+ } catch (e) {
77
+ logger.error(e instanceof Error ? e : new Error(String(e)), {
78
+ file: true,
79
+ });
54
80
  return [];
55
81
  }
56
82
  }
package/src/cli/export.ts CHANGED
@@ -32,9 +32,8 @@ export default async function exportHandler (program: Command): Promise<void> {
32
32
  const opts = program.opts();
33
33
  const format = getFormatOpt(opts);
34
34
 
35
- const entryPoints = inputPaths.map((p: string) => new Filepath(p));
36
- const compiler = new Compiler();
37
- compiler.layout = new NodeProjectLayout(entryPoints);
35
+ const entrypoints = inputPaths.map((p: string) => new Filepath(p));
36
+ const compiler = new Compiler(new NodeProjectLayout(entrypoints));
38
37
 
39
38
  const outputPlugin = opts.outFile
40
39
  ? new OutputFilePlugin(
@@ -49,13 +48,13 @@ export default async function exportHandler (program: Command): Promise<void> {
49
48
 
50
49
  let hasErrors = false;
51
50
 
52
- for (const filepath of entryPoints) {
51
+ for (const filepath of entrypoints) {
53
52
  const result = compiler.interpretFile(filepath);
54
53
  const errors = result.getErrors();
55
54
 
56
55
  if (errors.length > 0) {
57
56
  hasErrors = true;
58
- const isMultifile = compiler.reachableFiles(filepath).length > 1;
57
+ const isMultifile = compiler.reachableFiles(filepath).length > 1; // If this filepath can reach other files, it's mutifile
59
58
  logger.error(
60
59
  `\n ${errors
61
60
  .map((e) => {
@@ -1,6 +1,5 @@
1
1
  import path from 'path';
2
2
  import chalk from 'chalk';
3
- import stripAnsi from 'strip-ansi';
4
3
  import {
5
4
  createLogger, format, transports,
6
5
  } from 'winston';
@@ -22,7 +21,7 @@ const fileFormat = printf((info) => {
22
21
  const {
23
22
  timestamp: ts, message, stack, rootError,
24
23
  } = info as any;
25
- let logContent = `${ts}\n${stripAnsi(stack ?? message ?? '')}\n`;
24
+ let logContent = `${ts}\n${stack ?? message ?? ''}\n`;
26
25
  if (rootError) {
27
26
  logContent += '\nROOT_ERROR:';
28
27
  logContent += `\n${rootError.stack}`;
@@ -48,6 +47,7 @@ const consoleLogger = createLogger({
48
47
  const fileLogger = createLogger({
49
48
  format: combine(
50
49
  timestamp(),
50
+ format.uncolorize(),
51
51
  fileFormat,
52
52
  ),
53
53
  transports: [
@@ -69,9 +69,18 @@ const logger = {
69
69
  consoleLogger.warn(msg);
70
70
  },
71
71
 
72
- error (msg: Error | string) {
73
- consoleLogger.error(msg);
74
- fileLogger.error(msg);
72
+ error (msg: Error | string, {
73
+ console: toConsole,
74
+ file: toFile,
75
+ }: {
76
+ console?: boolean;
77
+ file?: boolean;
78
+ } = {
79
+ console: true,
80
+ file: true,
81
+ }) {
82
+ if (toConsole) consoleLogger.error(msg);
83
+ if (toFile) fileLogger.error(msg);
75
84
  },
76
85
  };
77
86