@barekey/cli 0.5.8 → 0.6.0

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.
@@ -1,5 +1,4 @@
1
1
  import { Command } from "commander";
2
- import pc from "picocolors";
3
2
 
4
3
  import { createCliAuthProvider } from "../auth-provider.js";
5
4
  import {
@@ -15,22 +14,23 @@ import {
15
14
  type CliTypegenResult,
16
15
  writeInstalledSdkGeneratedTypes,
17
16
  } from "../typegen/core.js";
17
+ import { accent, info, muted, strong, success, warning } from "../output/theme.js";
18
18
 
19
19
  const DEFAULT_TYPEGEN_WATCH_INTERVAL_MS = 5_000;
20
20
 
21
21
  export function formatTypegenResultMessage(result: CliTypegenResult): string {
22
22
  const title = result.written
23
- ? pc.green(pc.bold("Typegen complete"))
24
- : pc.cyan(pc.bold("Typegen already up to date"));
23
+ ? success(strong("Typegen complete"))
24
+ : info(strong("Typegen already up to date"));
25
25
  const detail = result.written
26
26
  ? "Fresh SDK types are ready in your installed @barekey/sdk package."
27
27
  : "Your installed @barekey/sdk package already has the latest generated types.";
28
28
 
29
29
  return [
30
30
  title,
31
- detail,
32
- `${pc.bold("Server types")}: ${result.serverPath}`,
33
- `${pc.bold("Public types")}: ${result.publicPath}`,
31
+ muted(detail),
32
+ `${accent("Server types")} ${muted(result.serverPath)}`,
33
+ `${accent("Public types")} ${muted(result.publicPath)}`,
34
34
  ].join("\n");
35
35
  }
36
36
 
@@ -41,9 +41,9 @@ export function formatTypegenWatchStartedMessage(input: {
41
41
  intervalMs: number;
42
42
  }): string {
43
43
  return [
44
- pc.cyan(pc.bold("Watching Barekey typegen")),
45
- `Target: ${pc.bold(`${input.organization}/${input.project}@${input.environment}`)}`,
46
- `Polling every ${pc.bold(`${input.intervalMs}ms`)}. Press ${pc.bold("Ctrl+C")} to stop.`,
44
+ info(strong("Watching Barekey typegen")),
45
+ `${accent("Target")} ${strong(`${input.organization}/${input.project}@${input.environment}`)}`,
46
+ `${warning("Polling every")} ${strong(`${input.intervalMs}ms`)}${muted(". Press Ctrl+C to stop.")}`,
47
47
  ].join("\n");
48
48
  }
49
49
 
@@ -74,6 +74,7 @@ async function resolveTypegenContext(options: EnvTargetOptions): Promise<{
74
74
  environment: string;
75
75
  runtimeMode: "centralized" | "standalone";
76
76
  typegenMode: "semantic" | "minimal";
77
+ strictGeneratedKeys: boolean;
77
78
  localEnvRoot: string | null;
78
79
  }> {
79
80
  const runtime = await loadRuntimeConfig();
@@ -89,6 +90,7 @@ async function resolveTypegenContext(options: EnvTargetOptions): Promise<{
89
90
  environment: target.stageSlug.trim().length > 0 ? target.stageSlug : "local",
90
91
  runtimeMode: runtime?.config.config?.mode ?? "centralized",
91
92
  typegenMode: runtime?.config.config?.typegen ?? "semantic",
93
+ strictGeneratedKeys: runtime?.config.config?.strictGeneratedKeys ?? false,
92
94
  localEnvRoot: runtime?.path ?? null,
93
95
  };
94
96
  }
@@ -126,6 +128,7 @@ async function runTypegen(options: EnvTargetOptions): Promise<void> {
126
128
  projectSlug: context.project,
127
129
  stageSlug: context.environment,
128
130
  typegenMode: context.typegenMode,
131
+ strictGeneratedKeys: context.strictGeneratedKeys,
129
132
  runtimeMode: context.runtimeMode,
130
133
  localEnvRoot: context.localEnvRoot,
131
134
  });
