prepublish.js
function main() {

    var database = fs.createWriteStream('./lib/database-min.js', { flags: 'w', encoding: 'utf8' });
    var testFile;

    fs.mkdir('./data', 493, function (error) {  // 493 == 0755 (no octal in strict mode.)
        // ignore errors.
    });
    
    database.write("// Do not edit this file, your changes will be lost.\n");
    database.write("module.exports = { \n");
    getJSON('http://alscan.info/agent_groups/groups.json', function (groups) {
        var s = JSON.stringify(groups);
        database.write("groups:" + s + ",\n");
        testFile = fs.createWriteStream('./data/groups.json', { flags: 'w', encoding: 'utf8' });
        testFile.write(s+"\n");
        testFile.end();
        getJSON('http://alscan.info/agent_sources/sources.json', function (sources) {
            var s = JSON.stringify(sources);
            database.write("sources:" + s + ",\n");
            testFile = fs.createWriteStream('./data/sources.json', { flags: 'w', encoding: 'utf8' });
            testFile.write(s+"\n");
            testFile.end();
            getJSON('http://alscan.info/patterns/patterns.json', function (patterns) {
                database.write("patterns:[\n");
                patterns.forEach(function (pattern) {
                    database.write("{p: new RegExp('" + pattern.pattern + "'), x:" + 
                            agentdb.getX(pattern.groupId, pattern.sourceId) + "},");
                });
                database.write("],\n");
                testFile = fs.createWriteStream('./data/patterns.json', { flags: 'w', encoding: 'utf8' });
                testFile.write(JSON.stringify(patterns)+"\n");
                testFile.end();
                getJSON('http://alscan.info/agents/agents.json', function (agents) {
                    var hash = new HashTable(HASH_TABLE_SIZE, HASH_TABLE_SEED, HASH_TABLE_MULTIPLIER);
                    agents.forEach(function (agent) {
                        if (agent.status < 2) {
                            var obj = { a: agent.agent, x: agentdb.getX(agent.groupId, agent.sourceId) };
                            hash.add('a', obj);
                        }
                    });
                    database.write("table:" + JSON.stringify(hash.table) + ",\n");
                    database.write("HASH_TABLE_SIZE:" + HASH_TABLE_SIZE + ",\n");
                    database.write("HASH_TABLE_SEED:" + HASH_TABLE_SEED + ",\n");
                    database.write("HASH_TABLE_MULTIPLIER:" + HASH_TABLE_MULTIPLIER + ",\n");
                    database.write("hash: undefined\n}\n");
                    testFile = fs.createWriteStream('./data/agents.json', { flags: 'w', encoding: 'utf8' });
                    testFile.write(JSON.stringify(agents)+"\n");
                    testFile.end();
                    if (debug) {
                        var history = hash.getHistory();
                        console.log("Hash table history");
                        for (var n=0; n < history.length; n++) {
                            console.log("  Depth=" + n + ", count=" + history[n] + ", percent=" + (history[n] / HASH_TABLE_SIZE));
                        }
                    }
                });
            });
        });
    });
}
function main() {

    var database = fs.createWriteStream('./lib/database-min.js', { flags: 'w', encoding: 'utf8' });
    var testFile;

    fs.mkdir('./data', 493, function (error) {  // 493 == 0755 (no octal in strict mode.)
        // ignore errors.
    });
    
    database.write("// Do not edit this file, your changes will be lost.\n");
    database.write("module.exports = { \n");
    getJSON('http://alscan.info/agent_groups/groups.json', function (groups) {
        var s = JSON.stringify(groups);
        database.write("groups:" + s + ",\n");
        testFile = fs.createWriteStream('./data/groups.json', { flags: 'w', encoding: 'utf8' });
        testFile.write(s+"\n");
        testFile.end();
        getJSON('http://alscan.info/agent_sources/sources.json', function (sources) {
            var s = JSON.stringify(sources);
            database.write("sources:" + s + ",\n");
            testFile = fs.createWriteStream('./data/sources.json', { flags: 'w', encoding: 'utf8' });
            testFile.write(s+"\n");
            testFile.end();
            getJSON('http://alscan.info/patterns/patterns.json', function (patterns) {
                database.write("patterns:[\n");
                patterns.forEach(function (pattern) {
                    database.write("{p: new RegExp('" + pattern.pattern + "'), x:" + 
                            agentdb.getX(pattern.groupId, pattern.sourceId) + "},");
                });
                database.write("],\n");
                testFile = fs.createWriteStream('./data/patterns.json', { flags: 'w', encoding: 'utf8' });
                testFile.write(JSON.stringify(patterns)+"\n");
                testFile.end();
                getJSON('http://alscan.info/agents/agents.json', function (agents) {
                    var hash = new HashTable(HASH_TABLE_SIZE, HASH_TABLE_SEED, HASH_TABLE_MULTIPLIER);
                    agents.forEach(function (agent) {
                        if (agent.status < 2) {
                            var obj = { a: agent.agent, x: agentdb.getX(agent.groupId, agent.sourceId) };
                            hash.add('a', obj);
                        }
                    });
                    database.write("table:" + JSON.stringify(hash.table) + ",\n");
                    database.write("HASH_TABLE_SIZE:" + HASH_TABLE_SIZE + ",\n");
                    database.write("HASH_TABLE_SEED:" + HASH_TABLE_SEED + ",\n");
                    database.write("HASH_TABLE_MULTIPLIER:" + HASH_TABLE_MULTIPLIER + ",\n");
                    database.write("hash: undefined\n}\n");
                    testFile = fs.createWriteStream('./data/agents.json', { flags: 'w', encoding: 'utf8' });
                    testFile.write(JSON.stringify(agents)+"\n");
                    testFile.end();
                    if (debug) {
                        var history = hash.getHistory();
                        console.log("Hash table history");
                        for (var n=0; n < history.length; n++) {
                            console.log("  Depth=" + n + ", count=" + history[n] + ", percent=" + (history[n] / HASH_TABLE_SIZE));
                        }
                    }
                });
            });
        });
    });
}
function main ( ) { var database = fs . createWriteStream ( './lib/database-min.js' , { flags : 'w' , encoding : 'utf8' } ) ; var testFile ; fs . mkdir ( './data' , 493 , function ( error ) { // 493 == 0755 (no octal in strict mode.) // ignore errors. } ) ; database . write ( "// Do not edit this file, your changes will be lost.\n" ) ; database . write ( "module.exports = { \n" ) ; getJSON ( 'http://alscan.info/agent_groups/groups.json' , function ( groups ) { var s = JSON . stringify ( groups ) ; database . write ( "groups:" + s + ",\n" ) ; testFile = fs . createWriteStream ( './data/groups.json' , { flags : 'w' , encoding : 'utf8' } ) ; testFile . write ( s + "\n" ) ; testFile . end ( ) ; getJSON ( 'http://alscan.info/agent_sources/sources.json' , function ( sources ) { var s = JSON . stringify ( sources ) ; database . write ( "sources:" + s + ",\n" ) ; testFile = fs . createWriteStream ( './data/sources.json' , { flags : 'w' , encoding : 'utf8' } ) ; testFile . write ( s + "\n" ) ; testFile . end ( ) ; getJSON ( 'http://alscan.info/patterns/patterns.json' , function ( patterns ) { database . write ( "patterns:[\n" ) ; patterns . forEach ( function ( pattern ) { database . write ( "{p: new RegExp('" + pattern . pattern + "'), x:" + agentdb . getX ( pattern . groupId , pattern . sourceId ) + "}," ) ; } ) ; database . write ( "],\n" ) ; testFile = fs . createWriteStream ( './data/patterns.json' , { flags : 'w' , encoding : 'utf8' } ) ; testFile . write ( JSON . stringify ( patterns ) + "\n" ) ; testFile . end ( ) ; getJSON ( 'http://alscan.info/agents/agents.json' , function ( agents ) { var hash = new HashTable ( HASH_TABLE_SIZE , HASH_TABLE_SEED , HASH_TABLE_MULTIPLIER ) ; agents . forEach ( function ( agent ) { if ( agent . status < 2 ) { var obj = { a : agent . agent , x : agentdb . getX ( agent . groupId , agent . sourceId ) } ; hash . add ( 'a' , obj ) ; } } ) ; database . write ( "table:" + JSON . stringify ( hash . table ) + ",\n" ) ; database . write ( "HASH_TABLE_SIZE:" + HASH_TABLE_SIZE + ",\n" ) ; database . write ( "HASH_TABLE_SEED:" + HASH_TABLE_SEED + ",\n" ) ; database . write ( "HASH_TABLE_MULTIPLIER:" + HASH_TABLE_MULTIPLIER + ",\n" ) ; database . write ( "hash: undefined\n}\n" ) ; testFile = fs . createWriteStream ( './data/agents.json' , { flags : 'w' , encoding : 'utf8' } ) ; testFile . write ( JSON . stringify ( agents ) + "\n" ) ; testFile . end ( ) ; if ( debug ) { var history = hash . getHistory ( ) ; console . log ( "Hash table history" ) ; for ( var n = 0 ; n < history . length ; n ++ ) { console . log ( "  Depth=" + n + ", count=" + history [ n ] + ", percent=" + ( history [ n ] / HASH_TABLE_SIZE ) ) ; } } } ) ; } ) ; } ) ; } ) ; }
Main entry point for prepublish script.
Main entry point for prepublish script .