zenstack-kit 0.1.8 → 0.1.10

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 CHANGED
@@ -102,7 +102,10 @@ Migrations are tracked in the `_prisma_migrations` table, making them compatible
102
102
 
103
103
  ## CLI Commands
104
104
 
105
- Run `zenstack-kit` without arguments to launch the interactive menu, or run commands directly.
105
+ Run `zenstack-kit` without arguments to launch the interactive menu, or run commands directly. For CI or non-TTY environments, pass `--no-ui` to bypass Ink.
106
+
107
+ Global options:
108
+ - `--no-ui` - Disable Ink UI (useful for CI/non-TTY)
106
109
 
107
110
  ### `zenstack-kit init`
108
111
 
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/cli/app.tsx"],"names":[],"mappings":";AAEA;;;;;;;;;GASG;AAuTH,wBAAgB,MAAM,SAkBrB"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/cli/app.tsx"],"names":[],"mappings":";AAEA;;;;;;;;;GASG;AAgYH,wBAAgB,MAAM,SA4BrB"}
package/dist/cli/app.js CHANGED
@@ -59,6 +59,9 @@ function parseArgs() {
59
59
  else if (arg === "--migration") {
60
60
  options.migration = args[++i];
61
61
  }
62
+ else if (arg === "--no-ui") {
63
+ options.noUi = true;
64
+ }
62
65
  else if (arg === "--dialect") {
63
66
  options.dialect = args[++i];
64
67
  }
@@ -113,7 +116,7 @@ function Status({ type, message }) {
113
116
  }
114
117
  // Help display component
115
118
  function HelpDisplay() {
116
- return (_jsxs(Box, { flexDirection: "column", paddingY: 1, children: [_jsx(Text, { bold: true, color: "cyan", children: "zenstack-kit" }), _jsx(Text, { dimColor: true, children: "Database tooling for ZenStack schemas" }), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: "Commands:" }), commands.filter(c => c.value !== "exit").map((cmd) => (_jsxs(Box, { marginLeft: 2, children: [_jsx(Box, { width: 20, children: _jsx(Text, { color: "yellow", children: cmd.label }) }), _jsx(Text, { dimColor: true, children: cmd.description })] }, cmd.value))), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: "Options:" }), _jsxs(Box, { marginLeft: 2, flexDirection: "column", children: [_jsx(Text, { dimColor: true, children: "-s, --schema <path> Path to ZenStack schema" }), _jsx(Text, { dimColor: true, children: "-m, --migrations <path> Migrations directory" }), _jsx(Text, { dimColor: true, children: "-n, --name <name> Migration name" }), _jsx(Text, { dimColor: true, children: "--dialect <dialect> Database dialect (sqlite, postgres, mysql)" }), _jsx(Text, { dimColor: true, children: "--url <url> Database connection URL" }), _jsx(Text, { dimColor: true, children: "--migration <name> Target a single migration (rehash only)" }), _jsx(Text, { dimColor: true, children: "--create-initial Create initial migration (skip prompt)" }), _jsx(Text, { dimColor: true, children: "--baseline Create baseline only (skip prompt)" }), _jsx(Text, { dimColor: true, children: "--preview Preview pending migrations without applying" }), _jsx(Text, { dimColor: true, children: "--mark-applied Mark pending migrations as applied without running SQL" }), _jsx(Text, { dimColor: true, children: "-f, --force Force operation without confirmation" }), _jsx(Text, { dimColor: true, children: "-c, --config <path> Path to zenstack-kit config file" })] })] }));
119
+ return (_jsxs(Box, { flexDirection: "column", paddingY: 1, children: [_jsx(Text, { bold: true, color: "cyan", children: "zenstack-kit" }), _jsx(Text, { dimColor: true, children: "Database tooling for ZenStack schemas" }), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: "Commands:" }), commands.filter(c => c.value !== "exit").map((cmd) => (_jsxs(Box, { marginLeft: 2, children: [_jsx(Box, { width: 20, children: _jsx(Text, { color: "yellow", children: cmd.label }) }), _jsx(Text, { dimColor: true, children: cmd.description })] }, cmd.value))), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: "Options:" }), _jsxs(Box, { marginLeft: 2, flexDirection: "column", children: [_jsx(Text, { dimColor: true, children: "-s, --schema <path> Path to ZenStack schema" }), _jsx(Text, { dimColor: true, children: "-m, --migrations <path> Migrations directory" }), _jsx(Text, { dimColor: true, children: "-n, --name <name> Migration name" }), _jsx(Text, { dimColor: true, children: "--dialect <dialect> Database dialect (sqlite, postgres, mysql)" }), _jsx(Text, { dimColor: true, children: "--url <url> Database connection URL" }), _jsx(Text, { dimColor: true, children: "--migration <name> Target a single migration (rehash only)" }), _jsx(Text, { dimColor: true, children: "--no-ui Disable Ink UI (useful for CI/non-TTY)" }), _jsx(Text, { dimColor: true, children: "--create-initial Create initial migration (skip prompt)" }), _jsx(Text, { dimColor: true, children: "--baseline Create baseline only (skip prompt)" }), _jsx(Text, { dimColor: true, children: "--preview Preview pending migrations without applying" }), _jsx(Text, { dimColor: true, children: "--mark-applied Mark pending migrations as applied without running SQL" }), _jsx(Text, { dimColor: true, children: "-f, --force Force operation without confirmation" }), _jsx(Text, { dimColor: true, children: "-c, --config <path> Path to zenstack-kit config file" })] })] }));
117
120
  }
