sheetxl
Version:
SheetXL - Command line tool
56 lines (55 loc) • 1.87 kB
JavaScript
/**
* @license sheetxl - SheetXL - Command line tool - v0.7.26
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/
import t from "node:fs";
import o from "node:path";
import { pathToFileURL as r } from "node:url";
import e from "chalk";
import { p as s, r as i } from "./DMpjrOGn7N6axE_E.js";
import { x as a } from "../cli.js";
import "fs";
import "path";
import "commander";
const n = async (n2, c, f, d) => {
const p = s(f);
let l = null;
if (d.workbook) try {
const t2 = {};
l = await i(d.workbook, t2);
} catch (t2) {
return void a.error(`Unable to parse '${d.workbook}' as a workbook`, { details: t2 });
}
const m = { sdk: n2.sdk, io: n2.io, notifier: n2.notifier, args: p, workbook: l }, u = c, k = o.resolve(process.cwd(), u);
if (!t.existsSync(k)) return void a.error("Script not found:", { details: k });
try {
t.accessSync(k, t.constants.R_OK);
} catch (t2) {
return void a.error("Unable to read file:", { details: k });
}
const w = o.extname(k).toLowerCase();
try {
if (".ts" === w || ".tsx" === w) {
const { register: t2 } = await import("tsx/esm/api"), o2 = t2();
try {
const t3 = r(k).href, o3 = await import(t3);
"function" == typeof o3.default && await o3.default(m);
} finally {
o2();
}
} else {
if (".js" !== w && ".mjs" !== w && ".cjs" !== w) return void a.error("Unsupported file type:", { details: `${w} (expected .ts, .tsx, .js, .mjs, or .cjs)` });
{
const t2 = r(k).href, o2 = await import(t2);
"function" == typeof o2.default && await o2.default(m);
}
}
} catch (t2) {
return a.error("Script execution failed:", { details: t2.message }), void (t2.stack && console.error(e.dim(t2.stack)));
}
};
export {
n as default
};