@beignet/cli 0.0.3 → 0.0.5

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 (138) hide show
  1. package/CHANGELOG.md +219 -0
  2. package/README.md +379 -61
  3. package/dist/ansi.d.ts +10 -0
  4. package/dist/ansi.d.ts.map +1 -0
  5. package/dist/ansi.js +20 -0
  6. package/dist/ansi.js.map +1 -0
  7. package/dist/choices.d.ts +49 -0
  8. package/dist/choices.d.ts.map +1 -0
  9. package/dist/choices.js +53 -0
  10. package/dist/choices.js.map +1 -0
  11. package/dist/completion.d.ts +47 -0
  12. package/dist/completion.d.ts.map +1 -0
  13. package/dist/completion.js +123 -0
  14. package/dist/completion.js.map +1 -0
  15. package/dist/config.d.ts +8 -0
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +8 -0
  18. package/dist/config.js.map +1 -1
  19. package/dist/create-prompts.d.ts +41 -0
  20. package/dist/create-prompts.d.ts.map +1 -0
  21. package/dist/create-prompts.js +78 -0
  22. package/dist/create-prompts.js.map +1 -0
  23. package/dist/create.d.ts +10 -5
  24. package/dist/create.d.ts.map +1 -1
  25. package/dist/create.js +28 -47
  26. package/dist/create.js.map +1 -1
  27. package/dist/db.d.ts +1 -0
  28. package/dist/db.d.ts.map +1 -1
  29. package/dist/db.js +37 -2
  30. package/dist/db.js.map +1 -1
  31. package/dist/github-annotations.d.ts +18 -0
  32. package/dist/github-annotations.d.ts.map +1 -0
  33. package/dist/github-annotations.js +22 -0
  34. package/dist/github-annotations.js.map +1 -0
  35. package/dist/index.d.ts +1 -9
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +665 -603
  38. package/dist/index.js.map +1 -1
  39. package/dist/inspect.d.ts +21 -2
  40. package/dist/inspect.d.ts.map +1 -1
  41. package/dist/inspect.js +1938 -131
  42. package/dist/inspect.js.map +1 -1
  43. package/dist/lib.d.ts +20 -0
  44. package/dist/lib.d.ts.map +1 -0
  45. package/dist/lib.js +17 -0
  46. package/dist/lib.js.map +1 -0
  47. package/dist/lint.d.ts +10 -1
  48. package/dist/lint.d.ts.map +1 -1
  49. package/dist/lint.js +340 -33
  50. package/dist/lint.js.map +1 -1
  51. package/dist/make.d.ts +20 -3
  52. package/dist/make.d.ts.map +1 -1
  53. package/dist/make.js +1896 -382
  54. package/dist/make.js.map +1 -1
  55. package/dist/outbox.d.ts +24 -0
  56. package/dist/outbox.d.ts.map +1 -0
  57. package/dist/outbox.js +138 -0
  58. package/dist/outbox.js.map +1 -0
  59. package/dist/schedule.d.ts +36 -0
  60. package/dist/schedule.d.ts.map +1 -0
  61. package/dist/schedule.js +155 -0
  62. package/dist/schedule.js.map +1 -0
  63. package/dist/task.d.ts +26 -0
  64. package/dist/task.d.ts.map +1 -0
  65. package/dist/task.js +106 -0
  66. package/dist/task.js.map +1 -0
  67. package/dist/templates/base.d.ts +13 -0
  68. package/dist/templates/base.d.ts.map +1 -0
  69. package/dist/templates/base.js +300 -0
  70. package/dist/templates/base.js.map +1 -0
  71. package/dist/templates/db.d.ts +14 -0
  72. package/dist/templates/db.d.ts.map +1 -0
  73. package/dist/templates/db.js +962 -0
  74. package/dist/templates/db.js.map +1 -0
  75. package/dist/templates/index.d.ts +14 -0
  76. package/dist/templates/index.d.ts.map +1 -0
  77. package/dist/templates/index.js +123 -0
  78. package/dist/templates/index.js.map +1 -0
  79. package/dist/templates/server.d.ts +26 -0
  80. package/dist/templates/server.d.ts.map +1 -0
  81. package/dist/templates/server.js +520 -0
  82. package/dist/templates/server.js.map +1 -0
  83. package/dist/templates/shadcn.d.ts +5 -0
  84. package/dist/templates/shadcn.d.ts.map +1 -0
  85. package/dist/templates/shadcn.js +555 -0
  86. package/dist/templates/shadcn.js.map +1 -0
  87. package/dist/templates/shared.d.ts +49 -0
  88. package/dist/templates/shared.d.ts.map +1 -0
  89. package/dist/templates/shared.js +57 -0
  90. package/dist/templates/shared.js.map +1 -0
  91. package/dist/templates/shell.d.ts +5 -0
  92. package/dist/templates/shell.d.ts.map +1 -0
  93. package/dist/templates/shell.js +1190 -0
  94. package/dist/templates/shell.js.map +1 -0
  95. package/dist/templates/todos.d.ts +17 -0
  96. package/dist/templates/todos.d.ts.map +1 -0
  97. package/dist/templates/todos.js +607 -0
  98. package/dist/templates/todos.js.map +1 -0
  99. package/dist/version.d.ts +8 -0
  100. package/dist/version.d.ts.map +1 -0
  101. package/dist/version.js +18 -0
  102. package/dist/version.js.map +1 -0
  103. package/package.json +9 -8
  104. package/src/ansi.ts +30 -0
  105. package/src/choices.ts +83 -0
  106. package/src/completion.ts +169 -0
  107. package/src/config.ts +16 -0
  108. package/src/create-prompts.ts +114 -0
  109. package/src/create.ts +40 -64
  110. package/src/db.ts +60 -4
  111. package/src/github-annotations.ts +37 -0
  112. package/src/index.ts +1075 -817
  113. package/src/inspect.ts +2859 -115
  114. package/src/lib.ts +45 -0
  115. package/src/lint.ts +493 -39
  116. package/src/make.ts +2389 -406
  117. package/src/outbox.ts +249 -0
  118. package/src/schedule.ts +272 -0
  119. package/src/task.ts +169 -0
  120. package/src/templates/base.ts +377 -0
  121. package/src/templates/db.ts +963 -0
  122. package/src/templates/index.ts +148 -0
  123. package/src/templates/server.ts +528 -0
  124. package/src/templates/shadcn.ts +570 -0
  125. package/src/templates/shared.ts +90 -0
  126. package/src/templates/shell.ts +1219 -0
  127. package/src/templates/todos.ts +607 -0
  128. package/src/version.ts +20 -0
  129. package/dist/create-bin.d.ts +0 -3
  130. package/dist/create-bin.d.ts.map +0 -1
  131. package/dist/create-bin.js +0 -9
  132. package/dist/create-bin.js.map +0 -1
  133. package/dist/templates.d.ts +0 -55
  134. package/dist/templates.d.ts.map +0 -1
  135. package/dist/templates.js +0 -3520
  136. package/dist/templates.js.map +0 -1
  137. package/src/create-bin.ts +0 -11
  138. package/src/templates.ts +0 -3774
