Implement setting of verbose log level

This commit is contained in:
Jia Hao 2016-03-25 20:50:52 +08:00
parent 7b10e16ddb
commit e7390b9e33
8 changed files with 33 additions and 13 deletions

View File

@ -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.

View File

@ -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",

View File

@ -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;
}
}

View File

@ -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();
});
}

View File

@ -40,6 +40,7 @@ if (require.main === module) {
.option('--inject <value>', '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) {

View File

@ -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() {

View File

@ -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);
});
}

View File

@ -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();