1. #1
    Sencha Premium Member
    Join Date
    Mar 2008
    Location
    Philadelphia, PA
    Posts
    131
    Vote Rating
    0
    mprice is on a distinguished road

      0  

    Default How to remove comments?

    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 then compared the resulting ext-all-debug.js to the ext-all-debug.js in the 3.1 download package. I expected that they would be identical, but they are not. There are commetns speckled throughout the .js created using jsbuilder. I thought Ext uses jsbuilder themselves to create the "-all" files. Is there a way to force comments to be removed?

  2. #2
    Ext User krider2010's Avatar
    Join Date
    Aug 2007
    Location
    Berkshire, UK
    Posts
    18
    Vote Rating
    0
    krider2010 is on a distinguished road

      0  

    Default


    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

  3. #3
    Sencha User
    Join Date
    Jul 2007
    Posts
    77
    Vote Rating
    0
    csky is on a distinguished road

      0  

    Default


    Any luck? I'm trying to figure out the same thing here.

  4. #4
    Ext User
    Join Date
    May 2010
    Posts
    1
    Vote Rating
    0
    kotletas is on a distinguished road

      0  

    Default


    Same prob, waiting for issue ...

    -----------------------------
    use seroquel
    soft

  5. #5
    Sencha User
    Join Date
    Jul 2007
    Posts
    77
    Vote Rating
    0
    csky is on a distinguished road

      0  

    Default


    I filed a bug report regarding this issue. We should be able to reproduce the ext-all*.js files exactly as ExtJS does.

  6. #6
    Sencha User realjax's Avatar
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    412
    Vote Rating
    6
    realjax is on a distinguished road

      0  

    Default


    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?

  7. #7
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    91
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    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])));
    	}
    }

  8. #8
    Ext User
    Join Date
    Nov 2007
    Posts
    1
    Vote Rating
    0
    mivion is on a distinguished road

      0  

    Default


    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);
            }
        }
    ...
    And of course, now we know a simple solution:
    the deployDir MUST NOT be the SAME as the homeDir.

    And there are no more annoying comments in your beloved code.

    mivion

  9. #9
    Sencha User
    Join Date
    Feb 2011
    Posts
    10
    Vote Rating
    0
    Beeaar is on a distinguished road

      0  

    Default


    There is also a build i did of JSBuilder2 what takes care of these issues. See the JSBuilder2 bugs thread.