@@ -23,6 +23,7 @@ var helpers = require('./helpers'),
23
23
events = require ( 'cordova-common' ) . events ,
24
24
ConfigParser = require ( 'cordova-common' ) . ConfigParser ,
25
25
create = require ( '../index' ) ,
26
+ fs = require ( 'fs' ) ,
26
27
CordovaLogger = require ( 'cordova-common' ) . CordovaLogger . get ( ) . setLevel ( 'error' ) ;
27
28
28
29
var tmpDir = helpers . tmpDir ( 'create_test' ) ;
@@ -328,4 +329,186 @@ describe('create end-to-end', function() {
328
329
. fin ( done ) ;
329
330
} , 60000 ) ;
330
331
332
+ describe ( 'when --link-to is provided' , function ( ) {
333
+ it ( 'when passed www folder should not move www/config.xml, only copy and update' , function ( done ) {
334
+ function checkSymWWW ( ) {
335
+ // Check if top level dirs exist.
336
+ var dirs = [ 'hooks' , 'platforms' , 'plugins' , 'www' ] ;
337
+ dirs . forEach ( function ( d ) {
338
+ expect ( path . join ( project , d ) ) . toExist ( ) ;
339
+ } ) ;
340
+ expect ( path . join ( project , 'hooks' , 'README.md' ) ) . toExist ( ) ;
341
+
342
+ // Check if www files exist.
343
+ expect ( path . join ( project , 'www' , 'index.html' ) ) . toExist ( ) ;
344
+
345
+ // Check www/config exists
346
+ expect ( path . join ( project , 'www' , 'config.xml' ) ) . toExist ( ) ;
347
+ // Check www/config.xml was not updated.
348
+ var configXml = new ConfigParser ( path . join ( project , 'www' , 'config.xml' ) ) ;
349
+ expect ( configXml . packageName ( ) ) . toEqual ( 'io.cordova.hellocordova' ) ;
350
+ expect ( configXml . version ( ) ) . toEqual ( '0.0.1' ) ;
351
+ expect ( configXml . description ( ) ) . toEqual ( 'this is the correct config.xml' ) ;
352
+
353
+ // Check that config.xml was copied to project/config.xml
354
+ expect ( path . join ( project , 'config.xml' ) ) . toExist ( ) ;
355
+ configXml = new ConfigParser ( path . join ( project , 'config.xml' ) ) ;
356
+ expect ( configXml . description ( ) ) . toEqual ( 'this is the correct config.xml' ) ;
357
+ // Check project/config.xml was updated.
358
+ expect ( configXml . packageName ( ) ) . toEqual ( appId ) ;
359
+ expect ( configXml . version ( ) ) . toEqual ( '1.0.0' ) ;
360
+
361
+ // Check that we got no package.json
362
+ expect ( path . join ( project , 'package.json' ) ) . not . toExist ( ) ;
363
+
364
+ // Check that www is really a symlink,
365
+ // and project/config.xml , hooks and merges are not
366
+ expect ( fs . lstatSync ( path . join ( project , 'www' ) ) . isSymbolicLink ( ) ) . toBe ( true ) ;
367
+ expect ( fs . lstatSync ( path . join ( project , 'hooks' ) ) . isSymbolicLink ( ) ) . not . toBe ( true ) ;
368
+ expect ( fs . lstatSync ( path . join ( project , 'config.xml' ) ) . isSymbolicLink ( ) ) . not . toBe ( true ) ;
369
+ }
370
+ var config = {
371
+ lib : {
372
+ www : {
373
+ template : true ,
374
+ url : path . join ( __dirname , 'templates' , 'config_in_www' , 'www' ) ,
375
+ version : '' ,
376
+ link : true
377
+ }
378
+ }
379
+ } ;
380
+ project = project + '4' ;
381
+ return create ( project , appId , appName , config )
382
+ . then ( checkSymWWW )
383
+ . fail ( function ( err ) {
384
+ if ( process . platform . slice ( 0 , 3 ) == 'win' ) {
385
+ // Allow symlink error if not in admin mode
386
+ expect ( err . message ) . toBe ( 'Symlinks on Windows require Administrator privileges' ) ;
387
+ } else {
388
+ if ( err ) {
389
+ console . log ( err . stack ) ;
390
+ }
391
+ expect ( err ) . toBeUndefined ( ) ;
392
+ }
393
+ } )
394
+ . fin ( done ) ;
395
+ } , 60000 ) ;
396
+
397
+ it ( 'with subdirectory should not update symlinked project/config.xml' , function ( done ) {
398
+ function checkSymSubDir ( ) {
399
+ // Check if top level dirs exist.
400
+ var dirs = [ 'hooks' , 'platforms' , 'plugins' , 'www' ] ;
401
+ dirs . forEach ( function ( d ) {
402
+ expect ( path . join ( project , d ) ) . toExist ( ) ;
403
+ } ) ;
404
+ expect ( path . join ( project , 'hooks' , 'README.md' ) ) . toExist ( ) ;
405
+
406
+ //index.js and template subdir folder should not exist (inner files should be copied to the project folder)
407
+ expect ( path . join ( project , 'index.js' ) ) . not . toExist ( ) ;
408
+ expect ( path . join ( project , 'template' ) ) . not . toExist ( ) ;
409
+
410
+ // Check if www files exist.
411
+ expect ( path . join ( project , 'www' , 'index.html' ) ) . toExist ( ) ;
412
+
413
+ // Check that www, and config.xml is really a symlink
414
+ expect ( fs . lstatSync ( path . join ( project , 'www' ) ) . isSymbolicLink ( ) ) . toBe ( true ) ;
415
+ expect ( fs . lstatSync ( path . join ( project , 'config.xml' ) ) . isSymbolicLink ( ) ) . toBe ( true ) ;
416
+
417
+ // Check that config.xml was not updated. (symlinked config does not get updated!)
418
+ var configXml = new ConfigParser ( path . join ( project , 'config.xml' ) ) ;
419
+ expect ( configXml . packageName ( ) ) . toEqual ( 'io.cordova.hellocordova' ) ;
420
+ expect ( configXml . version ( ) ) . toEqual ( '0.0.1' ) ;
421
+
422
+ // Check that we got the right config.xml
423
+ expect ( configXml . description ( ) ) . toEqual ( 'this is the correct config.xml' ) ;
424
+
425
+ // Check that we got package.json (the correct one) and it was changed
426
+ var pkjson = require ( path . join ( project , 'package.json' ) ) ;
427
+ expect ( pkjson . name ) . toEqual ( appName . toLowerCase ( ) ) ;
428
+ expect ( pkjson . valid ) . toEqual ( 'true' ) ;
429
+ }
430
+ var config = {
431
+ lib : {
432
+ www : {
433
+ template : true ,
434
+ url : path . join ( __dirname , 'templates' , 'withsubdirectory_package_json' ) ,
435
+ version : '' ,
436
+ link : true
437
+ }
438
+ }
439
+ } ;
440
+ project = project + '5' ;
441
+ return create ( project , appId , appName , config )
442
+ . then ( checkSymSubDir )
443
+ . fail ( function ( err ) {
444
+ if ( process . platform . slice ( 0 , 3 ) == 'win' ) {
445
+ // Allow symlink error if not in admin mode
446
+ expect ( err . message ) . toBe ( 'Symlinks on Windows require Administrator privileges' ) ;
447
+ } else {
448
+ if ( err ) {
449
+ console . log ( err . stack ) ;
450
+ }
451
+ expect ( err ) . toBeUndefined ( ) ;
452
+ }
453
+ } )
454
+ . fin ( done ) ;
455
+ } , 60000 ) ;
456
+
457
+ it ( 'with no config should create one and update it' , function ( done ) {
458
+ function checkSymNoConfig ( ) {
459
+ // Check if top level dirs exist.
460
+ var dirs = [ 'hooks' , 'platforms' , 'plugins' , 'www' ] ;
461
+ dirs . forEach ( function ( d ) {
462
+ expect ( path . join ( project , d ) ) . toExist ( ) ;
463
+ } ) ;
464
+ expect ( path . join ( project , 'hooks' , 'hooks.file' ) ) . toExist ( ) ;
465
+ expect ( path . join ( project , 'merges' , 'merges.file' ) ) . toExist ( ) ;
466
+
467
+ // Check if www files exist.
468
+ expect ( path . join ( project , 'www' , 'index.html' ) ) . toExist ( ) ;
469
+
470
+ // Check that config.xml was updated.
471
+ var configXml = new ConfigParser ( path . join ( project , 'config.xml' ) ) ;
472
+ expect ( configXml . packageName ( ) ) . toEqual ( appId ) ;
473
+
474
+ // Check that www, hooks, merges are really a symlink; config is not
475
+ expect ( fs . lstatSync ( path . join ( project , 'www' ) ) . isSymbolicLink ( ) ) . toBe ( true ) ;
476
+ expect ( fs . lstatSync ( path . join ( project , 'hooks' ) ) . isSymbolicLink ( ) ) . toBe ( true ) ;
477
+ expect ( fs . lstatSync ( path . join ( project , 'merges' ) ) . isSymbolicLink ( ) ) . toBe ( true ) ;
478
+ expect ( fs . lstatSync ( path . join ( project , 'config.xml' ) ) . isSymbolicLink ( ) ) . not . toBe ( true ) ;
479
+ }
480
+
481
+ var config = {
482
+ lib : {
483
+ www : {
484
+ template : true ,
485
+ url : path . join ( __dirname , 'templates' , 'noconfig' ) ,
486
+ version : '' ,
487
+ link : true
488
+ }
489
+ }
490
+ } ;
491
+ project = project + '6' ;
492
+ return create ( project , appId , appName , config )
493
+ . then ( checkSymNoConfig )
494
+ . fail ( function ( err ) {
495
+ if ( process . platform . slice ( 0 , 3 ) == 'win' ) {
496
+ // Allow symlink error if not in admin mode
497
+ expect ( err . message ) . toBe ( 'Symlinks on Windows require Administrator privileges' ) ;
498
+ } else {
499
+ if ( err ) {
500
+ console . log ( err . stack ) ;
501
+ }
502
+ expect ( err ) . toBeUndefined ( ) ;
503
+ }
504
+ } )
505
+ . fin ( done ) ;
506
+ } , 60000 ) ;
507
+
508
+ } ) ;
509
+
510
+
511
+
512
+
513
+
331
514
} ) ;
0 commit comments