Skip to content

Commit

Permalink
AIROptionsParser: add more folders with -C option instead of -e to re…
Browse files Browse the repository at this point in the history
…duce command line string (references BowlerHatLLC/vscode-as3mxml#388)
  • Loading branch information
joshtynjala committed Oct 16, 2020
1 parent ef452a7 commit 8810eba
Showing 1 changed file with 71 additions and 14 deletions.
85 changes: 71 additions & 14 deletions src/com/as3mxml/asconfigc/AIROptionsParser.as
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ package com.as3mxml.asconfigc

protected static function parseFiles(files:Array, result:Array):void
{
var selfFolders:Array = [];
var rootFolders:Array = [];
var cOptionFolders:Array = [];
var cOptionRootFolders:Array = [];
var count:int = files.length;
for(var i:int = 0; i < count; i++)
{
Expand All @@ -397,21 +397,21 @@ package com.as3mxml.asconfigc
{
//add these folders after everything else because we'll
//use the -C option
selfFolders.push(srcFile);
cOptionFolders.push(new FolderToAddWithCOption(srcFile, null));
continue;
}
else if(destPath == path.basename(srcFile))
else if(destPath == ".")
{
//add these folders after everything else because we'll
//use the -C option
selfFolders.push(srcFile);
cOptionRootFolders.push(srcFile);
continue;
}
else if(destPath == ".")
else if(canUseCOptionForFolder(srcFile, destPath))
{
//add these folders after everything else because we'll
//use the -C option
rootFolders.push(srcFile);
cOptionFolders.push(new FolderToAddWithCOption(srcFile, destPath));
continue;
}
}
Expand All @@ -422,24 +422,70 @@ package com.as3mxml.asconfigc
}
addFile(srcFile, destPath, result);
}
count = rootFolders.length;
count = cOptionRootFolders.length;
for(i = 0; i < count; i++)
{
folder = rootFolders[i];
var folder:String = cOptionRootFolders[i];
result.push("-C");
result.push(folder);
result.push(".");
}
count = selfFolders.length;
count = cOptionFolders.length;
for(i = 0; i < count; i++)
{
var folder:String = selfFolders[i];
result.push("-C");
result.push(path.dirname(folder));
result.push(path.basename(folder));
var cOptionFolder:FolderToAddWithCOption = FolderToAddWithCOption(cOptionFolders[i]);
var cOptionFolderSrcPath:String = cOptionFolder.srcPath;
var cOptionFolderDestPath:String = cOptionFolder.destPath;
if(!cOptionFolderDestPath)
{
result.push("-C");
result.push(path.dirname(cOptionFolderSrcPath));
result.push(path.basename(cOptionFolderSrcPath));
}
else
{
var baseFolderPath:String = cOptionFolderSrcPath;
var currentDestPath:String = cOptionFolderDestPath;
do
{
baseFolderPath = path.dirname(baseFolderPath);
if (baseFolderPath === ".") {
break;
}
currentDestPath = path.dirname(currentDestPath);
}
while(currentDestPath !== ".");

result.push("-C");
result.push(baseFolderPath);
result.push(cOptionFolderDestPath);
}
}
}

protected static function canUseCOptionForFolder(srcFolder:String, destPath:String):Boolean
{
var currentSrcPath:String = srcFolder;
var currentDestPath:String = destPath;
do
{
if(currentSrcPath === ".")
{
return false;
}
var currentSrcName:String = path.basename(currentSrcPath);
var currentDestName:String = path.basename(currentDestPath);
if(currentSrcName !== currentDestName)
{
return false;
}
currentSrcPath = path.dirname(currentSrcPath);
currentDestPath = path.dirname(currentDestPath);
}
while(currentDestPath !== ".");
return true;
}

protected static function addFile(srcFile:String, destPath:String, result:Array):void
{
if(fs.statSync(srcFile).isDirectory())
Expand Down Expand Up @@ -521,4 +567,15 @@ package com.as3mxml.asconfigc
}
}
}
}

class FolderToAddWithCOption {
public function FolderToAddWithCOption(srcPath:String, destPath:String)
{
this.srcPath = srcPath;
this.destPath = destPath;
}

public var srcPath:String;
public var destPath:String;
}

0 comments on commit 8810eba

Please sign in to comment.