ktx/scripts/prepare-cli-bin.mjs
Andrey Avtomonov 00cdf2de90
refactor: enforce ktx naming and AGENTS.md compliance sweep (#289)
Align the tree with AGENTS.md/CLAUDE.md conventions:

- Rewrite user-facing strings, docs, and tests to lowercase `ktx`
  (no bare uppercase `KTX` tokens remain outside literal identifiers).
- Drop the legacy `historicSql` migration path and its now-unused
  helpers, per the no-backward-compat rule.
- Remove `as unknown as` / `any` casts: narrow `BaseTool` generics to
  `z.ZodObject`, add a typed `createLookerClient`, and delete the dead
  `getParametersSchema`/`toAnthropicFormat` pre-AI-SDK helpers.
- Use `InvalidArgumentError` for Commander parse failures.
- Finish the adapter→connector prose conversion in the `ktx.yaml` docs
  while keeping the literal `adapters` config key.
2026-06-11 13:49:45 +02:00

44 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
import { constants } from 'node:fs';
import { access, chmod } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
export function ktxRootDir() {
return resolve(dirname(fileURLToPath(import.meta.url)), '..');
}
export function cliBinPath(rootDir = ktxRootDir()) {
return resolve(rootDir, 'packages', 'cli', 'dist', 'bin.js');
}
async function canExecute(path) {
try {
await access(path, constants.X_OK);
return true;
} catch {
return false;
}
}
export async function ensureCliBinExecutable(rootDir = ktxRootDir()) {
const binPath = cliBinPath(rootDir);
await access(binPath, constants.R_OK);
if (process.platform !== 'win32' && !(await canExecute(binPath))) {
await chmod(binPath, 0o755);
}
return binPath;
}
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
try {
const binPath = await ensureCliBinExecutable();
process.stdout.write(`Prepared ktx CLI bin: ${binPath}\n`);
} catch (error) {
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
process.exitCode = 1;
}
}