FINALLY! Here's what I had to do:
1) I created a Windows path variable named java_path. It turned out that there's
enough other things in my real path variable that using that to find the Java
path didn't work for cmd.exe. This is the full path, including java.exe, to my
latest Java.
2) I put the YUI compressor in a directory at the root of the partition and set
the YUI_path to it. Otherwise things would fail on the quotes around "PSPad
Editor". So
var YUI_path = 'D:/bin/yuicompressor-2.4.2.jar';
3) Since I'm only interested in the minimizer (for now anyway) I created a new
function that directly runs the YUI compressor without making a temporary file.
I also modified the call to the compressor like this:
sh.run('cmd /c "%java_path%" -jar ' + YUI_path + ' -o ' + fnYui + '
--nomunge ' + fn, 0, true)
4) in order to use a network path, I had to make a modification
(http://support.microsoft.com/kb/156276) to the Windows Registry to
allow cmd.exe to use UNC paths.
I also modified your code a bit to change the minimized filename to match the
way jQuery does things (funny that jScript doesn't support negative lengths for
substr):
var fnYui = fn.slice(0, -3) + '-min.js';
The pack function currently doesn't work, but I'm not interested in that. People
testing both ways have shown that packing is actually slower (for the tested
browsers) than minimizing since eval() must be run to unpack. With the same
modifications, the css minimizer works. I haven't dealt with the comparison part
yet.
What I'd like to do eventually is to modify things so that selecting the js
filename while in a html (or other) file would compress that file and change the
filename in the editor. Just to make things a little more foolproof. For now,
I'm just echoing the new filename, since relative paths (like a cms or MVC app
might use) might be a real PITA to parse.
--
<http://forum.pspad.com/read.php?2,51923,52049>
PSPad freeware editor http://www.pspad.com