Skip to content

Commit

Permalink
feat: report unreachable urls
Browse files Browse the repository at this point in the history
  • Loading branch information
PopGoesTheWza committed Mar 25, 2021
1 parent 255bc17 commit 8085984
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 40 deletions.
71 changes: 35 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"inquirer": "^8.0.0",
"inquirer-autocomplete-prompt-ipt": "^2.0.0",
"is-reachable": "^5.0.0",
"log-symbols": "^4.1.0",
"loud-rejection": "^2.2.0",
"make-dir": "^3.1.0",
"multimatch": "^5.0.0",
Expand Down
25 changes: 21 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cliTruncate from 'cli-truncate';
import fs from 'fs-extra';
import {script_v1 as scriptV1} from 'googleapis';
import isReachable from 'is-reachable';
import logSymbols from 'log-symbols';
import ora from 'ora';
import path from 'path';

Expand Down Expand Up @@ -202,15 +203,31 @@ export const getApiFileType = (value: string): string => {
*/
// If using a proxy, return true since `isOnline` doesn't work.
// @see https://github.com/googleapis/google-api-nodejs-client#using-a-proxy
export const safeIsOnline = async (): Promise<boolean> =>
Boolean(process.env.HTTP_PROXY || process.env.HTTPS_PROXY) ||
isReachable([
export const safeIsOnline = async (): Promise<boolean> => {
if (process.env.HTTP_PROXY || process.env.HTTPS_PROXY) {
return true;
}

const urls = [
// 'www.googleapis.com',
'script.google.com',
'console.developers.google.com',
'console.cloud.google.com',
'drive.google.com',
]);
];

const promises = urls.map(url => [url, isReachable(url)]);

let allReachable = true;
for (const [url, promise] of promises) {
if (!(await promise)) {
console.log(url, logSymbols.error);
allReachable = false;
}
}

return allReachable;
};

/**
* Checks if the network is available. Gracefully exits if not.
Expand Down

0 comments on commit 8085984

Please sign in to comment.