--- title: Command-Line Tools pagination_prev: demos/mobile/index pagination_next: demos/data/index sidebar_custom_props: cli: true --- import current from '/version.js'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; With the availability of JS engines and the success of server-side platforms, it is feasible to build command-line tools for various workflows. This demo covers a number of strategies for building standalone processors. The goal is to generate CSV output from an arbitrary spreadsheet file. ## Deno `deno compile` generates a standalone executable that includes the entire JS runtime as well as user JS code. When compiling, the `--allow-read` option must be specified to allow the script to read files from the filesystem with `Deno.readFileSync`. can be compiled and run from Deno: 0) Download the test file : ```bash curl -LO https://sheetjs.com/pres.numbers ``` 1) Test the script with `deno run`: ```bash deno run -r --allow-read https://docs.sheetjs.com/cli/sheet2csv.ts pres.numbers ``` If this worked, the program will print a CSV of the first worksheet. 2) Compile and run `sheet2csv`: ```bash deno compile -r --allow-read https://docs.sheetjs.com/cli/sheet2csv.ts ./sheet2csv pres.numbers ``` ## NodeJS There are a few popular tools for compiling NodeJS scripts to CLI programs. The demo script presents a friendly command line interface including flags: ```bash $ ./xlsx-cli -h Usage: xlsx-cli [options] [sheetname] Options: -V, --version output the version number -f, --file use specified workbook -s, --sheet print specified sheet (default first sheet) ... ``` 1) Download [`xlsx-cli.js`](pathname:///cli/xlsx-cli.js) 2) Install the dependencies:
{`\
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz exit-on-epipe commander@2`}
{`\
pnpm install https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz exit-on-epipe commander@2`}
{`\
yarn add https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz exit-on-epipe commander@2`}
3) Follow tooling steps: Run `nexe` and manually specify NodeJS version 14.15.3 ```bash npx nexe -t 14.15.3 xlsx-cli.js ``` This generates `xlsx-cli` or `xlsx-cli.exe` depending on platform. Run `pkg`: ```bash npx pkg xlsx-cli.js ``` This generates `xlsx-cli-linux`, `xlsx-cli-macos`, and `xlsx-cli-win.exe` .