From 0e913a90be66b2f29d2d75433b06ed52e83ba810 Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Mon, 10 Apr 2017 08:53:02 +0800 Subject: [PATCH] v4.1.0. Bugfix. --- HISTORY.md | 5 +++++ bin/cson2json | 2 +- bin/json2cson | 2 +- package.json | 2 +- source/cli.coffee | 30 ++++++++++++++++++++++-------- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ca28281..c3b8ede 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,10 @@ # History +## v4.1.0 2017 April 10 +- Updated base files +- `cson2json` and `json2cson` will now output the error if the input file is invalid + - Closes [issue #78](https://github.com/bevry/cson/issues/78) + ## v4.0.0 2016 October 20 - `parseCSString` no longer creates the `sandbox` variable if it was missing, the responsibility of such things should be, and now is, handled via the eval function of coffeescript which is what that method uses - This is a major breaking change as parsing coffeescript files will now by default run still in a virtual machine but now in the global context rather than their own context diff --git a/bin/cson2json b/bin/cson2json index d003501..aec9d29 100755 --- a/bin/cson2json +++ b/bin/cson2json @@ -1,2 +1,2 @@ #!/usr/bin/env node -require(require('path').join(__dirname, '..', 'es5', 'cli.js')) +require('../es5/cli') diff --git a/bin/json2cson b/bin/json2cson index d003501..aec9d29 100755 --- a/bin/json2cson +++ b/bin/json2cson @@ -1,2 +1,2 @@ #!/usr/bin/env node -require(require('path').join(__dirname, '..', 'es5', 'cli.js')) +require('../es5/cli') diff --git a/package.json b/package.json index 2f1aaab..6aa07d9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "title": "CSON", "name": "cson", - "version": "4.0.0", + "version": "4.1.0", "description": "CoffeeScript-Object-Notation Parser. Same as JSON but for CoffeeScript objects.", "homepage": "https://github.com/bevry/cson", "license": "MIT", diff --git a/source/cli.coffee b/source/cli.coffee index 9461f06..1f74422 100644 --- a/source/cli.coffee +++ b/source/cli.coffee @@ -60,12 +60,19 @@ else # File conversion if process.argv.length is 3 filePath = process.argv[2] - process.stdout.write( - if conversion is 'cson2json' - CSON.createJSONString CSON.parseCSONFile(filePath), opts - else - CSON.createCSONString CSON.parseJSONFile(filePath), opts - ) + + if conversion is 'cson2json' + parse = CSON.parseCSONFile.bind(CSON) + create = CSON.createJSONString.bind(CSON) + else + parse = CSON.parseJSONFile.bind(CSON) + create = CSON.createCSONString.bind(CSON) + + result = parse(filePath) + throw result if result instanceof Error + result = create(result, opts) + throw result if result instanceof Error + process.stdout.write(result) # Try STDIN else if process.argv.length is 2 @@ -77,9 +84,16 @@ else if process.argv.length is 2 processData = -> if conversion is 'cson2json' - result = CSON.createJSONString CSON.parseCSONString(data), opts + parse = CSON.parseCSONString.bind(CSON) + create = CSON.createJSONString.bind(CSON) else - result = CSON.createCSONString CSON.parseJSONString(data), opts + parse = CSON.parseJSONString.bind(CSON) + create = CSON.createCSONString.bind(CSON) + + result = parse(data) + throw result if result instanceof Error + result = create(result, opts) + throw result if result instanceof Error process.stdout.write(result) # Timeout if we don't have stdin