From 01a471c58ec0b0145aadc96ddf037f92094115a3 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sat, 23 Aug 2014 04:17:36 -0400 Subject: [PATCH] version bump 0.3.12: workaround for node bug - refuse to run `j` on node v0.10.31 (h/t @lightbringer1991, fixes #4) - use concat-stream and check process.stdin.isTTY (h/t @sindresorhus) - CI pinned to node 0.10.31 (see https://github.com/joyent/node/issues/8208) - updated XLS to 0.7.1, XLS to 0.7.9 - added --sheet-index option to specify by index rather than by name --- .travis.yml | 2 +- README.md | 43 ++++++++++++++++++++++--------------------- bin/j.njs | 39 ++++++++++++++++++++++++--------------- package.json | 5 +++-- 4 files changed, 50 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c5bfb6..724cc91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - "0.10" + - "0.10.30" - "0.8" - "0.11" before_install: diff --git a/README.md b/README.md index b76d48a..2d8fa09 100644 --- a/README.md +++ b/README.md @@ -60,27 +60,28 @@ $ j --help Options: - -h, --help output usage information - -V, --version output the version number - -f, --file use specified file (- for stdin) - -s, --sheet print specified sheet (default first sheet) - -l, --list-sheets list sheet names and exit - -o, --output output to specified file - -B, --xlsb emit XLSB to or .xlsb - -M, --xlsm emit XLSM to or .xlsm - -X, --xlsx emit XLSX to or .xlsx - -S, --formulae print formulae - -j, --json emit formatted JSON (all fields text) - -J, --raw-js emit raw JS object (raw numbers) - -x, --xml emit XML - -H, --html emit HTML - -m, --markdown emit markdown table (with pipes) - -F, --field-sep CSV field separator - -R, --row-sep CSV row separator - -n, --sheet-rows Number of rows to process (0=all rows) - --dev development mode - --read read but do not print out contents - -q, --quiet quiet mode + -h, --help output usage information + -V, --version output the version number + -f, --file use specified file (- for stdin) + -s, --sheet print specified sheet (default first sheet) + -N, --sheet-index use specified sheet index (0-based) + -l, --list-sheets list sheet names and exit + -o, --output output to specified file + -B, --xlsb emit XLSB to or .xlsb + -M, --xlsm emit XLSM to or .xlsm + -X, --xlsx emit XLSX to or .xlsx + -S, --formulae print formulae + -j, --json emit formatted JSON (all fields text) + -J, --raw-js emit raw JS object (raw numbers) + -x, --xml emit XML + -H, --html emit HTML + -m, --markdown emit markdown table (with pipes) + -F, --field-sep CSV field separator + -R, --row-sep CSV row separator + -n, --sheet-rows Number of rows to process (0=all rows) + --dev development mode + --read read but do not print out contents + -q, --quiet quiet mode ``` diff --git a/bin/j.njs b/bin/j.njs index 55356e8..658cd0b 100755 --- a/bin/j.njs +++ b/bin/j.njs @@ -9,6 +9,7 @@ program .usage('[options] [sheetname]') .option('-f, --file ', 'use specified file (- for stdin)') .option('-s, --sheet ', 'print specified sheet (default first sheet)') + .option('-N, --sheet-index ', 'use specified sheet index (0-based)') .option('-l, --list-sheets', 'list sheet names and exit') .option('-o, --output ', 'output to specified file') .option('-B, --xlsb', 'emit XLSB to or .xlsb') @@ -35,6 +36,17 @@ program.on('--help', function() { program.parse(process.argv); +/* see https://github.com/SheetJS/j/issues/4 */ +if(process.version === 'v0.10.31') { + var msgs = [ + "node v0.10.31 is known to crash on OSX and Linux, refusing to proceed.", + "see https://github.com/SheetJS/j/issues/4 for the relevant discussion.", + "see https://github.com/joyent/node/issues/8208 for the relevant node issue" + ]; + msgs.forEach(function(m) { console.error(m); }); + process.exit(1); +} + var filename, sheetname = ''; if(program.args[0]) { filename = program.args[0]; @@ -43,6 +55,8 @@ if(program.args[0]) { if(program.sheet) sheetname = program.sheet; if(program.file) filename = program.file; +if(!process.stdin.isTTY) filename = filename || "-"; + if(!filename) { console.error("j: must specify a filename"); process.exit(1); @@ -65,21 +79,14 @@ if(program.dev) { opts.WTF = true; } - -if(filename == "-") { - var buffers = []; - process.stdin.on('readable', function() { - var chunk = process.stdin.read(); - if(chunk !== null) { - buffers.push(chunk); - } - }); - process.stdin.on('end', function() { +if(filename === "-") { + var concat = require('concat-stream'); + process.stdin.pipe(concat(function(data) { if(program.dev) { - w = J.read(Buffer.concat(buffers), opts); + w = J.read(data, opts); } else try { - w = J.read(Buffer.concat(buffers), opts); + w = J.read(data, opts); } catch(e) { var msg = (program.quiet) ? "" : "j: error parsing "; msg += filename + ": " + e; @@ -87,7 +94,7 @@ if(filename == "-") { process.exit(3); } process_data(w); - }); + })); } else { if(program.dev) { w = J.readFile(filename, opts); @@ -121,8 +128,10 @@ if(program.xlsm) return fs.writeFileSync(sheetname || (filename + ".xlsm"), J.ut if(program.xlsb) return fs.writeFileSync(sheetname || (filename + ".xlsb"), J.utils.to_xlsb(w, wopts)); var target_sheet = sheetname || ''; -if(target_sheet === '') target_sheet = (wb.SheetNames||[""])[0]; - +if(target_sheet === '') { + if(program.sheetIndex < (wb.SheetNames||[]).length) target_sheet = wb.SheetNames[program.sheetIndex]; + else target_sheet = (wb.SheetNames||[""])[0]; +} var ws; try { ws = wb.Sheets[target_sheet]; diff --git a/package.json b/package.json index 4be5707..000667a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "j", - "version": "0.3.11", + "version": "0.3.12", "author": "sheetjs", "description": "CLI tool for working with XLS/XLSX/XLSM/XLSB files", "keywords": [ "excel", "xls", "xlsx", "xlsm", "xlsb", "office", "spreadsheet" ], @@ -16,7 +16,8 @@ "main": "./j", "dependencies": { "xlsjs": "~0.7.1", - "xlsx": "~0.7.8", + "xlsx": "~0.7.9", + "concat-stream":"", "commander":"" }, "devDependencies": {