Jump to content

Java utility to build debug version of Babylon.js


JCPalmer
 Share

Recommended Posts

I have experienced just one too many errors in my browser console pointing to line 1 of Babylon.js.  Made a little converter which took line 1 and made it multiline.  I understand a single line is a little smaller & possibly runs faster, but in dev neither is required when the thing is not currently running.

 

The utility makes a copy of the file with a -debug added.  Would have been better for sharing if I could made a single html file with inline Javascript, but that is not going to happen.  So here it is in Java source.  Hope it may help some

 

package debugbabylon;

import java.io.*;

/**
 * Purpose is to copy babylon.js, except line 1 is broken up by '{', '}', & ';' chars
 * New file is named babylon-debug.js, residing in the same directory as source
 * @author jeff Palmer
 */
public class DebugBabylon {

    /**
     *
     * @param args
     *    [0] - directory path (default working directory)
     *    [1] - name of input, e.g. babylon.1.12-beta.js, (default babylon.js)
     *
     */
    public static void main(final String[] args) throws IOException {
        final String path        = (args.length > 0) ? args[0] : ".";
        final String baseInFile  = (args.length > 1) ? args[1] : "babylon.js";
        final String baseOutFile = baseInFile.replace(".js", "-debug.js");
        
        try(BufferedReader reader = new BufferedReader(new FileReader(path + "/" + baseInFile)) ) {
            final String origLine1 = reader.readLine();
            final int nInput = origLine1.length();
            
            final File f = new File(path + "/" + baseOutFile);
            f.createNewFile();
            final BufferedWriter writer = new BufferedWriter(new FileWriter(f));
            
            int indent = 0;
            char ch;
            boolean inLiteral = false;
            for (int i = 0; i < nInput; i++){
                ch = origLine1.charAt(i);
                
                // separate if structure for literals, since strings should not span lines
                if (inLiteral || ch == '"'){
                    writer.append(ch);
                    inLiteral = (inLiteral && ch == '"') ? false : true;
                }
                else if (ch == '{'){
                    writer.append(ch);
                    writer.newLine();
                    appendIndent(writer, ++indent);                   
                }
                else if (ch == '}'){
                    writer.newLine();
                    appendIndent(writer, --indent);                   
                    writer.append(ch);
                    
                    // skip next part if immediately followed by a ';'
                    if (origLine1.charAt(i + 1) != ';'){
                        writer.newLine();
                        appendIndent(writer, indent);
                    }
                }
                else if (ch == ';'){
                    writer.append(ch);
                    writer.newLine();
                    appendIndent(writer, indent);                                       
                }
                else{
                    writer.append(ch);
                }
            }
            
            // put newline at end since readline is not inclusive of the terminator
            writer.newLine();
            
            String line;
            // loop thru rest of input unchanged
            while((line = reader.readLine()) != null){
                writer.write(line);
                writer.newLine();
            }
            writer.close();
        }
    }
    
    private static void appendIndent(final BufferedWriter writer, final int indent) throws IOException{
        for (int i = 0; i < indent; i++){
            writer.append('\t');
        }
    }
}

Link to comment
Share on other sites

If I have understood you well, you can achieve the same result with the minified version in Chrome Javascript console by selecting your file in the Sources tab and by clicking on the following icon '{}'. Thus you can work with the minified version and you can still debug it easily

Link to comment
Share on other sites

gwenael,

 

Thanks, I do not use Chrome (something about having my super-best friend tracking even my book marks gives me the creeps).  This is still minified in the sense that everything is consolidated into 1 file.  Just 40k of strategically placed newlines & tabs.

 

If I deploy anything will be sure investigate making a custom minified version.  If doing a browser based deployment will certainly need to test Chrome though.  Really hoping to use CocoonJS for iOS, Android, & Amazon.  MS for Windows 8.

 

Jeff

Link to comment
Share on other sites

Thanks,

Actually I just saw the same '{}' button in Firefox on Ubuntu 14.04, which is my primary dev system, with OSX my backup.  Recently blew away my Win 7 for Ubuntu, cause it was just hanging in IE & and alot of places.  Got like 6 drive bays.  Will get a drive & rebuild at my convenience.  Never want MS to be the first OS on the system anyway.  One of the perks of using Netbeans IDE.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...