2016-01-18 16:38:52 +01:00
#! /usr/bin/env node
2016-01-24 14:07:22 +01:00
import 'source-map-support/register' ;
2016-01-18 16:38:52 +01:00
import program from 'commander' ;
2016-01-29 07:26:35 +01:00
import nativefier from './index' ;
2017-04-29 16:52:12 +02:00
2017-10-03 17:58:00 +02:00
const dns = require ( 'dns' ) ;
2017-12-19 14:42:06 +01:00
const log = require ( 'loglevel' ) ;
2018-07-21 15:16:02 +02:00
const packageJson = require ( './../package' ) ;
2016-01-18 16:38:52 +01:00
2016-02-25 07:56:32 +01:00
function collect ( val , memo ) {
2017-04-29 16:52:12 +02:00
memo . push ( val ) ;
return memo ;
2016-02-25 07:56:32 +01:00
}
2018-12-01 20:04:55 +01:00
function parseMaybeBoolString ( val ) {
switch ( val ) {
case 'true' :
return true ;
case 'false' :
return false ;
default :
return val ;
}
}
2017-08-15 20:18:44 +02:00
function parseJson ( val ) {
if ( ! val ) return { } ;
return JSON . parse ( val ) ;
}
2017-08-16 16:20:43 +02:00
function getProcessEnvs ( val ) {
if ( ! val ) return { } ;
const pEnv = { } ;
pEnv . processEnvs = parseJson ( val ) ;
return pEnv ;
}
2017-10-03 17:58:00 +02:00
function checkInternet ( ) {
dns . lookup ( 'npmjs.com' , ( err ) => {
if ( err && err . code === 'ENOTFOUND' ) {
2018-05-24 09:02:44 +02:00
log . warn (
'\nNo Internet Connection\nTo offline build, download electron from https://github.com/electron/electron/releases\nand place in ~/AppData/Local/electron/Cache/ on Windows,\n~/.cache/electron on Linux or ~/Library/Caches/electron/ on Mac\nUse --electron-version to specify the version you downloaded.' ,
) ;
2017-10-03 17:58:00 +02:00
}
} ) ;
}
2016-01-18 16:38:52 +01:00
if ( require . main === module ) {
2018-12-01 20:04:55 +01:00
const sanitizedArgs = [ ] ;
process . argv . forEach ( ( arg ) => {
if ( sanitizedArgs . length > 0 ) {
const previousArg = sanitizedArgs [ sanitizedArgs . length - 1 ] ;
// Work around commander.js not supporting default argument for options
if (
previousArg === '--tray' &&
! [ 'true' , 'false' , 'start-in-tray' ] . includes ( arg )
) {
sanitizedArgs . push ( 'true' ) ;
}
}
sanitizedArgs . push ( arg ) ;
} ) ;
2017-04-29 16:52:12 +02:00
program
2018-08-01 02:29:26 +02:00
. version ( packageJson . version , '-v, --version' )
2017-04-29 16:52:12 +02:00
. arguments ( '<targetUrl> [dest]' )
. action ( ( targetUrl , appDir ) => {
program . targetUrl = targetUrl ;
program . out = appDir ;
} )
. option ( '-n, --name <value>' , 'app name' )
2018-05-24 09:02:44 +02:00
. option ( '-p, --platform <value>' , "'osx', 'mas', 'linux' or 'windows'" )
. option ( '-a, --arch <value>' , "'ia32' or 'x64' or 'armv7l'" )
. option (
'--app-version <value>' ,
'The release version of the application. Maps to the `ProductVersion` metadata property on Windows, and `CFBundleShortVersionString` on OS X.' ,
)
. option (
'--build-version <value>' ,
'The build version of the application. Maps to the `FileVersion` metadata property on Windows, and `CFBundleVersion` on OS X.' ,
)
. option (
'--app-copyright <value>' ,
'The human-readable copyright line for the app. Maps to the `LegalCopyright` metadata property on Windows, and `NSHumanReadableCopyright` on OS X' ,
)
. option (
'--win32metadata <json-string>' ,
'a JSON string of key/value pairs of application metadata (ProductName, InternalName, FileDescription) to embed into the executable (Windows only).' ,
parseJson ,
)
. option (
'-e, --electron-version <value>' ,
2018-10-27 03:45:19 +02:00
"electron version to package, without the 'v', see https://github.com/electron/electron/releases" ,
2018-05-24 09:02:44 +02:00
)
. option (
'--no-overwrite' ,
'do not override output directory if it already exists, defaults to false' ,
)
. option (
'-c, --conceal' ,
2018-10-27 03:45:19 +02:00
'packages the source code within your app into an archive, defaults to false, see https://electronjs.org/docs/tutorial/application-packaging' ,
2018-05-24 09:02:44 +02:00
)
. option (
'--counter' ,
'if the target app should use a persistent counter badge in the dock (macOS only), defaults to false' ,
)
. option (
'--bounce' ,
'if the the dock icon should bounce when counter increases (macOS only), defaults to false' ,
)
. option (
'-i, --icon <value>' ,
'the icon file to use as the icon for the app (should be a .png)' ,
)
. option (
'--width <value>' ,
'set window default width, defaults to 1280px' ,
parseInt ,
)
. option (
'--height <value>' ,
'set window default height, defaults to 800px' ,
parseInt ,
)
. option (
'--min-width <value>' ,
'set window minimum width, defaults to 0px' ,
parseInt ,
)
. option (
'--min-height <value>' ,
'set window minimum height, defaults to 0px' ,
parseInt ,
)
. option (
'--max-width <value>' ,
'set window maximum width, default is no limit' ,
parseInt ,
)
. option (
'--max-height <value>' ,
'set window maximum height, default is no limit' ,
parseInt ,
)
2017-12-26 19:00:39 +01:00
. option ( '--x <value>' , 'set window x location' , parseInt )
. option ( '--y <value>' , 'set window y location' , parseInt )
2017-04-29 16:52:12 +02:00
. option ( '-m, --show-menu-bar' , 'set menu bar visible, defaults to false' )
2018-05-24 09:02:44 +02:00
. option (
'-f, --fast-quit' ,
'quit app after window close (macOS only), defaults to false' ,
)
2017-04-29 16:52:12 +02:00
. option ( '-u, --user-agent <value>' , 'set the user agent string for the app' )
2018-05-24 09:02:44 +02:00
. option (
'--honest' ,
'prevent the nativefied app from changing the user agent string to masquerade as a regular chrome browser' ,
)
2017-04-29 16:52:12 +02:00
. option ( '--ignore-certificate' , 'ignore certificate related errors' )
2018-04-22 21:56:10 +02:00
. option ( '--disable-gpu' , 'disable hardware acceleration' )
2018-05-24 09:02:44 +02:00
. option (
'--ignore-gpu-blacklist' ,
'allow WebGl apps to work on non supported graphics cards' ,
)
2017-07-13 18:23:07 +02:00
. option ( '--enable-es3-apis' , 'force activation of WebGl 2.0' )
2018-05-24 09:02:44 +02:00
. option (
'--insecure' ,
'enable loading of insecure content, defaults to false' ,
)
2017-04-29 16:52:12 +02:00
. option ( '--flash' , 'if flash should be enabled' )
2018-05-24 09:02:44 +02:00
. option (
'--flash-path <value>' ,
'path to Chrome flash plugin, find it in `Chrome://plugins`' ,
)
. option (
'--disk-cache-size <value>' ,
'forces the maximum disk space (in bytes) to be used by the disk cache' ,
)
. option (
'--inject <value>' ,
'path to a CSS/JS file to be injected' ,
collect ,
[ ] ,
)
. option (
'--full-screen' ,
'if the app should always be started in full screen' ,
)
2017-04-29 16:52:12 +02:00
. option ( '--maximize' , 'if the app should always be started maximized' )
. option ( '--hide-window-frame' , 'disable window frame and controls' )
. option ( '--verbose' , 'if verbose logs should be displayed' )
. option ( '--disable-context-menu' , 'disable the context menu' )
. option ( '--disable-dev-tools' , 'disable developer tools' )
2018-05-24 09:02:44 +02:00
. option (
'--zoom <value>' ,
'default zoom factor to use when the app is opened, defaults to 1.0' ,
parseFloat ,
)
. option (
'--internal-urls <value>' ,
'regular expression of URLs to consider "internal"; all other URLs will be opened in an external browser. (default: URLs on same second-level domain as app)' ,
)
. option (
'--crash-reporter <value>' ,
'remote server URL to send crash reports' ,
)
. option (
'--single-instance' ,
'allow only a single instance of the application' ,
)
2019-02-08 16:03:29 +01:00
. option (
'--clear-cache' ,
'prevent the application from preserving cache between launches' ,
)
2018-05-24 09:02:44 +02:00
. option (
'--processEnvs <json-string>' ,
'a JSON string of key/value pairs to be set as environment variables before any browser windows are opened.' ,
getProcessEnvs ,
)
. option (
'--file-download-options <json-string>' ,
'a JSON string of key/value pairs to be set as file download options. See https://github.com/sindresorhus/electron-dl for available options.' ,
parseJson ,
)
2018-12-01 20:04:55 +01:00
. option (
'--tray [start-in-tray]' ,
"Allow app to stay in system tray. If 'start-in-tray' is given as argument, don't show main window on first start" ,
parseMaybeBoolString ,
)
2017-10-06 00:44:03 +02:00
. option ( '--basic-auth-username <value>' , 'basic http(s) auth username' )
. option ( '--basic-auth-password <value>' , 'basic http(s) auth password' )
2018-03-16 23:15:44 +01:00
. option ( '--always-on-top' , 'enable always on top window' )
2018-05-31 14:05:12 +02:00
. option (
'--title-bar-style <value>' ,
"(macOS only) set title bar style ('hidden', 'hiddenInset'). Consider injecting custom CSS (via --inject) for better integration." ,
)
2018-11-05 03:03:52 +01:00
. option (
'--global-shortcuts <value>' ,
'JSON file with global shortcut configuration. See https://github.com/jiahaog/nativefier/blob/master/docs/api.md#global-shortcuts' ,
)
2019-08-22 21:37:49 +02:00
. option (
'--browserwindow-options <json-string>' ,
'a JSON string that will be sent directly into electron BrowserWindow options. See https://github.com/jiahaog/nativefier/blob/master/docs/api.md#browserwindow-options' ,
parseJson ,
)
2019-08-22 21:25:58 +02:00
. option (
'--background-color <value>' ,
"Sets the background color (for seamless experience while the app is loading). Example value: '#2e2c29'" ,
)
2019-08-22 21:05:39 +02:00
. option (
'--darwin-dark-mode-support' ,
'(macOS only) enable Dark Mode support on macOS 10.14+' ,
)
2018-12-01 20:04:55 +01:00
. parse ( sanitizedArgs ) ;
2016-02-25 07:56:32 +01:00
2017-04-29 16:52:12 +02:00
if ( ! process . argv . slice ( 2 ) . length ) {
program . help ( ) ;
}
2017-10-03 17:58:00 +02:00
checkInternet ( ) ;
2017-04-29 16:52:12 +02:00
nativefier ( program , ( error , appPath ) => {
if ( error ) {
2017-12-19 14:42:06 +01:00
log . error ( error ) ;
2017-04-29 16:52:12 +02:00
return ;
2016-01-18 16:38:52 +01:00
}
2017-04-29 16:52:12 +02:00
if ( ! appPath ) {
// app exists and --overwrite is not passed
return ;
}
2017-12-19 14:42:06 +01:00
log . info ( ` App built to ${ appPath } ` ) ;
2017-04-29 16:52:12 +02:00
} ) ;
2016-01-18 16:38:52 +01:00
}