keytec-ai-cli 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/dist/cli.js +42 -6
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -10426,14 +10426,48 @@ function resolveConfigPath(path2 = ".keytec-ai.yml") {
10426
10426
  }
10427
10427
  throw new Error(`${path2}: not found in ${process.cwd()} or any parent directory`);
10428
10428
  }
10429
- function loadConfig(path2 = ".keytec-ai.yml") {
10430
- const resolved = resolveConfigPath(path2);
10431
- const doc = $parse(readFileSync2(resolved, "utf8"));
10429
+ function readConfigFile(path2) {
10430
+ const doc = $parse(readFileSync2(path2, "utf8"));
10432
10431
  if (!doc || typeof doc !== "object" || Array.isArray(doc)) {
10433
- throw new Error(`${resolved}: not a valid YAML object`);
10432
+ throw new Error(`${path2}: not a valid YAML object`);
10434
10433
  }
10435
10434
  return doc;
10436
10435
  }
10436
+ function isPlainObject(v) {
10437
+ return typeof v === "object" && v !== null && !Array.isArray(v);
10438
+ }
10439
+ function deepMerge(base, overlay) {
10440
+ const out = { ...base };
10441
+ for (const [k, v] of Object.entries(overlay)) {
10442
+ if (v === undefined)
10443
+ continue;
10444
+ if (isPlainObject(v) && isPlainObject(out[k])) {
10445
+ out[k] = deepMerge(out[k], v);
10446
+ } else {
10447
+ out[k] = v;
10448
+ }
10449
+ }
10450
+ return out;
10451
+ }
10452
+ function resolveOverlayPath(root, kind, name) {
10453
+ const rel = `.keytec-ai/${kind}/${name}.yml`;
10454
+ const abs = resolve(root, ".keytec-ai", kind, `${name}.yml`);
10455
+ if (!existsSync2(abs))
10456
+ throw new Error(`${rel}: not found`);
10457
+ return abs;
10458
+ }
10459
+ function loadConfig(opts = {}) {
10460
+ const basePath = resolveConfigPath(opts.config);
10461
+ const root = dirname(basePath);
10462
+ let config = readConfigFile(basePath);
10463
+ if (opts.site) {
10464
+ config = deepMerge(config, readConfigFile(resolveOverlayPath(root, "sites", opts.site)));
10465
+ }
10466
+ if (opts.feature) {
10467
+ config = deepMerge(config, readConfigFile(resolveOverlayPath(root, "features", opts.feature)));
10468
+ }
10469
+ return config;
10470
+ }
10437
10471
  function flatten(obj, prefix, out) {
10438
10472
  for (const [k, v] of Object.entries(obj)) {
10439
10473
  const key = prefix ? `${prefix}_${k}` : k;
@@ -10464,8 +10498,10 @@ function toEnv(config) {
10464
10498
  // src/commands/config/index.ts
10465
10499
  function registerConfig(program2) {
10466
10500
  const group = program2.command("config").description("Inspect and export .keytec-ai.yml");
10467
- group.command("to-env").description("Render the config as flat UPPER_SNAKE env vars").option("--config <path>", "config file path (default: .keytec-ai.yml, searched upward)").option("--to-file <path>", "write the env vars to this file instead of stdout").action((o) => {
10468
- const env = toEnv(loadConfig(o.config));
10501
+ group.command("to-env").description("Render the config as flat UPPER_SNAKE env vars").option("--config <path>", "config file path (default: .keytec-ai.yml, searched upward)").option("--site <name>", "apply the .keytec-ai/sites/<name>.yml overlay (env: KEYTEC_AI_SITE)").option("--feature <name>", "apply the .keytec-ai/features/<name>.yml overlay (env: KEYTEC_AI_FEATURE)").option("--to-file <path>", "write the env vars to this file instead of stdout").action((o) => {
10502
+ const site = o.site ?? (process.env.KEYTEC_AI_SITE || undefined);
10503
+ const feature = o.feature ?? (process.env.KEYTEC_AI_FEATURE || undefined);
10504
+ const env = toEnv(loadConfig({ config: o.config, site, feature }));
10469
10505
  if (o.toFile) {
10470
10506
  writeFileSync(o.toFile, `${env}
10471
10507
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keytec-ai-cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "keytec-ai: one CLI for .keytec-ai.yml operations (deploy, env) — used by GitLab CI, the DDEV addon and the deploy skill",
5
5
  "type": "module",
6
6
  "bin": {