sheetxl
Version:
SheetXL - Command line tool
116 lines (107 loc) ⢠4.89 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 e from "node:util";
import t from "node:path";
import o from "node:os";
import n from "open";
import r from "node:repl";
import i from "chalk";
import { x as s, j as a, u as l, i as c, k as p, I as m } from "../cli.js";
import { i as d, r as h, w as f } from "./DMpjrOGn7N6axE_E.js";
import "fs";
import "path";
import "commander";
import "node:fs";
async function u(u2, g, w) {
const { program: y } = w, b = y.opts().quiet || false;
b || (s.log(`${i.green("Welcome to the SheetXL REPL!")}`), s.log(`${i.dim(`Type ${i.cyan(".help")} for REPL commands, or ${i.cyan("help")} for SheetXL API info.`)}`));
let x = 0, k = 0, $ = 0, P = "";
const S = { onStart(e2, t2) {
k = (/* @__PURE__ */ new Date()).getTime(), $ = 0;
}, onProgress(e2, t2) {
$ += e2, process.stdout.write(i.green("#"));
}, onWarning(e2, t2) {
process.stdout.write(i.red("warning")), process.stdout.write(i.dim(i.red(`${t2}: ${e2}
`)));
}, onComplete() {
const e2 = (/* @__PURE__ */ new Date()).getTime();
var t2;
$ > 0 && process.stdout.write("\n"), s.log(i.blue(`${P} ${((e3) => {
if (void 0 === e3) return "";
if (0 === e3) return "nothing ";
if (e3 < 1024) return `${e3}B `;
const t3 = Math.floor(Math.log(e3) / Math.log(1024));
return `${(e3 / Math.pow(1024, t3)).toFixed(2)}${["B", "KB", "MB", "GB", "TB"][t3]} `;
})(x)}in ${t2 = Math.trunc(0.55 * (e2 - k)), t2 < 1e3 ? `${Math.trunc(t2)}ms` : `${(t2 / 1e3).toFixed(2)}s`}`)), k = 0, x = void 0;
} }, L = async (e2, t2) => h(e2, t2, S, (e3, t3) => {
x = t3.size, P = e3, k = (/* @__PURE__ */ new Date()).getTime(), $ = 0;
}), v = async (e2, t2, o2) => f(e2, t2, o2, S, (e3, t3) => {
x = t3?.size ?? void 0, P = e3, k = (/* @__PURE__ */ new Date()).getTime(), $ = 0;
});
let A = null;
if (u2) try {
A = await L(u2);
} catch (e2) {
s.error(i.red(`Failed to read workbook: ${e2.message}`));
}
const I = A ? `'${a.capitalize(A.getName() || "Workbook")}'` : "SheetXL", T = r.start({ prompt: `${i.cyanBright(I)}${i.cyan(" > ")}`, writer: (t2) => {
if (b) return "";
if (t2) {
const e2 = t2[Symbol.toStringTag];
if ("string" == typeof e2) {
const o2 = t2.toString?.();
return "string" == typeof o2 && "[object Object]" !== o2 ? `${i.cyan(e2)} ${i.yellow(o2)}` : i.cyan(e2);
}
}
return e.inspect(t2, { colors: true });
}, preview: false, ignoreUndefined: true }), X = t.join(o.homedir(), ".sheetxl_history");
T.setupHistory(X, (e2) => {
e2 && console.error("Failed to set up REPL history:", e2);
}), T.defineCommand("clear", { help: "Clear the terminal screen", action() {
this.clearBufferedCommand(), console.clear(), this.displayPrompt();
} });
const B = "https://www.sheetxl.com/docs/guides";
return T.defineCommand("docs", { help: "Open the SheetXL documentation website", async action() {
this.clearBufferedCommand(), console.log(`Opening ${i.blue(B)} in your browser...`), n(B), this.displayPrompt();
} }), T.defineCommand("license", { help: "Check the current license status", async action() {
this.clearBufferedCommand(), await l.print(), this.displayPrompt();
} }), A ? (d(T, A, "wb"), T.context.write = async (e2, t2) => await v(e2, A, t2), T.context.save = T.context.write, Object.defineProperty(T.context, "help", { async get() {
console.log(`š§ SheetXL REPL Workbook Help:
Available helpers:
- write(path): Writes a workbook to a file
Available namespaces:
- SheetXL SDK (from @sheetxl/sdk)
- SheetXL IO (from @sheetxl/io)
Tips:
- You can access any Workbook API directly, e.g., getRange('A1:E5')
- Use .exit to leave the REPL
To see the full API documentation, visit:
š Getting Started: ${i.blue("https://www.sheetxl.com/docs/guides/getting-started/cli")}
š API: ${i.blue("https://api.sheetxl.com")}
`);
} })) : (T.context.workbookIO = c, T.context.read = L, T.context.write = v, T.context.save = v, d(T, p, "sdk"), d(T, m, "io"), Object.defineProperty(T.context, "help", { async get() {
console.log(`š§ SheetXL REPL Help:
Available helpers:
- read(path): Reads a file and returns a SheetXL workbook
- write(path, wb): Writes a workbook to a file (alias for writeFile)
Available namespaces:
- SheetXL SDK (from @sheetxl/sdk)
- SheetXL IO (from @sheetxl/io)
Tips:
- You can access any @sheetxl/sdk API directly, e.g., new Workbook()
- Use .exit to leave the REPL
To see the full API documentation, visit:
š Getting Started: ${i.blue("https://www.sheetxl.com/docs/guides/getting-started/cli")}
š API: ${i.blue("https://api.sheetxl.com")}
`);
} })), new Promise((e2) => {
T.on("exit", () => e2(0));
});
}
export {
u as default
};