@@ -167,6 +170,7 @@ async function runTypegenWatch(
167
170
  projectSlug: nextContext.project,
168
171
  stageSlug: nextContext.environment,
169
172
  typegenMode: nextContext.typegenMode,
173
+ strictGeneratedKeys: nextContext.strictGeneratedKeys,
170
174
  runtimeMode: nextContext.runtimeMode,
171
175
  localEnvRoot: nextContext.localEnvRoot,
172
176
  });
@@ -26,6 +26,7 @@ export const RuntimeConfigSchema = Schema.Struct({
26
26
  config: Schema.optional(
27
27
  Schema.Struct({
28
28
  typegen: Schema.optional(TypegenModeSchema),
29
+ strictGeneratedKeys: Schema.optional(Schema.Boolean),
29
30
  mode: Schema.optional(RuntimeModeSchema),
30
31
  }),
31
32
  ),
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from "commander";
3
- import pc from "picocolors";
4
3
 
5
4
  import { registerAuthCommands } from "./commands/auth.js";
6
5
  import { registerAuditCommands } from "./commands/audit.js";
@@ -12,9 +11,14 @@ import { registerProjectCommands } from "./commands/project.js";
12
11
  import { registerStageCommands } from "./commands/stage.js";
13
12
  import { registerTypegenCommand } from "./commands/typegen.js";
14
13
  import { CLI_DESCRIPTION, CLI_NAME, CLI_VERSION } from "./constants.js";
14
+ import { danger } from "./output/theme.js";
15
15
 
16
16
  const program = new Command();
17
17
  program.name(CLI_NAME).description(CLI_DESCRIPTION).version(CLI_VERSION);
18
+ program.configureOutput({
19
+ writeErr: (message) => process.stderr.write(message),
20
+ outputError: (message, write) => write(danger(message)),
21
+ });
18
22
 
19
23
  registerAuthCommands(program);
20
24
  registerAuditCommands(program);
@@ -28,6 +32,6 @@ registerTypegenCommand(program);
28
32
 
29
33
  program.parseAsync(process.argv).catch((error: unknown) => {
30
34
  const message = error instanceof Error ? error.message : "Command failed.";
31
- console.error(pc.red(message));
35
+ console.error(danger(message));
32
36
  process.exitCode = 1;
33
37
  });
@@ -0,0 +1,166 @@
1
+ import pc from "picocolors";
2
+
3
+ const MINECRAFT_HEX = {
4
+ "1": "#0000AA",
5
+ "6": "#FFAA00",
6
+ "7": "#AAAAAA",
7
+ "8": "#555555",
8
+ "a": "#55FF55",
9
+ "b": "#55FFFF",
10
+ "c": "#FF5555",
11
+ "e": "#FFFF55",
12
+ } as const;
13
+
14
+ type MinecraftColorCode = keyof typeof MINECRAFT_HEX;
15
+
16
+ /**
17
+ * Returns whether styled terminal output should be emitted.
18
+ *
19
+ * @returns `true` when stdout is interactive and color has not been disabled.
20
+ * @remarks This keeps human output colorful while preserving clean automation output in dumb/no-color terminals.
21
+ * @lastModified 2026-03-19
22
+ * @author GPT-5.4
23
+ */
24
+ export function supportsCliColor(): boolean {
25
+ if (!process.stdout.isTTY) {
26
+ return false;
27
+ }
28
+
29
+ if ((process.env.NO_COLOR ?? "").trim().length > 0) {
30
+ return false;
31
+ }
32
+
33
+ return (process.env.TERM ?? "").toLowerCase() !== "dumb";
34
+ }
35
+
36
+ function hexToRgb(hex: string): { red: number; green: number; blue: number } {
37
+ const normalized = hex.replace(/^#/, "");
38
+ return {
39
+ red: Number.parseInt(normalized.slice(0, 2), 16),
40
+ green: Number.parseInt(normalized.slice(2, 4), 16),
41
+ blue: Number.parseInt(normalized.slice(4, 6), 16),
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Applies one Minecraft-style truecolor swatch to a string.
47
+ *
48
+ * @param code The legacy Minecraft color code to emulate.
49
+ * @param value The text to colorize.
50
+ * @returns The styled string, or the original text when colors are disabled.
51
+ * @remarks This uses truecolor ANSI so the palette stays stable across modern terminals.
52
+ * @lastModified 2026-03-19
53
+ * @author GPT-5.4
54
+ */
55
+ export function mc(code: MinecraftColorCode, value: string): string {
56
+ if (!supportsCliColor()) {
57
+ return value;
58
+ }
59
+
60
+ const { red, green, blue } = hexToRgb(MINECRAFT_HEX[code]);
61
+ return `\u001b[38;2;${red};${green};${blue}m${value}\u001b[39m`;
62
+ }
63
+
64
+ /**
65
+ * Styles one primary CLI label.
66
+ *
67
+ * @param value The label text.
68
+ * @returns The highlighted label.
69
+ * @remarks Gold is used as the main CLI accent color.
70
+ * @lastModified 2026-03-19
71
+ * @author GPT-5.4
72
+ */
73
+ export function accent(value: string): string {
74
+ return mc("6", value);
75
+ }
76
+
77
+ /**
78
+ * Styles one positive/success string.
79
+ *
80
+ * @param value The text to colorize.
81
+ * @returns The success-colored string.
82
+ * @remarks Green is used for successful actions and positive counts.
83
+ * @lastModified 2026-03-19
84
+ * @author GPT-5.4
85
+ */
86
+ export function success(value: string): string {
87
+ return mc("a", value);
88
+ }
89
+
90
+ /**
91
+ * Styles one informational string.
92
+ *
93
+ * @param value The text to colorize.
94
+ * @returns The info-colored string.
95
+ * @remarks Aqua is used for list metadata and secondary highlights.
96
+ * @lastModified 2026-03-19
97
+ * @author GPT-5.4
98
+ */
99
+ export function info(value: string): string {
100
+ return mc("b", value);
101
+ }
102
+
103
+ /**
104
+ * Styles one warning string.
105
+ *
106
+ * @param value The text to colorize.
107
+ * @returns The warning-colored string.
108
+ * @remarks Bright yellow is used for cautionary or count summary output.
109
+ * @lastModified 2026-03-19
110
+ * @author GPT-5.4
111
+ */
112
+ export function warning(value: string): string {
113
+ return mc("e", value);
114
+ }
115
+
116
+ /**
117
+ * Styles one muted metadata string.
118
+ *
119
+ * @param value The text to colorize.
120
+ * @returns The muted string.
121
+ * @remarks Gray is used for low-emphasis metadata like slugs and file paths.
122
+ * @lastModified 2026-03-19
123
+ * @author GPT-5.4
124
+ */
125
+ export function muted(value: string): string {
126
+ return mc("7", value);
127
+ }
128
+
129
+ /**
130
+ * Styles one subtle low-contrast string.
131
+ *
132
+ * @param value The text to colorize.
133
+ * @returns The subtle string.
134
+ * @remarks Dark gray is used for separators, labels, and empty-state output.
135
+ * @lastModified 2026-03-19
136
+ * @author GPT-5.4
137
+ */
138
+ export function subtle(value: string): string {
139
+ return mc("8", value);
140
+ }
141
+
142
+ /**
143
+ * Styles one failure/error string.
144
+ *
145
+ * @param value The text to colorize.
146
+ * @returns The danger-colored string.
147
+ * @remarks Red is reserved for errors and destructive outcomes.
148
+ * @lastModified 2026-03-19
149
+ * @author GPT-5.4
150
+ */
151
+ export function danger(value: string): string {
152
+ return mc("c", value);
153
+ }
154
+
155
+ /**
156
+ * Styles one prominent value with bold emphasis.
157
+ *
158
+ * @param value The text to emphasize.
159
+ * @returns The bold string.
160
+ * @remarks This intentionally leaves color choice to the caller.
161
+ * @lastModified 2026-03-19
162
+ * @author GPT-5.4
163
+ */
164
+ export function strong(value: string): string {
165
+ return pc.bold(value);
166
+ }
@@ -10,6 +10,7 @@ export type BarekeyRuntimeConfig = {
10
10
  environment?: string;
11
11
  config?: {
12
12
  typegen?: "semantic" | "minimal";
13
+ strictGeneratedKeys?: boolean;
13
14
  mode?: "centralized" | "standalone";
14
15
  };
15
16
  };
@@ -61,6 +62,7 @@ export async function loadRuntimeConfig(): Promise<BarekeyRuntimeConfigResult |
61
62
  const mode = config?.mode ?? "centralized";
62
63
  const typegen =
63
64
  mode === "standalone" ? "minimal" : (config?.typegen ?? decoded.right.typegen ?? "semantic");
65
+ const strictGeneratedKeys = config?.strictGeneratedKeys ?? false;
64
66
 
65
67
  return {
66
68
  path: configPath,
@@ -71,6 +73,7 @@ export async function loadRuntimeConfig(): Promise<BarekeyRuntimeConfigResult |
71
73
  config: {
72
74
  mode,
73
75
  typegen,
76
+ strictGeneratedKeys,
74
77
  },
75
78
  },
76
79
  };
@@ -8,6 +8,7 @@ import { TypegenManifestSchema, type TypegenManifest } from "../contracts/index.
8
8
 
9
9
  export type CliTypegenMode = "semantic" | "minimal";
10
10
  export type CliRuntimeMode = "centralized" | "standalone";
11
+ export type CliStrictGeneratedKeys = boolean;
11
12
 
12
13
  export type CliTypegenResult = {
13
14
  written: boolean;
@@ -23,6 +24,7 @@ type TypegenIdentity = {
23
24
  projectSlug: string;
24
25
  stageSlug: string;
25
26
  typegenMode: CliTypegenMode;
27
+ strictGeneratedKeys: CliStrictGeneratedKeys;
26
28
  runtimeMode: CliRuntimeMode;
27
29
  localEnvRoot: string | null;
28
30
  };
@@ -37,6 +39,7 @@ const TypegenMetadataSchema = Schema.Struct({
37
39
  projectSlug: Schema.NullOr(Schema.String),
38
40
  stageSlug: Schema.NullOr(Schema.String),
39
41
  typegenMode: Schema.NullOr(Schema.Literal("semantic", "minimal")),
42
+ strictGeneratedKeys: Schema.Boolean,
40
43
  runtimeMode: Schema.NullOr(Schema.Literal("centralized", "standalone")),
41
44
  localEnvRoot: Schema.NullOr(Schema.String),
42
45
  });
@@ -93,9 +96,11 @@ function buildGeneratedTypesContents(
93
96
  manifest: TypegenManifest,
94
97
  input: {
95
98
  mode: CliTypegenMode;
99
+ strictGeneratedKeys: CliStrictGeneratedKeys;
96
100
  typeModulePath: "./dist/types.js" | "./dist/public-types.js";
97
101
  declaredModulePath: "./dist/types.js" | "./dist/public-types.js";
98
102
  interfaceName: "BarekeyGeneratedTypeMap" | "BarekeyPublicGeneratedTypeMap";
103
+ configInterfaceName: "BarekeyGeneratedTypeConfig" | "BarekeyPublicGeneratedTypeConfig";
99
104
  include: (row: TypegenManifest["variables"][number]) => boolean;
100
105
  },
101
106
  ): string {
@@ -111,7 +116,7 @@ function buildGeneratedTypesContents(
111
116
  ? `import type { EaseInOut, Env, Linear, Step } from "${input.typeModulePath}";\n\n`
112
117
  : "";
113
118
 
114
- return `/* eslint-disable */\n/* This file is generated by barekey typegen. */\n/* barekey-manifest-version: ${manifest.manifestVersion} */\n\n${importLine}declare module "${input.declaredModulePath}" {\n interface ${input.interfaceName} {\n${mapLines.length > 0 ? mapLines : ""}\n }\n}\n\nexport {};\n`;
119
+ return `/* eslint-disable */\n/* This file is generated by barekey typegen. */\n/* barekey-manifest-version: ${manifest.manifestVersion} */\n\n${importLine}declare module "${input.declaredModulePath}" {\n interface ${input.interfaceName} {\n${mapLines.length > 0 ? mapLines : ""}\n }\n\n interface ${input.configInterfaceName} {\n allowUnknownKeys: ${input.strictGeneratedKeys ? "false" : "true"};\n }\n}\n\nexport {};\n`;
115
120
  }
116
121
 
117
122
  function readManifestVersion(contents: string | null): string | null {
@@ -197,6 +202,7 @@ function buildTypegenMetadataContents(lastGeneratedAt: Date, identity: TypegenId
197
202
  projectSlug: identity.projectSlug,
198
203
  stageSlug: identity.stageSlug,
199
204
  typegenMode: identity.typegenMode,
205
+ strictGeneratedKeys: identity.strictGeneratedKeys,
200
206
  runtimeMode: identity.runtimeMode,
201
207
  localEnvRoot: identity.localEnvRoot,
202
208
  },
@@ -218,6 +224,7 @@ function buildTypegenMetadataContents(lastGeneratedAt: Date, identity: TypegenId
218
224
  export function renderGeneratedTypesForManifest(
219
225
  manifest: TypegenManifest,
220
226
  mode: CliTypegenMode,
227
+ strictGeneratedKeys = false,
221
228
  ): {
222
229
  serverContents: string;
223
230
  publicContents: string;
@@ -227,16 +234,20 @@ export function renderGeneratedTypesForManifest(
227
234
  return {
228
235
  serverContents: buildGeneratedTypesContents(decodedManifest, {
229
236
  mode,
237
+ strictGeneratedKeys,
230
238
  typeModulePath: "./dist/types.js",
231
239
  declaredModulePath: "./dist/types.js",
232
240
  interfaceName: "BarekeyGeneratedTypeMap",
241
+ configInterfaceName: "BarekeyGeneratedTypeConfig",
233
242
  include: () => true,
234
243
  }),
235
244
  publicContents: buildGeneratedTypesContents(decodedManifest, {
236
245
  mode,
246
+ strictGeneratedKeys,
237
247
  typeModulePath: "./dist/public-types.js",
238
248
  declaredModulePath: "./dist/public-types.js",
239
249
  interfaceName: "BarekeyPublicGeneratedTypeMap",
250
+ configInterfaceName: "BarekeyPublicGeneratedTypeConfig",
240
251
  include: (row) => row.visibility === "public",
241
252
  }),
242
253
  };
@@ -271,7 +282,11 @@ export async function writeInstalledSdkGeneratedTypes(
271
282
  readTextFile(target.serverGeneratedTypesPath),
272
283
  readTextFile(target.publicGeneratedTypesPath),
273
284
  ]);
274
- const rendered = renderGeneratedTypesForManifest(manifest, identity.typegenMode);
285
+ const rendered = renderGeneratedTypesForManifest(
286
+ manifest,
287
+ identity.typegenMode,
288
+ identity.strictGeneratedKeys,
289
+ );
275
290
 
276
291
  if (
277
292
  existingServerContents === rendered.serverContents &&
@@ -86,6 +86,37 @@ describe("loadRuntimeConfig", () => {
86
86
  config: {
87
87
  mode: "centralized",
88
88
  typegen: "semantic",
89
+ strictGeneratedKeys: false,
90
+ },
91
+ },
92
+ });
93
+ });
94
+ });
95
+
96
+ test("reads config.strictGeneratedKeys when present", async () => {
97
+ const tempDir = await createTempDir();
98
+ await writeFile(
99
+ path.join(tempDir, "barekey.json"),
100
+ JSON.stringify(
101
+ {
102
+ organization: "acme",
103
+ project: "api",
104
+ environment: "development",
105
+ config: {
106
+ strictGeneratedKeys: true,
107
+ },
108
+ },
109
+ null,
110
+ 2,
111
+ ),
112
+ "utf8",
113
+ );
114
+
115
+ await withWorkingDirectory(tempDir, async () => {
116
+ await expect(loadRuntimeConfig()).resolves.toMatchObject({
117
+ config: {
118
+ config: {
119
+ strictGeneratedKeys: true,
89
120
  },
90
121
  },
91
122
  });