lib/index.js
function include(list) {
    var cmd, clazz, i, file, j, name, newname;
    for(i = 0;i < list.length;i++) {
      file = list[i];
      try {
        clazz = require(file);
        // assume it is already instantiated
        if(typeof clazz === 'object') {
          cmd = clazz;
        }else{
          cmd = new clazz(clazz.definition);
        }

        // rename and delete commands
        if(cmd && cmd.definition && cmd.definition.name) {
          for(j = 0;j < rename.length;j++) {
            name = rename[j][0];
            newname = rename[j][1];
            if(name
              && name.toLowerCase() === cmd.definition.name.toLowerCase()) {
              newname = (newname || '').toLowerCase();
              // actually renaming
              if(newname) {
                log.warning(
                  'rename command %s -> %s', cmd.definition.name, newname);
                cmd.definition.name = newname;
              // deleting the command, mark as deleted with false
              }else{
                log.warning(
                  'deleted command %s (%s)', cmd.definition.name, file);
                commands[cmd.definition.name] = false;
                // clear the module cache
                delete require.cache[file];
              }
              break;
            }
          }
        }

        // deleted the command
        if(!require.cache[file]) continue;

        // sanity checks
        if(!(cmd instanceof CommandExec)) {
          throw new Error(
            util.format(
              'module does not export a command exec instance (%s)', file));
        }else if(
          !cmd.definition
          || !cmd.definition.constructor
          || cmd.definition.constructor.name !== Command.name) {
          throw new Error(
            util.format(
              'command does not have a valid definition (%s)', file));
        }else if(!cmd.definition.name) {
          throw new Error(
            util.format(
              'command definition does not have a name (%s)', file));
        }

        if(opts.override !== true && commands[cmd.definition.name]) {
          throw new Error(util.format(
              'duplicate command %s (%s)', cmd.definition.name, file));
        }

        log.debug('loaded %s (%s)', cmd.definition.name, file);

        // map of command names to command exec handlers
        commands[cmd.definition.name] = cmd;
      }catch(e) {
        return complete(e);
      }
    }
    complete();
  }
function include(list) {
    var cmd, clazz, i, file, j, name, newname;
    for(i = 0;i < list.length;i++) {
      file = list[i];
      try {
        clazz = require(file);
        // assume it is already instantiated
        if(typeof clazz === 'object') {
          cmd = clazz;
        }else{
          cmd = new clazz(clazz.definition);
        }

        // rename and delete commands
        if(cmd && cmd.definition && cmd.definition.name) {
          for(j = 0;j < rename.length;j++) {
            name = rename[j][0];
            newname = rename[j][1];
            if(name
              && name.toLowerCase() === cmd.definition.name.toLowerCase()) {
              newname = (newname || '').toLowerCase();
              // actually renaming
              if(newname) {
                log.warning(
                  'rename command %s -> %s', cmd.definition.name, newname);
                cmd.definition.name = newname;
              // deleting the command, mark as deleted with false
              }else{
                log.warning(
                  'deleted command %s (%s)', cmd.definition.name, file);
                commands[cmd.definition.name] = false;
                // clear the module cache
                delete require.cache[file];
              }
              break;
            }
          }
        }

        // deleted the command
        if(!require.cache[file]) continue;

        // sanity checks
        if(!(cmd instanceof CommandExec)) {
          throw new Error(
            util.format(
              'module does not export a command exec instance (%s)', file));
        }else if(
          !cmd.definition
          || !cmd.definition.constructor
          || cmd.definition.constructor.name !== Command.name) {
          throw new Error(
            util.format(
              'command does not have a valid definition (%s)', file));
        }else if(!cmd.definition.name) {
          throw new Error(
            util.format(
              'command definition does not have a name (%s)', file));
        }

        if(opts.override !== true && commands[cmd.definition.name]) {
          throw new Error(util.format(
              'duplicate command %s (%s)', cmd.definition.name, file));
        }

        log.debug('loaded %s (%s)', cmd.definition.name, file);

        // map of command names to command exec handlers
        commands[cmd.definition.name] = cmd;
      }catch(e) {
        return complete(e);
      }
    }
    complete();
  }
function include ( list ) { var cmd , clazz , i , file , j , name , newname ; for ( i = 0 ; i < list . length ; i ++ ) { file = list [ i ] ; try { clazz = require ( file ) ; // assume it is already instantiated if ( typeof clazz === 'object' ) { cmd = clazz ; } else { cmd = new clazz ( clazz . definition ) ; } // rename and delete commands if ( cmd && cmd . definition && cmd . definition . name ) { for ( j = 0 ; j < rename . length ; j ++ ) { name = rename [ j ] [ 0 ] ; newname = rename [ j ] [ 1 ] ; if ( name && name . toLowerCase ( ) === cmd . definition . name . toLowerCase ( ) ) { newname = ( newname || '' ) . toLowerCase ( ) ; // actually renaming if ( newname ) { log . warning ( 'rename command %s -> %s' , cmd . definition . name , newname ) ; cmd . definition . name = newname ; // deleting the command, mark as deleted with false } else { log . warning ( 'deleted command %s (%s)' , cmd . definition . name , file ) ; commands [ cmd . definition . name ] = false ; // clear the module cache delete require . cache [ file ] ; } break ; } } } // deleted the command if ( ! require . cache [ file ] ) continue ; // sanity checks if ( ! ( cmd instanceof CommandExec ) ) { throw new Error ( util . format ( 'module does not export a command exec instance (%s)' , file ) ) ; } else if ( ! cmd . definition || ! cmd . definition . constructor || cmd . definition . constructor . name !== Command . name ) { throw new Error ( util . format ( 'command does not have a valid definition (%s)' , file ) ) ; } else if ( ! cmd . definition . name ) { throw new Error ( util . format ( 'command definition does not have a name (%s)' , file ) ) ; } if ( opts . override !== true && commands [ cmd . definition . name ] ) { throw new Error ( util . format ( 'duplicate command %s (%s)' , cmd . definition . name , file ) ) ; } log . debug ( 'loaded %s (%s)' , cmd . definition . name , file ) ; // map of command names to command exec handlers commands [ cmd . definition . name ] = cmd ; } catch ( e ) { return complete ( e ) ; } } complete ( ) ; }
Requires the array of files.
Requires the array of files .