118
121
  function CliApp({ initialCommand, options }) {
119
122
  const { exit } = useApp();
@@ -233,9 +236,83 @@ function CliApp({ initialCommand, options }) {
233
236
  });
234
237
  return (_jsxs(Box, { flexDirection: "column", paddingY: 1, children: [phase === "select" && (_jsxs(_Fragment, { children: [_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { bold: true, color: "cyan", children: "zenstack-kit" }), _jsx(Text, { dimColor: true, children: " - Select a command" })] }), _jsx(SelectInput, { items: commands, onSelect: handleSelect })] })), command === "help" && _jsx(HelpDisplay, {}), logs.map((l, i) => (_jsx(Status, { type: l.type, message: l.message }, i))), phase === "done" && command !== "help" && !initialCommand && !logs.some((l) => l.type === "error") && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Press Enter to continue, 'q' or Escape to exit" }) }))] }));
235
238
  }
239
+ function printHelpText() {
240
+ const lines = [
241
+ "zenstack-kit",
242
+ "Database tooling for ZenStack schemas",
243
+ "",
244
+ "Commands:",
245
+ " migrate create Generate a new SQL migration file",
246
+ " migrate apply Apply pending SQL migrations",
247
+ " migrate rehash Rebuild migration log checksums",
248
+ " init Initialize snapshot from existing schema",
249
+ " pull Introspect database and generate schema",
250
+ " help Show help information",
251
+ "",
252
+ "Options:",
253
+ " -s, --schema <path> Path to ZenStack schema",
254
+ " -m, --migrations <path> Migrations directory",
255
+ " -n, --name <name> Migration name",
256
+ " --dialect <dialect> Database dialect (sqlite, postgres, mysql)",
257
+ " --url <url> Database connection URL",
258
+ " --migration <name> Target a single migration (rehash only)",
259
+ " --no-ui Disable Ink UI (useful for CI/non-TTY)",
260
+ " --create-initial Create initial migration (skip prompt)",
261
+ " --baseline Create baseline only (skip prompt)",
262
+ " --preview Preview pending migrations without applying",
263
+ " --mark-applied Mark pending migrations as applied without running SQL",
264
+ " -f, --force Force operation without confirmation",
265
+ " -c, --config <path> Path to zenstack-kit config file",
266
+ ];
267
+ console.log(lines.join("\n"));
268
+ }
269
+ async function runCommandDirect(command, options) {
270
+ const log = (type, message) => {
271
+ const prefix = type === "error" ? "✗" : type === "success" ? "✓" : type === "warning" ? "⚠" : "ℹ";
272
+ const line = `${prefix} ${message}`;
273
+ if (type === "error") {
274
+ console.error(line);
275
+ }
276
+ else {
277
+ console.log(line);
278
+ }
279
+ };
280
+ const ctx = {
281
+ cwd: process.cwd(),
282
+ options,
283
+ log,
284
+ };
285
+ try {
286
+ if (command === "migrate create") {
287
+ await runMigrateGenerate(ctx);
288
+ }
289
+ else if (command === "migrate apply") {
290
+ await runMigrateApply(ctx);
291
+ }
292
+ else if (command === "migrate rehash") {
293
+ await runMigrateRehash(ctx);
294
+ }
295
+ else if (command === "init") {
296
+ await runInit(ctx);
297
+ }
298
+ else if (command === "pull") {
299
+ await runPull(ctx);
300
+ }
301
+ }
302
+ catch (err) {
303
+ if (err instanceof CommandError) {
304
+ log("error", err.message);
305
+ }
306
+ else {
307
+ log("error", `Error: ${err instanceof Error ? err.message : String(err)}`);
308
+ }
309
+ process.exitCode = 1;
310
+ }
311
+ }
236
312
  // Entry point
