diff --git a/docs/api.md b/docs/api.md index f286ed4..b7359a6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -26,6 +26,7 @@ - [[inject]](#inject) - [[full-screen]](#full-screen) - [[maximize]](#maximize) + - [[verbose]](#verbose) - [Programmatic API](#programmatic-api) ## Command Line @@ -236,6 +237,14 @@ Makes the packaged app start in full screen. Makes the packaged app start maximized. +#### [verbose] + +``` +--verbose +``` + +Shows detailed logs in the console. + ## Programmatic API You can use the Nativefier programmatic API as well. diff --git a/package.json b/package.json index 68249b8..5cf8930 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "gitcloud": "^0.1.0", "hasbin": "^1.2.0", "lodash": "^4.0.0", + "loglevel": "^1.4.0", "ncp": "^2.0.0", "page-icon": "^0.3.0", "progress": "^1.1.8", diff --git a/src/build/buildMain.js b/src/build/buildMain.js index 0da0844..5b7b059 100644 --- a/src/build/buildMain.js +++ b/src/build/buildMain.js @@ -4,6 +4,7 @@ import tmp from 'tmp'; import ncp from 'ncp'; import async from 'async'; import hasBinary from 'hasbin'; +import log from 'loglevel'; import DishonestProgress from './../helpers/dishonestProgress'; import optionsFactory from './../options/optionsMain'; import iconBuild from './iconBuild'; @@ -107,7 +108,7 @@ function getAppPath(appPathArray) { } if (appPathArray.length > 1) { - console.warn('Warning: This should not be happening, packaged app path contains more than one element:', appPathArray); + log.warn('Warning: This should not be happening, packaged app path contains more than one element:', appPathArray); } return appPathArray[0]; @@ -121,7 +122,7 @@ function maybeNoIconOption(options) { const packageOptions = JSON.parse(JSON.stringify(options)); if (options.platform === 'win32' && !isWindows()) { if (!hasBinary.sync('wine')) { - console.warn('Wine is required to set the icon for a Windows app when packaging on non-windows platforms'); + log.warn('Wine is required to set the icon for a Windows app when packaging on non-windows platforms'); packageOptions.icon = null; } } diff --git a/src/build/iconBuild.js b/src/build/iconBuild.js index 2d27421..cc754df 100644 --- a/src/build/iconBuild.js +++ b/src/build/iconBuild.js @@ -1,4 +1,5 @@ import path from 'path'; +import log from 'loglevel'; import helpers from './../helpers/helpers'; import iconShellHelpers from './../helpers/iconShellHelpers'; @@ -41,7 +42,7 @@ function iconBuild(options, callback) { returnCallback(); }) .catch(error => { - console.warn('Skipping icon conversion to .ico', error); + log.warn('Skipping icon conversion to .ico', error); returnCallback(); }); return; @@ -59,7 +60,7 @@ function iconBuild(options, callback) { returnCallback(); }) .catch(error => { - console.warn('Skipping icon conversion to .png', error); + log.warn('Skipping icon conversion to .png', error); returnCallback(); }); return; @@ -71,7 +72,7 @@ function iconBuild(options, callback) { } if (!isOSX()) { - console.warn('Skipping icon conversion to .icns, conversion is only supported on OSX'); + log.warn('Skipping icon conversion to .icns, conversion is only supported on OSX'); returnCallback(); return; } @@ -82,7 +83,7 @@ function iconBuild(options, callback) { returnCallback(); }) .catch(error => { - console.warn('Skipping icon conversion to .icns', error); + log.warn('Skipping icon conversion to .icns', error); returnCallback(); }); } diff --git a/src/cli.js b/src/cli.js index 7c1fb0a..f773357 100755 --- a/src/cli.js +++ b/src/cli.js @@ -40,6 +40,7 @@ if (require.main === module) { .option('--inject ', 'path to a file to be injected', collect, []) .option('--full-screen', 'if the app should always be started in full screen') .option('--maximize', 'if the app should always be started maximized') + .option('--verbose', 'if verbose logs should be displayed') .parse(process.argv); if (!process.argv.slice(2).length) { diff --git a/src/infer/inferOs.js b/src/infer/inferOs.js index b6846a8..2f091c9 100644 --- a/src/infer/inferOs.js +++ b/src/infer/inferOs.js @@ -6,8 +6,7 @@ function inferPlatform() { return platform; } - console.warn(`Warning: Untested platform ${platform} detected, assuming linux`); - return 'linux'; + throw `Untested platform ${platform} detected`; } function inferArch() { diff --git a/src/infer/inferUserAgent.js b/src/infer/inferUserAgent.js index ab0355d..48fa025 100644 --- a/src/infer/inferUserAgent.js +++ b/src/infer/inferUserAgent.js @@ -1,11 +1,11 @@ import axios from 'axios'; import _ from 'lodash'; +import log from 'loglevel'; const ELECTRON_VERSIONS_URL = 'https://atom.io/download/atom-shell/index.json'; const DEFAULT_CHROME_VERSION = '47.0.2526.73'; function getChromeVersionForElectronVersion(electronVersion, url = ELECTRON_VERSIONS_URL) { - return axios.get(url, {timeout: 5000}) .then(response => { if (response.status !== 200) { @@ -47,7 +47,7 @@ function inferUserAgent(electronVersion, platform, url = ELECTRON_VERSIONS_URL) return getUserAgentString(chromeVersion, platform); }) .catch(() => { - // console.warn(`Unable to infer chrome version for user agent, using ${DEFAULT_CHROME_VERSION}`); + log.warn(`Unable to infer chrome version for user agent, using ${DEFAULT_CHROME_VERSION}`); return getUserAgentString(DEFAULT_CHROME_VERSION, platform); }); } diff --git a/src/options/optionsMain.js b/src/options/optionsMain.js index cf02279..a9e778a 100644 --- a/src/options/optionsMain.js +++ b/src/options/optionsMain.js @@ -1,6 +1,7 @@ import path from 'path'; import _ from 'lodash'; import async from 'async'; +import log from 'loglevel'; import sanitizeFilenameLib from 'sanitize-filename'; import inferIcon from './../infer/inferIcon'; @@ -52,9 +53,16 @@ function optionsFactory(inpOptions, callback) { flashPluginDir: inpOptions.flash || null, inject: inpOptions.inject || null, fullScreen: inpOptions.fullScreen || false, - maximize: inpOptions.maximize || false + maximize: inpOptions.maximize || false, + verbose: inpOptions.verbose }; + if (options.verbose) { + log.setLevel('trace'); + } else { + log.setLevel('error'); + } + if (inpOptions.honest) { options.userAgent = null; } @@ -91,7 +99,7 @@ function optionsFactory(inpOptions, callback) { callback(); }) .catch(error => { - console.warn('Cannot automatically retrieve the app icon:', error); + log.warn('Cannot automatically retrieve the app icon:', error); callback(); }); }, @@ -104,7 +112,7 @@ function optionsFactory(inpOptions, callback) { inferTitle(options.targetUrl, function(error, pageTitle) { if (error) { - console.warn(`Unable to automatically determine app name, falling back to '${DEFAULT_APP_NAME}'`); + log.warn(`Unable to automatically determine app name, falling back to '${DEFAULT_APP_NAME}'`); options.name = DEFAULT_APP_NAME; } else { options.name = pageTitle.trim();