How to remove comments?
I downloaded Ext 3.1, and ran jsbuilder2 on the source using the jsb2 file included in the 3.1 download package:
Code:
java.exe -jar jsbuilder2.jar --projectFile "c:\development\js builder\staging\ext.jsb2" --homeDir "c:\development\js builder\compiled"
I'd also like to know this if anyone has any ideas?
I'm not concerned if ext-all-debug.js has to be passed through another tool, I'd just like to know what is done by Ext to build the distributable releases, so that I can build patched versions that differ only by the patch and not the presence of comments etc.
Cheers
Any luck? I'm trying to figure out the same thing here.
I filed a bug report regarding this issue. We should be able to reproduce the ext-all*.js files exactly as ExtJS does.
Allright.. this builder thingie stinks and the Ext team is in no hurry to fix things.
Does anyone know of an alternative tool that works?
- Join Date
- Mar 2007
- Location
- The Netherlands
- 24,246
- Vote Rating
- 118
JSBuilder3 is included in the latest Sencha Touch betas and can also be used to build (a pre-alpha) Ext 4 from SVN, but to build Ext 3 you need to convert ext.jsb2 to .jsb3 format.
ps. I wrote a small java app to remove comments and additional whitespace from a .js file:
Code:
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.regex.Pattern; public class CleanJavascript { private static String read(final String filename) throws IOException { File file = new File(filename); long length = file.length(); if (length > Integer.MAX_VALUE) { throw new IOException("File " + file.getName() + " is too large"); } byte[] bytes = new byte[(int) length]; InputStream is = new FileInputStream(file); try { int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } if (offset < bytes.length) { throw new IOException("Could not completely read file " + file.getName()); } } finally { is.close(); } return new String(bytes, "UTF-8"); } private static String clean(final String script) { return Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL).matcher(script).replaceAll("") .replaceAll("//.*", "") .replaceAll("\r\n", "\n") .replaceAll("\\s+\n", "\n") .replaceAll("\t", " ") .replaceAll("\n\n", "\n") .replaceAll("^\n", ""); } private static void write(final String filename, final String data) throws UnsupportedEncodingException, IOException { File file = new File(filename); OutputStream os = new FileOutputStream(file); try { os.write(data.getBytes("UTF-8")); } finally { os.close(); } } public static void main(String[] args) throws IOException { write(args[1], clean(read(args[0]))); } }
Hi!
I'm too had this problem, and I've decided to fix it by myself. Couple of hours and...
The main problem is in function writeHeadersToTargets(), which is must write these comments (only?) for the target files.
But, it is not only, it do it for all *.js and *.css files in the deployDir, RECURSIVELY.
What for? I don't know.
But, I think, it should process ONLY target files, but not every one in the deployDir.
Here the quick fix for it:
Code:
... public static void writeHeadersToTargets() { /* mivion : Why? Collection<File> outFiles = FileHelper.listFiles(deployDir, new FilenameFilter() { private Pattern pattern = Pattern.compile(".*[\\.js|\\.css]"); public boolean accept(File dir, String name) { return pattern.matcher(name).matches() && !(new File(dir.getAbsolutePath() + File.separatorChar + name).isDirectory()); } }, true); */ for (File f : outputFiles) { // mivion : was outFiles if (verbose) { // mivion System.out.println("Writing license text to: " + f.getAbsolutePath()); } String headerContents = FileHelper.readFileToString(headerFile); String codeContents = FileHelper.readFileToString(f); FileHelper.writeStringToFile(headerContents, f, false); FileHelper.writeStringToFile(codeContents, f, true); } } ...
the deployDir MUST NOT be the SAME as the homeDir.
And there are no more annoying comments in your beloved code.
mivion
There is also a build i did of JSBuilder2 what takes care of these issues. See the JSBuilder2 bugs thread.