UNPKG

xlsx-to-csv

Version:
69 lines (68 loc) 2.51 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBinary = getBinary; exports.run = run; var path_1 = require("path"); var node_child_process_1 = require("node:child_process"); var fs = __importStar(require("node:fs")); var os = __importStar(require("node:os")); var NAME = 'xlsx-to-csv'; function getPlatform() { var type = os.type(); var arch = os.arch(); if (type === 'Windows_NT' && arch === 'x64') return 'win64'; if (type === 'Windows_NT') return 'win32'; if (type === 'Linux' && arch === 'x64') return 'linux'; if (type === 'Darwin' && arch === 'x64') return 'macos-x86_64'; if (type === 'Darwin' && arch === 'arm64') return 'macos-aarch64'; throw new Error("Unsupported platform: ".concat(type, " ").concat(arch)); } function getBinary() { var platform = getPlatform(); var binaryName = "".concat(NAME, "-").concat(platform); var binaryPath = (0, path_1.join)(__dirname, binaryName); // Check if the binary exists in the filesystem if (!fs.existsSync(binaryPath)) { throw new Error("Binary not found: ".concat(binaryPath)); } return binaryPath; } function run() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var result = (0, node_child_process_1.spawnSync)(getBinary(), args, {}); if (result.error) { throw result.error; } return result; }