Update CLI scripts to enhance functionality and error handling. Change shebang in cli-ink.js for improved compatibility with TypeScript. Modify websearch.js to utilize EXA_API_KEY from environment variables, adding error handling for missing keys. Refactor wget.js to use ES module syntax and improve filename generation for downloaded content.

This commit is contained in:
sebseb7
2025-08-12 05:44:17 +00:00
parent 62e9754ab0
commit ac09e4ed08
6 changed files with 66 additions and 7 deletions

43
scripts/jsx-loader.mjs Normal file
View File

@@ -0,0 +1,43 @@
// ESM loader to transpile .jsx files on the fly using esbuild
// Usage: node --loader ./scripts/jsx-loader.mjs cli-ink.js
import { readFile } from 'node:fs/promises';
import { pathToFileURL, fileURLToPath } from 'node:url';
import { transform } from 'esbuild';
/** @typedef {import('node:module').LoadHook} LoadHook */
/** @typedef {import('node:module').ResolveHook} ResolveHook */
/** @type {ResolveHook} */
export async function resolve(specifier, context, nextResolve) {
// Defer to Node's default resolver for most cases
return nextResolve(specifier, context, nextResolve);
}
/** @type {LoadHook} */
export async function load(url, context, nextLoad) {
// Handle .jsx sources
if (url.endsWith('.jsx')) {
const filename = fileURLToPath(url);
const source = await readFile(filename, 'utf8');
const result = await transform(source, {
loader: 'jsx',
format: 'esm',
jsx: 'automatic',
sourcefile: filename,
});
return {
format: 'module',
source: result.code,
shortCircuit: true,
};
}
// Fallback to default loader for everything else
return nextLoad(url, context, nextLoad);
}