@drzl/cli 4.14.1 → 4.14.2

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/dist/cli.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";var __drzlModuleUrl = require("node:url").pathToFileURL(__filename).href;
2
3
  "use strict";
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
@@ -278,15 +279,15 @@ var init_dist = __esm({
278
279
  }
279
280
  async generate(opts) {
280
281
  const fs3 = await import("fs/promises");
281
- const path5 = await import("path");
282
- const out = path5.resolve(process.cwd(), opts.outDir);
282
+ const path6 = await import("path");
283
+ const out = path6.resolve(process.cwd(), opts.outDir);
283
284
  const files = [];
284
285
  await fs3.mkdir(out, { recursive: true });
285
286
  const affix = (0, import_validation_core2.resolveAffix)(opts);
286
287
  const fileSuffix = opts.fileSuffix ?? DEFAULT_FILE_SUFFIX;
287
288
  const target = opts.target ?? "draft-2020-12";
288
289
  for (const table of this.analysis.tables) {
289
- const filePath = path5.join(out, (0, import_validation_core2.moduleFileName)(table.tsName, fileSuffix));
290
+ const filePath = path6.join(out, (0, import_validation_core2.moduleFileName)(table.tsName, fileSuffix));
290
291
  const code = renderTableModule(table, affix, target, !!opts.applyDefaults);
291
292
  const formatted = await (0, import_validation_core2.formatCode)(
292
293
  buildHeader(opts.outputHeader) + code,
@@ -301,7 +302,7 @@ var init_dist = __esm({
301
302
  target,
302
303
  applyDefaults: !!opts.applyDefaults
303
304
  });
304
- const componentsPath = path5.join(out, "components.ts");
305
+ const componentsPath = path6.join(out, "components.ts");
305
306
  const code = `export const components = ${JSON.stringify(doc, null, 2)} as const;
306
307
  `;
307
308
  await fs3.writeFile(
@@ -311,7 +312,7 @@ var init_dist = __esm({
311
312
  );
312
313
  files.push(componentsPath);
313
314
  }
314
- const indexPath = path5.join(out, "index.ts");
315
+ const indexPath = path6.join(out, "index.ts");
315
316
  const index = this.analysis.tables.map((t) => `export * from '${(0, import_validation_core2.moduleSpecifier)(t.tsName, fileSuffix, opts.importExtension)}';`).concat(
316
317
  opts.components ? [`export * from './components${opts.importExtension === "none" ? "" : ".js"}';`] : []
317
318
  ).join("\n") + "\n";
@@ -344,7 +345,7 @@ var import_chalk2 = __toESM(require("chalk"), 1);
344
345
  var import_chokidar = __toESM(require("chokidar"), 1);
345
346
  var import_cli_progress = __toESM(require("cli-progress"), 1);
346
347
  var import_commander = require("commander");
347
- var path4 = __toESM(require("path"), 1);
348
+ var path5 = __toESM(require("path"), 1);
348
349
  var import_ora = __toESM(require("ora"), 1);
349
350
 
350
351
  // src/validation-options.ts
@@ -836,9 +837,42 @@ function writeCache(payload) {
836
837
  (0, import_node_fs2.writeFileSync)(CACHE_FILE, JSON.stringify(payload, null, 2), "utf8");
837
838
  }
838
839
 
840
+ // src/version.ts
841
+ var import_node_fs3 = require("fs");
842
+ var path4 = __toESM(require("path"), 1);
843
+ var import_node_url = require("url");
844
+ var PACKAGE_NAME = "@drzl/cli";
845
+ function moduleDir() {
846
+ return path4.dirname((0, import_node_url.fileURLToPath)(__drzlModuleUrl));
847
+ }
848
+ function readVersionFrom(manifestPath) {
849
+ let raw;
850
+ try {
851
+ raw = (0, import_node_fs3.readFileSync)(manifestPath, "utf8");
852
+ } catch (e) {
853
+ throw new Error(
854
+ `${PACKAGE_NAME} cannot read its own version: no manifest at ${manifestPath} (${e?.message ?? String(e)}).`
855
+ );
856
+ }
857
+ const manifest = JSON.parse(raw);
858
+ if (manifest.name !== PACKAGE_NAME) {
859
+ throw new Error(
860
+ `${PACKAGE_NAME} looked for its own version in ${manifestPath} and found ${JSON.stringify(manifest.name)}, so this build is not sitting where it thinks it is.`
861
+ );
862
+ }
863
+ if (typeof manifest.version !== "string" || manifest.version.length === 0) {
864
+ throw new Error(`${manifestPath} declares no version, so there is nothing to report.`);
865
+ }
866
+ return manifest.version;
867
+ }
868
+ function readCliVersion() {
869
+ return readVersionFrom(path4.join(moduleDir(), "..", "package.json"));
870
+ }
871
+ var CLI_VERSION = readCliVersion();
872
+
839
873
  // src/cli.ts
840
874
  var program = new import_commander.Command();
841
- program.name("drzl").description("DRZL - Drizzle Developer Toolkit").version("0.0.1");
875
+ program.name("drzl").description("DRZL - Drizzle Developer Toolkit").version(CLI_VERSION);
842
876
  program.addHelpText(
843
877
  "afterAll",
844
878
  `
@@ -1078,7 +1112,7 @@ Generated output is out of date (${drift.length} file(s)):`));
1078
1112
  for (const d of drift) {
1079
1113
  const mark = d.status === "added" ? "+" : d.status === "removed" ? "-" : "~";
1080
1114
  console.error(
1081
- ` ${mark} ${import_chalk2.default.yellow(d.status.padEnd(8))} ${path4.relative(process.cwd(), d.file)}`
1115
+ ` ${mark} ${import_chalk2.default.yellow(d.status.padEnd(8))} ${path5.relative(process.cwd(), d.file)}`
1082
1116
  );
1083
1117
  }
1084
1118
  console.error(
@@ -1130,10 +1164,10 @@ program.command("watch").description("Watch schema and regenerate on changes").o
1130
1164
  process.exit(2);
1131
1165
  return;
1132
1166
  }
1133
- const abs = (p) => path4.resolve(process.cwd(), p);
1167
+ const abs = (p) => path5.resolve(process.cwd(), p);
1134
1168
  const isInside = (child, parent) => {
1135
- const rel = path4.relative(parent, child);
1136
- return !!rel && !rel.startsWith("..") && !path4.isAbsolute(rel);
1169
+ const rel = path5.relative(parent, child);
1170
+ return !!rel && !rel.startsWith("..") && !path5.isAbsolute(rel);
1137
1171
  };
1138
1172
  const ignoredOutDirs = new Set(computeGeneratorOutputDirs(cfg).map(abs));
1139
1173
  const currentTargets = new Set(computeWatchTargets(cfg).map(abs));
@@ -1158,7 +1192,7 @@ program.command("watch").description("Watch schema and regenerate on changes").o
1158
1192
  if (full === dir || isInside(full, dir)) return true;
1159
1193
  }
1160
1194
  if (stats?.isDirectory()) return false;
1161
- const ext = path4.extname(full);
1195
+ const ext = path5.extname(full);
1162
1196
  if (!ext) return false;
1163
1197
  return !WATCHED_EXTENSIONS.has(ext);
1164
1198
  };
@@ -1393,7 +1427,7 @@ program.command("watch").description("Watch schema and regenerate on changes").o
1393
1427
  } else {
1394
1428
  console.log(
1395
1429
  import_chalk2.default.gray(
1396
- "Watching:\n " + Array.from(currentTargets).map((p) => path4.relative(process.cwd(), p)).join("\n ")
1430
+ "Watching:\n " + Array.from(currentTargets).map((p) => path5.relative(process.cwd(), p)).join("\n ")
1397
1431
  )
1398
1432
  );
1399
1433
  }
@@ -1402,8 +1436,8 @@ program.command("watch").description("Watch schema and regenerate on changes").o
1402
1436
  });
1403
1437
  program.command("init").description("Scaffold a drzl.config.ts").option("-y, --yes", "accept defaults").action(async (_opts) => {
1404
1438
  const fs3 = await import("fs/promises");
1405
- const path5 = await import("path");
1406
- const target = path5.resolve(process.cwd(), "drzl.config.ts");
1439
+ const path6 = await import("path");
1440
+ const target = path6.resolve(process.cwd(), "drzl.config.ts");
1407
1441
  const template = `export default {
1408
1442
  schema: 'src/db/schema.ts',
1409
1443
  outDir: 'src/api',