@@ -372,8 +372,8 @@ package com.as3mxml.asconfigc
372
372
373
373
protected static function parseFiles (files :Array , result :Array ):void
374
374
{
375
- var selfFolders : Array = [];
376
- var rootFolders : Array = [];
375
+ var cOptionFolders : Array = [];
376
+ var cOptionRootFolders : Array = [];
377
377
var count : int = files. length ;
378
378
for (var i: int = 0 ; i < count ; i++ )
379
379
{
@@ -397,21 +397,21 @@ package com.as3mxml.asconfigc
397
397
{
398
398
//add these folders after everything else because we'll
399
399
//use the -C option
400
- selfFolders . push (srcFile);
400
+ cOptionFolders . push (new FolderToAddWithCOption( srcFile, null ) );
401
401
continue ;
402
402
}
403
- else if (destPath == path . basename(srcFile) )
403
+ else if (destPath == "." )
404
404
{
405
405
//add these folders after everything else because we'll
406
406
//use the -C option
407
- selfFolders . push (srcFile);
407
+ cOptionRootFolders . push (srcFile);
408
408
continue ;
409
409
}
410
- else if (destPath == "." )
410
+ else if (canUseCOptionForFolder(srcFile, destPath) )
411
411
{
412
412
//add these folders after everything else because we'll
413
413
//use the -C option
414
- rootFolders . push (srcFile);
414
+ cOptionFolders . push (new FolderToAddWithCOption( srcFile, destPath) );
415
415
continue ;
416
416
}
417
417
}
@@ -422,24 +422,70 @@ package com.as3mxml.asconfigc
422
422
}
423
423
addFile(srcFile, destPath, result );
424
424
}
425
- count = rootFolders . length ;
425
+ count = cOptionRootFolders . length ;
426
426
for (i = 0 ; i < count ; i++ )
427
427
{
428
- folder = rootFolders [ i];
428
+ var folder: String = cOptionRootFolders [ i];
429
429
result . push ("-C" );
430
430
result . push (folder);
431
431
result . push ("." );
432
432
}
433
- count = selfFolders . length ;
433
+ count = cOptionFolders . length ;
434
434
for (i = 0 ; i < count ; i++ )
435
435
{
436
- var folder: String = selfFolders[ i];
437
- result . push ("-C" );
438
- result . push (path. dirname(folder));
439
- result . push (path. basename(folder));
436
+ var cOptionFolder: FolderToAddWithCOption = FolderToAddWithCOption(cOptionFolders[ i] );
437
+ var cOptionFolderSrcPath: String = cOptionFolder. srcPath;
438
+ var cOptionFolderDestPath: String = cOptionFolder. destPath;
439
+ if (! cOptionFolderDestPath)
440
+ {
441
+ result . push ("-C" );
442
+ result . push (path. dirname(cOptionFolderSrcPath));
443
+ result . push (path. basename(cOptionFolderSrcPath));
444
+ }
445
+ else
446
+ {
447
+ var baseFolderPath: String = cOptionFolderSrcPath;
448
+ var currentDestPath: String = cOptionFolderDestPath;
449
+ do
450
+ {
451
+ baseFolderPath = path. dirname(baseFolderPath);
452
+ if (baseFolderPath === "." ) {
453
+ break ;
454
+ }
455
+ currentDestPath = path. dirname(currentDestPath);
456
+ }
457
+ while (currentDestPath !== "." );
458
+
459
+ result . push ("-C" );
460
+ result . push (baseFolderPath);
461
+ result . push (cOptionFolderDestPath);
462
+ }
440
463
}
441
464
}
442
465
466
+ protected static function canUseCOptionForFolder (srcFolder :String , destPath :String ):Boolean
467
+ {
468
+ var currentSrcPath: String = srcFolder;
469
+ var currentDestPath: String = destPath;
470
+ do
471
+ {
472
+ if (currentSrcPath === "." )
473
+ {
474
+ return false ;
475
+ }
476
+ var currentSrcName: String = path. basename(currentSrcPath);
477
+ var currentDestName: String = path. basename(currentDestPath);
478
+ if (currentSrcName !== currentDestName)
479
+ {
480
+ return false ;
481
+ }
482
+ currentSrcPath = path. dirname(currentSrcPath);
483
+ currentDestPath = path. dirname(currentDestPath);
484
+ }
485
+ while (currentDestPath !== "." );
486
+ return true ;
487
+ }
488
+
443
489
protected static function addFile (srcFile :String , destPath :String , result :Array ):void
444
490
{
445
491
if (fs. statSync(srcFile). isDirectory())
@@ -521,4 +567,15 @@ package com.as3mxml.asconfigc
521
567
}
522
568
}
523
569
}
570
+ }
571
+
572
+ class FolderToAddWithCOption {
573
+ public function FolderToAddWithCOption (srcPath :String , destPath :String )
574
+ {
575
+ this . srcPath = srcPath;
576
+ this . destPath = destPath;
577
+ }
578
+
579
+ public var srcPath: String ;
580
+ public var destPath: String ;
524
581
}
0 commit comments