From e7c5830c488c11fe0294d80ef0c8832f5bd105c0 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 27 Dec 2016 10:30:10 +0200 Subject: [PATCH] feature(cloudcmd) show line number when config is not valid json (closes #98) --- bin/cloudcmd.js | 9 +++++++-- package.json | 3 ++- server/config.js | 11 ++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index 92c1b8e7..94b162a9 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -151,13 +151,18 @@ function readConfig(name) { if (!name) return; + const fs = require('fs'); const tryCatch = require('try-catch'); - const readjson = require('readjson'); + const jju = require('jju'); + + const readjsonSync = (name) => jju.parse(fs.readFileSync(name, 'utf8'), { + mode: 'json' + }); let data; const error = tryCatch(() => { - data = readjson.sync(name); + data = readjsonSync(name); }); if (error) diff --git a/package.json b/package.json index 7d66f497..3a2918da 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "http-auth": "^2.3.1", "ishtar": "^1.5.0", "jaguar": "^3.0.0", + "jju": "^1.3.0", "join-io": "^1.4.0", "jonny": "^1.0.0", "markdown-it": "^8.0.0", @@ -125,7 +126,6 @@ "package-json": "^2.3.0", "ponse": "^1.4.0", "pullout": "^1.0.1", - "readjson": "^1.1.0", "remedy": "^1.5.0", "rendy": "^1.1.0", "restafary": "^1.6.0", @@ -153,6 +153,7 @@ "nsp": "^2.2.1", "nyc": "^9.0.1", "place": "^1.1.4", + "readjson": "^1.1.3", "recess": "^1.1.9", "redrun": "^5.0.0", "request": "^2.76.0", diff --git a/server/config.js b/server/config.js index 6c3aa3d8..9342466d 100644 --- a/server/config.js +++ b/server/config.js @@ -5,6 +5,7 @@ const DIR_COMMON = DIR_SERVER + '../common/'; const DIR = DIR_SERVER + '../'; const path = require('path'); +const fs = require('fs'); const exit = require(DIR_SERVER + 'exit'); const CloudFunc = require(DIR_COMMON + 'cloudfunc'); @@ -12,7 +13,7 @@ const CloudFunc = require(DIR_COMMON + 'cloudfunc'); const pullout = require('pullout/legacy'); const ponse = require('ponse'); const jonny = require('jonny'); -const readjson = require('readjson'); +const jju = require('jju'); const writejson = require('writejson'); const tryCatch = require('try-catch'); const exec = require('execon'); @@ -24,9 +25,13 @@ const apiURL = CloudFunc.apiURL; const ConfigPath = path.join(DIR, 'json/config.json'); const ConfigHome = path.join(HOME, '.cloudcmd.json'); +const readjsonSync = (name) => jju.parse(fs.readFileSync(name, 'utf8'), { + mode: 'json' +}); + let config; let error = tryCatch(() => { - config = readjson.sync(ConfigHome); + config = readjsonSync(ConfigHome); }); if (error) { @@ -34,7 +39,7 @@ if (error) { console.error('cloudcmd --config ~/.cloudcmd.json:', error.message); error = tryCatch(() => { - config = readjson.sync(ConfigPath); + config = readjsonSync(ConfigPath); }); if (error)