@drzl/cli 4.14.0 → 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/README.md +4 -1
- package/dist/cli.cjs +50 -15
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +44 -10
- package/dist/cli.js.map +1 -1
- package/dist/config.cjs +1 -0
- package/dist/config.cjs.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -52,4 +52,7 @@ export default defineConfig({
|
|
|
52
52
|
|
|
53
53
|
Notes
|
|
54
54
|
|
|
55
|
-
- `format.engine: 'auto'` tries Prettier, then Biome.
|
|
55
|
+
- `format.engine: 'auto'` tries Prettier, then Biome. Both are your own: neither is bundled, and
|
|
56
|
+
DRZL uses whichever it finds in your project, with your config. With neither installed the
|
|
57
|
+
generated files are written exactly as rendered, which is the same valid TypeScript with worse
|
|
58
|
+
whitespace. Add `prettier` as a dev dependency if you want it formatted.
|
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
|
|
282
|
-
const out =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
348
|
+
var path5 = __toESM(require("path"), 1);
|
|
348
349
|
var import_ora = __toESM(require("ora"), 1);
|
|
349
350
|
|
|
350
351
|
// src/validation-options.ts
|
|
@@ -779,6 +780,7 @@ var tips = [
|
|
|
779
780
|
"Pair DRZL watch mode with drizzle-kit to keep schema & API synced.",
|
|
780
781
|
"Templatize your ORPC routers to roll out new endpoints safely.",
|
|
781
782
|
"Need typed validators? Enable the zod, valibot, arktype, or typebox generators.",
|
|
783
|
+
"Need JSON Schema or OpenAPI? The json-schema generator emits both, with no runtime dependency.",
|
|
782
784
|
"Use output headers to track generated files and trim noisy diffs."
|
|
783
785
|
];
|
|
784
786
|
var green = (msg) => import_chalk.default.hex("#6ee7b7")(msg);
|
|
@@ -835,9 +837,42 @@ function writeCache(payload) {
|
|
|
835
837
|
(0, import_node_fs2.writeFileSync)(CACHE_FILE, JSON.stringify(payload, null, 2), "utf8");
|
|
836
838
|
}
|
|
837
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
|
+
|
|
838
873
|
// src/cli.ts
|
|
839
874
|
var program = new import_commander.Command();
|
|
840
|
-
program.name("drzl").description("DRZL - Drizzle Developer Toolkit").version(
|
|
875
|
+
program.name("drzl").description("DRZL - Drizzle Developer Toolkit").version(CLI_VERSION);
|
|
841
876
|
program.addHelpText(
|
|
842
877
|
"afterAll",
|
|
843
878
|
`
|
|
@@ -1077,7 +1112,7 @@ Generated output is out of date (${drift.length} file(s)):`));
|
|
|
1077
1112
|
for (const d of drift) {
|
|
1078
1113
|
const mark = d.status === "added" ? "+" : d.status === "removed" ? "-" : "~";
|
|
1079
1114
|
console.error(
|
|
1080
|
-
` ${mark} ${import_chalk2.default.yellow(d.status.padEnd(8))} ${
|
|
1115
|
+
` ${mark} ${import_chalk2.default.yellow(d.status.padEnd(8))} ${path5.relative(process.cwd(), d.file)}`
|
|
1081
1116
|
);
|
|
1082
1117
|
}
|
|
1083
1118
|
console.error(
|
|
@@ -1129,10 +1164,10 @@ program.command("watch").description("Watch schema and regenerate on changes").o
|
|
|
1129
1164
|
process.exit(2);
|
|
1130
1165
|
return;
|
|
1131
1166
|
}
|
|
1132
|
-
const abs = (p) =>
|
|
1167
|
+
const abs = (p) => path5.resolve(process.cwd(), p);
|
|
1133
1168
|
const isInside = (child, parent) => {
|
|
1134
|
-
const rel =
|
|
1135
|
-
return !!rel && !rel.startsWith("..") && !
|
|
1169
|
+
const rel = path5.relative(parent, child);
|
|
1170
|
+
return !!rel && !rel.startsWith("..") && !path5.isAbsolute(rel);
|
|
1136
1171
|
};
|
|
1137
1172
|
const ignoredOutDirs = new Set(computeGeneratorOutputDirs(cfg).map(abs));
|
|
1138
1173
|
const currentTargets = new Set(computeWatchTargets(cfg).map(abs));
|
|
@@ -1157,7 +1192,7 @@ program.command("watch").description("Watch schema and regenerate on changes").o
|
|
|
1157
1192
|
if (full === dir || isInside(full, dir)) return true;
|
|
1158
1193
|
}
|
|
1159
1194
|
if (stats?.isDirectory()) return false;
|
|
1160
|
-
const ext =
|
|
1195
|
+
const ext = path5.extname(full);
|
|
1161
1196
|
if (!ext) return false;
|
|
1162
1197
|
return !WATCHED_EXTENSIONS.has(ext);
|
|
1163
1198
|
};
|
|
@@ -1392,7 +1427,7 @@ program.command("watch").description("Watch schema and regenerate on changes").o
|
|
|
1392
1427
|
} else {
|
|
1393
1428
|
console.log(
|
|
1394
1429
|
import_chalk2.default.gray(
|
|
1395
|
-
"Watching:\n " + Array.from(currentTargets).map((p) =>
|
|
1430
|
+
"Watching:\n " + Array.from(currentTargets).map((p) => path5.relative(process.cwd(), p)).join("\n ")
|
|
1396
1431
|
)
|
|
1397
1432
|
);
|
|
1398
1433
|
}
|
|
@@ -1401,8 +1436,8 @@ program.command("watch").description("Watch schema and regenerate on changes").o
|
|
|
1401
1436
|
});
|
|
1402
1437
|
program.command("init").description("Scaffold a drzl.config.ts").option("-y, --yes", "accept defaults").action(async (_opts) => {
|
|
1403
1438
|
const fs3 = await import("fs/promises");
|
|
1404
|
-
const
|
|
1405
|
-
const target =
|
|
1439
|
+
const path6 = await import("path");
|
|
1440
|
+
const target = path6.resolve(process.cwd(), "drzl.config.ts");
|
|
1406
1441
|
const template = `export default {
|
|
1407
1442
|
schema: 'src/db/schema.ts',
|
|
1408
1443
|
outDir: 'src/api',
|