Skip to content

Commit 8810eba

Browse files
committed
AIROptionsParser: add more folders with -C option instead of -e to reduce command line string (references BowlerHatLLC/vscode-as3mxml#388)
1 parent ef452a7 commit 8810eba

File tree

1 file changed

+71
-14
lines changed

1 file changed

+71
-14
lines changed

src/com/as3mxml/asconfigc/AIROptionsParser.as

+71-14
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ package com.as3mxml.asconfigc
372372

373373
protected static function parseFiles(files:Array, result:Array):void
374374
{
375-
var selfFolders:Array = [];
376-
var rootFolders:Array = [];
375+
var cOptionFolders:Array = [];
376+
var cOptionRootFolders:Array = [];
377377
var count:int = files.length;
378378
for(var i:int = 0; i < count; i++)
379379
{
@@ -397,21 +397,21 @@ package com.as3mxml.asconfigc
397397
{
398398
//add these folders after everything else because we'll
399399
//use the -C option
400-
selfFolders.push(srcFile);
400+
cOptionFolders.push(new FolderToAddWithCOption(srcFile, null));
401401
continue;
402402
}
403-
else if(destPath == path.basename(srcFile))
403+
else if(destPath == ".")
404404
{
405405
//add these folders after everything else because we'll
406406
//use the -C option
407-
selfFolders.push(srcFile);
407+
cOptionRootFolders.push(srcFile);
408408
continue;
409409
}
410-
else if(destPath == ".")
410+
else if(canUseCOptionForFolder(srcFile, destPath))
411411
{
412412
//add these folders after everything else because we'll
413413
//use the -C option
414-
rootFolders.push(srcFile);
414+
cOptionFolders.push(new FolderToAddWithCOption(srcFile, destPath));
415415
continue;
416416
}
417417
}
@@ -422,24 +422,70 @@ package com.as3mxml.asconfigc
422422
}
423423
addFile(srcFile, destPath, result);
424424
}
425-
count = rootFolders.length;
425+
count = cOptionRootFolders.length;
426426
for(i = 0; i < count; i++)
427427
{
428-
folder = rootFolders[i];
428+
var folder:String = cOptionRootFolders[i];
429429
result.push("-C");
430430
result.push(folder);
431431
result.push(".");
432432
}
433-
count = selfFolders.length;
433+
count = cOptionFolders.length;
434434
for(i = 0; i < count; i++)
435435
{
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+
}
440463
}
441464
}
442465

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+
443489
protected static function addFile(srcFile:String, destPath:String, result:Array):void
444490
{
445491
if(fs.statSync(srcFile).isDirectory())
@@ -521,4 +567,15 @@ package com.as3mxml.asconfigc
521567
}
522568
}
523569
}
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;
524581
}

0 commit comments

Comments
 (0)