Note: The actual error from Java/Closure Compiler came from the missing t in –js-outputfile!
I have this PowerShell script:
cls
$jsFiles = @();
Get-ChildItem | Where {$_.PsIsContainer} | Foreach {
$dir = $_.FullName;
$jsFile = $dir + "\" + $_.Name + ".js";
if (Test-Path ($jsFile)) {
$jsFiles += $jsFile;
}
}
$wd = [System.IO.Directory]::GetCurrentDirectory();
# Build Closure Compiler command line call
$cmd = @("-jar $wd\..\ClosureCompiler\compiler.jar");
Foreach ($file in $jsFiles) {
# Both insert a newline!
$cmd += "--js $file";
#$cmd = "$cmd --js $file";
}
$cmd = "$cmd --js_ouput_file $wd\all.js";
Invoke-Expression "java.exe $cmd"
The problem is that newlines are inserted on each += or $cmd = "$cmd str" call!
Echoargs gives me this output:
Arg 0 is <-jar>
Arg 1 is <S:\ome\Path\compiler.jar>
Arg 2 is <--js>
Arg 3 is <S:\ome\Path\script1.js>
Arg 4 is <--js>
Arg 5 is <S:\ome\Path\script2.js>
...
Arg 98 is <--js_ouput_file>
Arg 99 is <S:\ome\Path\all.js>
(Possibly) therefore, I get some errors from java.exe:
java.exe : "--js_ouput_file" is not a valid option
At line:1 char:1
+ java.exe -jar ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ("--js_ouput_file" is not a valid option:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Try to rewrite to much simple version: