bin/configure.js
function handleConfigEntry ( defaults, values, parent_name, cb ) {
    var entries = Object.keys( defaults ),
        c = 0;

    var cont = function () {    // entry handling function
        if( c < entries.length ) {
            var key = entries[ c ],
                entry = defaults[ key ];
            if ( typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean" || entry == undefined ) {
                ask( ( parent_name ? parent_name + "." + key.blue : key.blue ) + " (" + entry.toString().yellow + "): ", function ( newValue ) {
                    if ( newValue === "" ) {
                        newValue = defaults[ key ];
                    }
                    values[ key ] = newValue;
                    c++;
                    cont();    // continue
                } );
            } else if ( entry instanceof Array ) {    // support for arrays
                var array = values[ key ] = [],
                    _proto = defaults[ key ][ 0 ];
                if ( _proto ) {
                    var array_handler = function ( num ) {
                        num = parseInt( num );
                        if( num ) {    // this makes sure num > 0
                            var cc = -1;
                            var array_item_handler = function () {
                                cc++;
                                if( cc < num ) {
                                    array.push( {} );
                                    var i = array[ array.length - 1 ];
                                    handleConfigEntry( _proto, i,  ( parent_name ? parent_name + "." + key : key ) + "." + cc, array_item_handler );
                                } else {
                                    c++;
                                    cont();    // done with the array
                                }
                            };
                            array_item_handler();    // begin with the array
                        } else {
                            ask( "Number of entries for " + ( parent_name ? parent_name + "." + key.blue : key.blue ) + " ? ", array_handler );
                        }
                    };
                    ask( "Number of entries for " + ( parent_name ? parent_name + "." + key.blue : key.blue ) + " ? ", array_handler );
                } else {
                    c++;
                    cont();
                }
            } else {
                values[ key ] = {};

                // recurse down the object
                handleConfigEntry( defaults[ key ], values[ key ], ( parent_name ? parent_name + "." + key : key ), function () {
                    c++;
                    cont();
                } );
            }
        } else {
            if ( cb ) {
                cb();   // done :)
            }
        }
    };

    // begin
    cont();
}
function handleConfigEntry ( defaults, values, parent_name, cb ) {
    var entries = Object.keys( defaults ),
        c = 0;

    var cont = function () {    // entry handling function
        if( c < entries.length ) {
            var key = entries[ c ],
                entry = defaults[ key ];
            if ( typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean" || entry == undefined ) {
                ask( ( parent_name ? parent_name + "." + key.blue : key.blue ) + " (" + entry.toString().yellow + "): ", function ( newValue ) {
                    if ( newValue === "" ) {
                        newValue = defaults[ key ];
                    }
                    values[ key ] = newValue;
                    c++;
                    cont();    // continue
                } );
            } else if ( entry instanceof Array ) {    // support for arrays
                var array = values[ key ] = [],
                    _proto = defaults[ key ][ 0 ];
                if ( _proto ) {
                    var array_handler = function ( num ) {
                        num = parseInt( num );
                        if( num ) {    // this makes sure num > 0
                            var cc = -1;
                            var array_item_handler = function () {
                                cc++;
                                if( cc < num ) {
                                    array.push( {} );
                                    var i = array[ array.length - 1 ];
                                    handleConfigEntry( _proto, i,  ( parent_name ? parent_name + "." + key : key ) + "." + cc, array_item_handler );
                                } else {
                                    c++;
                                    cont();    // done with the array
                                }
                            };
                            array_item_handler();    // begin with the array
                        } else {
                            ask( "Number of entries for " + ( parent_name ? parent_name + "." + key.blue : key.blue ) + " ? ", array_handler );
                        }
                    };
                    ask( "Number of entries for " + ( parent_name ? parent_name + "." + key.blue : key.blue ) + " ? ", array_handler );
                } else {
                    c++;
                    cont();
                }
            } else {
                values[ key ] = {};

                // recurse down the object
                handleConfigEntry( defaults[ key ], values[ key ], ( parent_name ? parent_name + "." + key : key ), function () {
                    c++;
                    cont();
                } );
            }
        } else {
            if ( cb ) {
                cb();   // done :)
            }
        }
    };

    // begin
    cont();
}
function handleConfigEntry ( defaults , values , parent_name , cb ) { var entries = Object . keys ( defaults ) , c = 0 ; var cont = function ( ) { // entry handling function if ( c < entries . length ) { var key = entries [ c ] , entry = defaults [ key ] ; if ( typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean" || entry == undefined ) { ask ( ( parent_name ? parent_name + "." + key . blue : key . blue ) + " (" + entry . toString ( ) . yellow + "): " , function ( newValue ) { if ( newValue === "" ) { newValue = defaults [ key ] ; } values [ key ] = newValue ; c ++ ; cont ( ) ; // continue } ) ; } else if ( entry instanceof Array ) { // support for arrays var array = values [ key ] = [ ] , _proto = defaults [ key ] [ 0 ] ; if ( _proto ) { var array_handler = function ( num ) { num = parseInt ( num ) ; if ( num ) { // this makes sure num > 0 var cc = - 1 ; var array_item_handler = function ( ) { cc ++ ; if ( cc < num ) { array . push ( { } ) ; var i = array [ array . length - 1 ] ; handleConfigEntry ( _proto , i , ( parent_name ? parent_name + "." + key : key ) + "." + cc , array_item_handler ) ; } else { c ++ ; cont ( ) ; // done with the array } } ; array_item_handler ( ) ; // begin with the array } else { ask ( "Number of entries for " + ( parent_name ? parent_name + "." + key . blue : key . blue ) + " ? " , array_handler ) ; } } ; ask ( "Number of entries for " + ( parent_name ? parent_name + "." + key . blue : key . blue ) + " ? " , array_handler ) ; } else { c ++ ; cont ( ) ; } } else { values [ key ] = { } ; // recurse down the object handleConfigEntry ( defaults [ key ] , values [ key ] , ( parent_name ? parent_name + "." + key : key ) , function ( ) { c ++ ; cont ( ) ; } ) ; } } else { if ( cb ) { cb ( ) ; // done :) } } } ; // begin cont ( ) ; }
Recursive handling of config object. It asks the user for values of the each attribute of the config.defaults object.
If the user skips an attribute, the default value is taken.
@param defaults Configuration default values.
@param values Configuration user given values.
@param parent_name Current config object parent name.
@param cb Callback function. No arguments given.
Recursive handling of config object . It asks the user for values of the each attribute of the config . defaults object . If the user skips an attribute the default value is taken .