From 8b327f257cc55b3b9842ac869117f0af5ae16959 Mon Sep 17 00:00:00 2001 From: TJKoury Date: Thu, 28 Jul 2016 10:13:23 -0400 Subject: [PATCH 1/7] Catch err and display message Make sure error is caught and appropriate message displayed. Currently just throws an error if there's an issue in the request: /usr/local/lib/node_modules/vue-cli/bin/vue-list:29 JSON.parse(body).forEach(function (repo) { ^ TypeError: JSON.parse(...).forEach is not a function --- bin/vue-list | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/bin/vue-list b/bin/vue-list index 11186b5e13..52ad23f78f 100755 --- a/bin/vue-list +++ b/bin/vue-list @@ -16,20 +16,29 @@ process.on('exit', function () { /** * List repos. */ - + request({ url: 'https://api.github.com/users/vuejs-templates/repos', headers: { 'User-Agent': 'vue-cli' } }, function (err, res, body) { - if (err) logger.fatal(err) - console.log(' Available official templates:') - console.log() - JSON.parse(body).forEach(function (repo) { - console.log( - ' ' + chalk.yellow('★') + - ' ' + chalk.blue(repo.name) + - ' - ' + repo.description) - }) + if (err) { + logger.fatal(err); + }else{ + + var _body = JSON.parse(body); + + if(Array.isArray(_body)){ + + console.log(' Available official templates: \n'); + _body.forEach(function (repo) { + console.log('%s %s - %s', chalk.yellow('★'), chalk.blue(repo.name), repo.description); + }); + }else if(_body.hasOwnProperty('message')){ + console.log('%s', chalk.yellow(_body.message)); + }else{ + console.log(_body); + } + } }) From e779016b754b33c61d9a379bc007c2c1f4b30ad8 Mon Sep 17 00:00:00 2001 From: TJKoury Date: Thu, 28 Jul 2016 10:16:31 -0400 Subject: [PATCH 2/7] Update format Easier to read on narrow windows. --- bin/vue-list | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/vue-list b/bin/vue-list index 52ad23f78f..a984cc7a2b 100755 --- a/bin/vue-list +++ b/bin/vue-list @@ -33,10 +33,13 @@ request({ console.log(' Available official templates: \n'); _body.forEach(function (repo) { - console.log('%s %s - %s', chalk.yellow('★'), chalk.blue(repo.name), repo.description); + console.log('%s %s - %s', + chalk.yellow('★'), + chalk.blue(repo.name), + repo.description); }); }else if(_body.hasOwnProperty('message')){ - console.log('%s', chalk.yellow(_body.message)); + console.log(chalk.yellow(_body.message)); }else{ console.log(_body); } From 7c729c7fce4eb0f2277a2e726e9ae945e9c3e717 Mon Sep 17 00:00:00 2001 From: TJKoury Date: Thu, 28 Jul 2016 10:34:48 -0400 Subject: [PATCH 3/7] Formatting Formatting --- bin/vue-list | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/bin/vue-list b/bin/vue-list index a984cc7a2b..43afc94468 100755 --- a/bin/vue-list +++ b/bin/vue-list @@ -16,7 +16,7 @@ process.on('exit', function () { /** * List repos. */ - + request({ url: 'https://api.github.com/users/vuejs-templates/repos', headers: { @@ -24,13 +24,10 @@ request({ } }, function (err, res, body) { if (err) { - logger.fatal(err); - }else{ - - var _body = JSON.parse(body); - - if(Array.isArray(_body)){ - + logger.fatal(err) + } else { + var _body = JSON.parse(body) + if (Array.isArray(_body)) { console.log(' Available official templates: \n'); _body.forEach(function (repo) { console.log('%s %s - %s', @@ -38,10 +35,10 @@ request({ chalk.blue(repo.name), repo.description); }); - }else if(_body.hasOwnProperty('message')){ - console.log(chalk.yellow(_body.message)); - }else{ - console.log(_body); + } else if (_body.hasOwnProperty('message')) { + console.log(chalk.yellow(_body.message)) + } else { + console.log(_body) } } }) From 1df4a3b541dcc3d966dd13483f8c87b97796e8d2 Mon Sep 17 00:00:00 2001 From: TJKoury Date: Thu, 28 Jul 2016 10:51:59 -0400 Subject: [PATCH 4/7] Check return length --- bin/vue-list | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/vue-list b/bin/vue-list index 43afc94468..f734eae23a 100755 --- a/bin/vue-list +++ b/bin/vue-list @@ -3,6 +3,7 @@ var logger = require('../lib/logger') var request = require('request') var chalk = require('chalk') +var template_url = 'https://api.github.com/users/vuejs-templates/repos'; /** * Padding. @@ -18,7 +19,7 @@ process.on('exit', function () { */ request({ - url: 'https://api.github.com/users/vuejs-templates/repos', + url: template_url, headers: { 'User-Agent': 'vue-cli' } @@ -27,7 +28,8 @@ request({ logger.fatal(err) } else { var _body = JSON.parse(body) - if (Array.isArray(_body)) { + if (Array.isArray(_body) && + _body.length) { console.log(' Available official templates: \n'); _body.forEach(function (repo) { console.log('%s %s - %s', @@ -35,6 +37,10 @@ request({ chalk.blue(repo.name), repo.description); }); + } else if (!_body.length){ + console.log('%s %s', + chalk.yellow('No Templates found:'), + template_url) } else if (_body.hasOwnProperty('message')) { console.log(chalk.yellow(_body.message)) } else { From 3d1c33a62d97b504fd66faf52afbfa0dba3882e7 Mon Sep 17 00:00:00 2001 From: TJKoury Date: Thu, 28 Jul 2016 11:26:30 -0400 Subject: [PATCH 5/7] Formatting --- bin/vue-list | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/vue-list b/bin/vue-list index f734eae23a..5bea6a95d0 100755 --- a/bin/vue-list +++ b/bin/vue-list @@ -3,7 +3,7 @@ var logger = require('../lib/logger') var request = require('request') var chalk = require('chalk') -var template_url = 'https://api.github.com/users/vuejs-templates/repos'; +var templateUrl = 'https://api.github.com/users/vuejs-templates/repos' /** * Padding. @@ -19,7 +19,7 @@ process.on('exit', function () { */ request({ - url: template_url, + url: templateUrl, headers: { 'User-Agent': 'vue-cli' } @@ -28,16 +28,16 @@ request({ logger.fatal(err) } else { var _body = JSON.parse(body) - if (Array.isArray(_body) && + if (Array.isArray(_body) && _body.length) { - console.log(' Available official templates: \n'); + console.log(' Available official templates: \n') _body.forEach(function (repo) { - console.log('%s %s - %s', - chalk.yellow('★'), - chalk.blue(repo.name), - repo.description); - }); - } else if (!_body.length){ + console.log('%s %s - %s', + chalk.yellow('★'), + chalk.blue(repo.name), + repo.description) + }) + } else if (!_body.length) { console.log('%s %s', chalk.yellow('No Templates found:'), template_url) From 301e22cf71dc6a2ef39baf40740c6900bbfc3fdd Mon Sep 17 00:00:00 2001 From: TJKoury Date: Thu, 28 Jul 2016 11:27:55 -0400 Subject: [PATCH 6/7] Update vue-list --- bin/vue-list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/vue-list b/bin/vue-list index 5bea6a95d0..2689f3e2f2 100755 --- a/bin/vue-list +++ b/bin/vue-list @@ -40,7 +40,7 @@ request({ } else if (!_body.length) { console.log('%s %s', chalk.yellow('No Templates found:'), - template_url) + templateUrl) } else if (_body.hasOwnProperty('message')) { console.log(chalk.yellow(_body.message)) } else { From ab3ca2269b26d0665e1d331a2cf88b5a42b22a68 Mon Sep 17 00:00:00 2001 From: TJKoury Date: Thu, 11 Aug 2016 12:14:43 -0400 Subject: [PATCH 7/7] Update vue-list --- bin/vue-list | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/vue-list b/bin/vue-list index 2689f3e2f2..07b310f6e6 100755 --- a/bin/vue-list +++ b/bin/vue-list @@ -27,24 +27,24 @@ request({ if (err) { logger.fatal(err) } else { - var _body = JSON.parse(body) - if (Array.isArray(_body) && - _body.length) { + body = JSON.parse(body) + if (Array.isArray(body) && + body.length) { console.log(' Available official templates: \n') - _body.forEach(function (repo) { + body.forEach(function (repo) { console.log('%s %s - %s', chalk.yellow('★'), chalk.blue(repo.name), repo.description) }) - } else if (!_body.length) { + } else if (!body.length) { console.log('%s %s', chalk.yellow('No Templates found:'), templateUrl) - } else if (_body.hasOwnProperty('message')) { + } else if (body.hasOwnProperty('message')) { console.log(chalk.yellow(_body.message)) } else { - console.log(_body) + console.log(body) } } })