@@ -5,15 +5,18 @@ var ig = require('imagemagick');
55var colors = require ( 'colors' ) ;
66var _ = require ( 'underscore' ) ;
77var Q = require ( 'q' ) ;
8- var argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
8+ var optparse = require ( 'optparse' ) ;
99
1010/**
1111 * @var {Object} settings - names of the config file and of the splash image
1212 */
1313var settings = { } ;
14- settings . CONFIG_FILE = argv . config || 'config.xml' ;
15- settings . SPLASH_FILE = argv . splash || 'splash.png' ;
16- settings . OLD_XCODE_PATH = argv [ 'xcode-old' ] || false ;
14+ settings . CONFIG_FILE = 'config.xml' ;
15+ settings . SPLASH_FILE = 'splash.png' ;
16+ settings . RESOURCE_PATH = 'config/res' ; // without trailing slash
17+ settings . SCREEN_DIR = 'screen' ; // without slashes
18+ settings . USE_PLATFORMS_PATH = true ; // true to use platforms path
19+ settings . OLD_XCODE_PATH = false ;
1720
1821/**
1922 * Check which platforms are added to the project and return their splash screen names and sizes
@@ -34,7 +37,8 @@ var getPlatforms = function (projectName) {
3437 name : 'ios' ,
3538 // TODO: use async fs.exists
3639 isAdded : fs . existsSync ( 'platforms/ios' ) ,
37- splashPath : 'platforms/ios/' + projectName + xcodeFolder ,
40+ splashPath : ( settings . RESOURCE_PATH + '/' + settings . SCREEN_DIR + '/ios/' ) . replace ( '//' , '/' ) ,
41+ platformSplashPath : 'platforms/ios/' + projectName + xcodeFolder ,
3842 splash : [
3943 // iPhone
4044 { name : 'Default~iphone.png' , width : 320 , height : 480 } ,
@@ -55,7 +59,8 @@ var getPlatforms = function (projectName) {
5559 platforms . push ( {
5660 name : 'android' ,
5761 isAdded : fs . existsSync ( 'platforms/android' ) ,
58- splashPath : 'platforms/android/res/' ,
62+ splashPath : ( settings . RESOURCE_PATH + '/' + settings . SCREEN_DIR + '/android/' ) . replace ( '//' , '/' ) ,
63+ platformSplashPath : 'platforms/android/res/' ,
5964 splash : [
6065 // Landscape
6166 { name : 'drawable-land-ldpi/screen.png' , width : 320 , height : 200 } ,
@@ -76,7 +81,8 @@ var getPlatforms = function (projectName) {
7681 platforms . push ( {
7782 name : 'windows' ,
7883 isAdded : fs . existsSync ( 'platforms/windows' ) ,
79- splashPath : 'platforms/windows/images/' ,
84+ splashPath :( settings . RESOURCE_PATH + '/' + settings . SCREEN_DIR + '/windows/' ) . replace ( '//' , '/' ) ,
85+ platformSplashPath : 'platforms/windows/images/' ,
8086 splash : [
8187 // Landscape
8288 { name : 'SplashScreen.scale-100.png' , width : 620 , height : 300 } ,
@@ -151,7 +157,8 @@ var generateSplash = function (platform, splash) {
151157 if ( fs . existsSync ( platformPath ) ) {
152158 srcPath = platformPath ;
153159 }
154- var dstPath = platform . splashPath + splash . name ;
160+ var dstPath = ( settings . USE_PLATFORMS_PATH ?
161+ platform . platformSplashPath : platform . splashPath ) + splash . name ;
155162 var dst = path . dirname ( dstPath ) ;
156163 if ( ! fs . existsSync ( dst ) ) {
157164 fs . mkdirsSync ( dst ) ;
@@ -168,7 +175,7 @@ var generateSplash = function (platform, splash) {
168175 deferred . reject ( err ) ;
169176 } else {
170177 deferred . resolve ( ) ;
171- display . success ( splash . name + ' created' ) ;
178+ display . success ( splash . name + ' created [' + dstPath + '] ') ;
172179 }
173180 } ) ;
174181 return deferred . promise ;
@@ -280,11 +287,79 @@ var configFileExists = function () {
280287 return deferred . promise ;
281288} ;
282289
290+ var resourcePathExists = function ( ) {
291+ var deferred = Q . defer ( ) ;
292+
293+ if ( ! settings . USE_PLATFORMS_PATH ) {
294+ fs . exists ( settings . RESOURCE_PATH , function ( exists ) {
295+ if ( exists ) {
296+ display . success ( settings . RESOURCE_PATH + ' exists' ) ;
297+ deferred . resolve ( ) ;
298+ } else {
299+ display . error ( 'cordova\'s ' + settings . RESOURCE_PATH + ' does not exist' ) ;
300+ deferred . reject ( ) ;
301+ }
302+ } ) ;
303+ } else {
304+ deferred . resolve ( ) ;
305+ }
306+ return deferred . promise ;
307+ } ;
308+
309+ /**
310+ * parse command line options
311+ */
312+ var parseOptions = function ( ) {
313+ var switches = [
314+ [ '-h' , '--help' , 'Show this help' ] ,
315+ [ '-s' , '--splash DIR' , 'splash file in PATH, defaults to ' + settings . SPLASH_FILE ] ,
316+ [ '-c' , '--config DIR' , 'screen file in PATH, defaults to ' + settings . CONFIG_FILE ] ,
317+ [ '-p' , '--platform' , 'use platform resources path, defaults to ' + settings . USE_PLATFORMS_PATH ] ,
318+ [ '-r' , '--resource PATH' , 'resource path, (overrides -b and -i), defaults to ' + settings . RESOURCE_PATH ] ,
319+ [ '-rs' , '--screen DIR' , 'screen directory in PATH, defaults to ' + settings . SCREEN_DIR ] ,
320+ [ '-xo' , '--xcode-old' , 'use old version of Cordova for iOS and generate file in /Resources/icons/' ] ,
321+ ] ;
322+ var parser = new optparse . OptionParser ( switches ) ;
323+ parser . on ( 'help' , function ( ) {
324+ console . log ( parser . toString ( ) ) ;
325+ process . exit ( ) ;
326+ } ) ;
327+ parser . on ( 'config' , function ( opt , path ) {
328+ settings . CONFIG_FILE = path ;
329+ } ) ;
330+ parser . on ( 'splash' , function ( opt , path ) {
331+ settings . SPLASH_FILE = path ;
332+ } ) ;
333+ parser . on ( 'platform' , function ( opt , path ) {
334+ // Can be use if USE_PLATFORMS_PATH is set to false by default in the future.
335+ settings . USE_PLATFORMS_PATH = true ;
336+ } ) ;
337+ parser . on ( 'resource' , function ( opt , path ) {
338+ // Only update if value provided, otherwise assum default.
339+ if ( path ) {
340+ settings . RESOURCE_PATH = path ;
341+ }
342+ settings . USE_PLATFORMS_PATH = false ;
343+ } ) ;
344+ parser . on ( 'screen' , function ( opt , path ) {
345+ settings . SCREEN_DIR = path ;
346+ settings . USE_PLATFORMS_PATH = false ;
347+ } ) ;
348+ parser . on ( 'xcode-old' , function ( ) {
349+ settings . OLD_XCODE_PATH = true ;
350+ } ) ;
351+
352+ parser . parse ( process . argv ) ;
353+ } ;
354+
355+ parseOptions ( ) ;
356+
283357display . header ( 'Checking Project & Splash' ) ;
284358
285359atLeastOnePlatformFound ( )
286360. then ( validSplashExists )
287361. then ( configFileExists )
362+ . then ( resourcePathExists )
288363. then ( getProjectName )
289364. then ( getPlatforms )
290365. then ( generateSplashes )
0 commit comments