Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Commit

Permalink
version bump 0.3.12: workaround for node bug
Browse files Browse the repository at this point in the history
- 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 nodejs/node-v0.x-archive#8208)
- updated XLS to 0.7.1, XLS to 0.7.9
- added --sheet-index option to specify by index rather than by name
  • Loading branch information
SheetJSDev committed Aug 23, 2014
1 parent e1e21ca commit 01a471c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "0.10"
- "0.10.30"
- "0.8"
- "0.11"
before_install:
Expand Down
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,28 @@ $ j --help
Options:
-h, --help output usage information
-V, --version output the version number
-f, --file <file> use specified file (- for stdin)
-s, --sheet <sheet> print specified sheet (default first sheet)
-l, --list-sheets list sheet names and exit
-o, --output <file> output to specified file
-B, --xlsb emit XLSB to <sheetname> or <file>.xlsb
-M, --xlsm emit XLSM to <sheetname> or <file>.xlsm
-X, --xlsx emit XLSX to <sheetname> or <file>.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 <sep> CSV field separator
-R, --row-sep <sep> CSV row separator
-n, --sheet-rows <num> 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 <file> use specified file (- for stdin)
-s, --sheet <sheet> print specified sheet (default first sheet)
-N, --sheet-index <idx> use specified sheet index (0-based)
-l, --list-sheets list sheet names and exit
-o, --output <file> output to specified file
-B, --xlsb emit XLSB to <sheetname> or <file>.xlsb
-M, --xlsm emit XLSM to <sheetname> or <file>.xlsm
-X, --xlsx emit XLSX to <sheetname> or <file>.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 <sep> CSV field separator
-R, --row-sep <sep> CSV row separator
-n, --sheet-rows <num> Number of rows to process (0=all rows)
--dev development mode
--read read but do not print out contents
-q, --quiet quiet mode
```


Expand Down
39 changes: 24 additions & 15 deletions bin/j.njs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ program
.usage('[options] <file> [sheetname]')
.option('-f, --file <file>', 'use specified file (- for stdin)')
.option('-s, --sheet <sheet>', 'print specified sheet (default first sheet)')
.option('-N, --sheet-index <idx>', 'use specified sheet index (0-based)')
.option('-l, --list-sheets', 'list sheet names and exit')
.option('-o, --output <file>', 'output to specified file')
.option('-B, --xlsb', 'emit XLSB to <sheetname> or <file>.xlsb')
Expand All @@ -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];
Expand All @@ -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);
Expand All @@ -65,29 +79,22 @@ 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;
console.error(msg);
process.exit(3);
}
process_data(w);
});
}));
} else {
if(program.dev) {
w = J.readFile(filename, opts);
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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" ],
Expand All @@ -16,7 +16,8 @@
"main": "./j",
"dependencies": {
"xlsjs": "~0.7.1",
"xlsx": "~0.7.8",
"xlsx": "~0.7.9",
"concat-stream":"",
"commander":""
},
"devDependencies": {
Expand Down

0 comments on commit 01a471c

Please sign in to comment.