package/src/db.ts CHANGED
@@ -21,6 +21,7 @@ export type RunDatabaseCommandOptions = {
21
21
  * Result returned by a database lifecycle command.
22
22
  */
23
23
  export type RunDatabaseCommandResult = {
24
+ schemaVersion: 1;
24
25
  command: DatabaseCommand;
25
26
  cwd: string;
26
27
  script: string;
@@ -56,18 +57,20 @@ export async function runDatabaseCommand(
56
57
  const cwd = path.resolve(options.cwd ?? process.cwd());
57
58
  const script = databaseScripts[options.command];
58
59
  const packageJson = await readPackageJson(cwd);
60
+ const scriptCommand = packageJson.scripts?.[script];
59
61
 
60
- if (!packageJson.scripts?.[script]) {
61
- throw new Error(
62
- `Missing package.json script "${script}". Add it to this Beignet app before running beignet db ${options.command}.`,
63
- );
62
+ if (!scriptCommand) {
63
+ throw new Error(missingDatabaseScriptMessage(options.command, script));
64
64
  }
65
65
 
66
+ await assertDatabaseCommandPreflight(cwd, options.command, scriptCommand);
67
+
66
68
  const runner = await detectPackageManager(cwd);
67
69
  const args = ["run", script];
68
70
 
69
71
  if (options.dryRun) {
70
72
  return {
73
+ schemaVersion: 1,
71
74
  command: options.command,
72
75
  cwd,
73
76
  script,
@@ -83,6 +86,7 @@ export async function runDatabaseCommand(
83
86
  });
84
87
 
85
88
  return {
89
+ schemaVersion: 1,
86
90
  command: options.command,
87
91
  cwd,
88
92
  script,
@@ -96,6 +100,58 @@ export async function runDatabaseCommand(
96
100
  };
97
101
  }
98
102
 
103
+ async function assertDatabaseCommandPreflight(
104
+ cwd: string,
105
+ command: DatabaseCommand,
106
+ scriptCommand: string,
107
+ ): Promise<void> {
108
+ if (
109
+ (command === "generate" || command === "migrate") &&
110
+ /\bdrizzle-kit\b/.test(scriptCommand) &&
111
+ !hasExplicitDrizzleConfigFlag(scriptCommand) &&
112
+ !(await exists(path.join(cwd, "drizzle.config.ts"))) &&
113
+ !(await exists(path.join(cwd, "drizzle.config.mts"))) &&
114
+ !(await exists(path.join(cwd, "drizzle.config.js"))) &&
115
+ !(await exists(path.join(cwd, "drizzle.config.mjs")))
116
+ ) {
117
+ throw new Error(
118
+ `Missing Drizzle config. beignet db ${command} runs "${scriptCommand}", but no drizzle.config.ts, drizzle.config.mts, drizzle.config.js, or drizzle.config.mjs exists in the app root.`,
119
+ );
120
+ }
121
+
122
+ const standardEntrypoints: Partial<Record<DatabaseCommand, string>> = {
123
+ seed: "infra/db/seed.ts",
124
+ reset: "infra/db/reset.ts",
125
+ };
126
+ const standardEntrypoint = standardEntrypoints[command];
127
+ if (
128
+ standardEntrypoint &&
129
+ scriptCommand.includes(standardEntrypoint) &&
130
+ !(await exists(path.join(cwd, standardEntrypoint)))
131
+ ) {
132
+ throw new Error(
133
+ `Missing database ${command} entrypoint ${standardEntrypoint}. beignet db ${command} runs "${scriptCommand}", so restore ${standardEntrypoint} or update package.json script "${databaseScripts[command]}".`,
134
+ );
135
+ }
136
+ }
137
+
138
+ function hasExplicitDrizzleConfigFlag(scriptCommand: string): boolean {
139
+ return /(?:^|\s)--config(?:=|\s)/.test(scriptCommand);
140
+ }
141
+
142
+ function missingDatabaseScriptMessage(
143
+ command: DatabaseCommand,
144
+ script: string,
145
+ ): string {
146
+ if (command === "generate" || command === "migrate") {
147
+ return `Missing package.json script "${script}". Standard Drizzle apps use "${script}": "drizzle-kit ${command}" with drizzle.config.ts at the app root.`;
148
+ }
149
+
150
+ const entrypoint =
151
+ command === "seed" ? "infra/db/seed.ts" : "infra/db/reset.ts";
152
+ return `Missing package.json script "${script}". Standard Drizzle apps use "${script}": "bun ${entrypoint}" so beignet db ${command} can run the app-owned ${command} entrypoint.`;
153
+ }
154
+
99
155
  async function readPackageJson(cwd: string): Promise<PackageJson> {
100
156
  try {
101
157
  return JSON.parse(
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Severity levels understood by GitHub Actions workflow commands.
3
+ */
4
+ export type GithubAnnotationSeverity = "error" | "warning" | "notice";
5
+
6
+ /**
7
+ * Format one GitHub Actions annotation workflow command.
8
+ *
9
+ * Absent properties are omitted and the message is percent-encoded so
10
+ * multiline messages survive the single-line command format.
11
+ */
12
+ export function formatGithubAnnotation(annotation: {
13
+ severity: GithubAnnotationSeverity;
14
+ message: string;
15
+ file?: string;
16
+ line?: number;
17
+ col?: number;
18
+ }): string {
19
+ const properties = [
20
+ annotation.file === undefined ? undefined : `file=${annotation.file}`,
21
+ annotation.line === undefined ? undefined : `line=${annotation.line}`,
22
+ annotation.col === undefined ? undefined : `col=${annotation.col}`,
23
+ ].filter((property): property is string => property !== undefined);
24
+ const propertySection =
25
+ properties.length > 0 ? ` ${properties.join(",")}` : "";
26
+
27
+ return `::${annotation.severity}${propertySection}::${encodeGithubAnnotationMessage(
28
+ annotation.message,
29
+ )}`;
30
+ }
31
+
32
+ function encodeGithubAnnotationMessage(message: string): string {
33
+ return message
34
+ .replaceAll("%", "%25")
35
+ .replaceAll("\r", "%0D")
36
+ .replaceAll("\n", "%0A");
37
+ }