Skip to content

Commit

Permalink
Change the network check tool (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcanessa authored Mar 8, 2017
1 parent d03814d commit ba12e23
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
11 changes: 4 additions & 7 deletions bin/gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

'use strict';

var GithubReleaseNotes = require('../src/gren');
var GithubReleaseNotes = require('./src/gren');
var gren = new GithubReleaseNotes();
var utils = require('../src/utils');

var utils = require('./src/utils');
var action = utils.getBashOptions(process.argv)['action'];

gren.init()
.then(function (success) {
if(success) {
.then(function() {
return gren[action || 'release']();
}
});
});
7 changes: 2 additions & 5 deletions github-release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
var GithubReleaseNotes = require('./src/gren');
var gren = new GithubReleaseNotes();
var utils = require('./src/utils');

var action = utils.getBashOptions(process.argv)['action'];

gren.init()
.then(function (success) {
if(success) {
.then(function() {
return gren[action || 'release']();
}
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"homepage": "https://github.com/alexcanessa/github-release-notes#readme",
"dependencies": {
"chalk": "^1.1.3",
"connectivity": "^1.0.0",
"es6-promise": "^3.2.1",
"github-api": "^2.1.0",
"is-online": "^5.1.1",
Expand All @@ -41,7 +42,7 @@
"devDependencies": {
"eslint": "^3.6.0",
"eslint-config-standard": "^6.0.1",
"eslint-plugin-promise": "^2.0.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^2.0.0",
"grunt": "^1.0.1",
"grunt-contrib-nodeunit": "^1.0.0",
Expand Down
20 changes: 7 additions & 13 deletions src/gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Github = require('github-api');
var fs = require('fs');
var chalk = require('chalk');
var Promise = Promise || require('es6-promise').Promise;
var isOnline = require('is-online');
var connectivity = require('connectivity');
var ObjectAssign = require('object-assign');

var defaults = {
Expand Down Expand Up @@ -749,12 +749,12 @@ function generateOptions(options) {
*/
function hasNetwork() {
return new Promise(function(resolve, reject) {
isOnline(function(err, online) {
if (err) {
reject(chalk.red(err));
connectivity(function(isOnline) {
if (!isOnline) {
reject(chalk.red('You need to have network connectivity'));
}

resolve(online);
resolve(isOnline);
});
});
}
Expand Down Expand Up @@ -790,12 +790,8 @@ GithubReleaseNotes.prototype.init = function() {
var gren = this;

return hasNetwork()
.then(function(success) {
if (success) {
return generateOptions(gren.options);
} else {
throw chalk.red('You need to have network connectivity');
}
.then(function() {
return generateOptions(gren.options);
})
.then(function(optionData) {
gren.options = ObjectAssign(...optionData, gren.options);
Expand All @@ -810,8 +806,6 @@ GithubReleaseNotes.prototype.init = function() {

gren.repo = githubApi.getRepo(gren.options.username, gren.options.repo);
gren.issues = githubApi.getIssues(gren.options.username, gren.options.repo);

return true;
})
.catch(function(error) {
console.log(error);
Expand Down

0 comments on commit ba12e23

Please sign in to comment.