237
313
  export function runCli() {
238
314
  const { command, options } = parseArgs();
315
+ const isInteractive = Boolean(process.stdout.isTTY) && !options.noUi;
239
316
  // Show version
240
317
  if (process.argv.includes("--version") || process.argv.includes("-v")) {
241
318
  console.log("0.1.0");
@@ -243,8 +320,17 @@ export function runCli() {
243
320
  }
244
321
  // Show help if no command or --help/-h flag
245
322
  if (!command || process.argv.includes("--help") || process.argv.includes("-h")) {
246
- const { waitUntilExit } = render(_jsx(HelpDisplay, {}));
247
- waitUntilExit().then(() => process.exit(0));
323
+ if (isInteractive) {
324
+ const { waitUntilExit } = render(_jsx(HelpDisplay, {}));
325
+ waitUntilExit().then(() => process.exit(0));
326
+ }
327
+ else {
328
+ printHelpText();
329
+ }
330
+ return;
331
+ }
332
+ if (!isInteractive) {
333
+ void runCommandDirect(command, options);
248
334
  return;
249
335
  }
250
336
  const { waitUntilExit } = render(_jsx(CliApp, { initialCommand: command, options: options }));
@@ -12,6 +12,7 @@ export interface CommandOptions {
12
12
  migrations?: string;
13
13
  name?: string;
14
14
  migration?: string;
15
+ noUi?: boolean;
15
16
  dialect?: string;
16
17
  url?: string;
17
18
  output?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAuBH,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAE9F,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EA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C,CAyGhE"}
@@ -248,7 +248,7 @@ export async function applyPrismaMigrations(options) {
248
248
  // Read migration folders
249
249
  const entries = await fs.readdir(options.migrationsFolder, { withFileTypes: true });
250
250
  const migrationFolders = entries
251
- .filter((e) => e.isDirectory() && /^\d{14}_/.test(e.name))
251
+ .filter((e) => e.isDirectory() && /^\d{14}(?:_.+)?$/.test(e.name))
252
252
  .map((e) => e.name)
253
253
  .sort();
254
254
  const migrationFoldersWithSql = [];
@@ -352,7 +352,7 @@ export async function previewPrismaMigrations(options) {
352
352
  // Read migration folders
353
353
  const entries = await fs.readdir(options.migrationsFolder, { withFileTypes: true });
354
354
  const migrationFolders = entries
355
- .filter((e) => e.isDirectory() && /^\d{14}_/.test(e.name))
355
+ .filter((e) => e.isDirectory() && /^\d{14}(?:_.+)?$/.test(e.name))
356
356
  .map((e) => e.name)
357
357
  .sort();
358
358
  const result = {
@@ -76,7 +76,7 @@ export async function scanMigrationFolders(outputPath) {
76
76
  try {
77
77
  const dirEntries = await fs.readdir(outputPath, { withFileTypes: true });
78
78
  const migrationFolders = dirEntries
79
- .filter((e) => e.isDirectory() && /^\d{14}_/.test(e.name))
79
+ .filter((e) => e.isDirectory() && /^\d{14}(?:_.+)?$/.test(e.name))
80
80
  .map((e) => e.name)
81
81
  .sort();
82
82
  for (const folderName of migrationFolders) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zenstack-kit",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Drizzle-kit like CLI tooling for ZenStack schemas with Kysely support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",