index.js
function renderFile(path, rootPath) {
  var isPug = /\.(?:pug|jade)$/;
  var isIgnored = /([\/\\]_)|(^_)/;

  var stat = fs.lstatSync(path);
  // Found pug file
  if (stat.isFile() && isPug.test(path) && !isIgnored.test(path)) {
    // Try to watch the file if needed. watchFile takes care of duplicates.
    if (program.watch) watchFile(path, null, rootPath);
    if (program.nameAfterFile) {
      options.name = getNameFromFileName(path);
    }
    var fn = options.client
           ? pug.compileFileClient(path, options)
           : pug.compileFile(path, options);
    if (program.watch && fn.dependencies) {
      // watch dependencies, and recompile the base
      fn.dependencies.forEach(function (dep) {
        watchFile(dep, path, rootPath);
      });
    }

    // --extension
    var extname;
    if (program.extension)   extname = '.' + program.extension;
    else if (options.client) extname = '.js';
    else if (program.extension === '') extname = '';
    else                     extname = '.html';

    // path: foo.pug -> foo.<ext>
    path = path.replace(isPug, extname);
    if (program.out) {
      // prepend output directory
      if (rootPath) {
        // replace the rootPath of the resolved path with output directory
        path = relative(rootPath, path);
      } else {
        // if no rootPath handling is needed
        path = basename(path);
      }
      path = resolve(program.out, path);
    }
    var dir = resolve(dirname(path));
    mkdirp.sync(dir);
    var output = options.client ? fn : fn(options);
    fs.writeFileSync(path, output);
    consoleLog('  ' + chalk.gray('rendered') + ' ' + chalk.cyan('%s'), normalize(path));
  // Found directory
  } else if (stat.isDirectory()) {
    var files = fs.readdirSync(path);
    files.map(function(filename) {
      return path + '/' + filename;
    }).forEach(function (file) {
      render(file, rootPath || path);
    });
  }
}
function renderFile(path, rootPath) {
  var isPug = /\.(?:pug|jade)$/;
  var isIgnored = /([\/\\]_)|(^_)/;

  var stat = fs.lstatSync(path);
  // Found pug file
  if (stat.isFile() && isPug.test(path) && !isIgnored.test(path)) {
    // Try to watch the file if needed. watchFile takes care of duplicates.
    if (program.watch) watchFile(path, null, rootPath);
    if (program.nameAfterFile) {
      options.name = getNameFromFileName(path);
    }
    var fn = options.client
           ? pug.compileFileClient(path, options)
           : pug.compileFile(path, options);
    if (program.watch && fn.dependencies) {
      // watch dependencies, and recompile the base
      fn.dependencies.forEach(function (dep) {
        watchFile(dep, path, rootPath);
      });
    }

    // --extension
    var extname;
    if (program.extension)   extname = '.' + program.extension;
    else if (options.client) extname = '.js';
    else if (program.extension === '') extname = '';
    else                     extname = '.html';

    // path: foo.pug -> foo.<ext>
    path = path.replace(isPug, extname);
    if (program.out) {
      // prepend output directory
      if (rootPath) {
        // replace the rootPath of the resolved path with output directory
        path = relative(rootPath, path);
      } else {
        // if no rootPath handling is needed
        path = basename(path);
      }
      path = resolve(program.out, path);
    }
    var dir = resolve(dirname(path));
    mkdirp.sync(dir);
    var output = options.client ? fn : fn(options);
    fs.writeFileSync(path, output);
    consoleLog('  ' + chalk.gray('rendered') + ' ' + chalk.cyan('%s'), normalize(path));
  // Found directory
  } else if (stat.isDirectory()) {
    var files = fs.readdirSync(path);
    files.map(function(filename) {
      return path + '/' + filename;
    }).forEach(function (file) {
      render(file, rootPath || path);
    });
  }
}
function renderFile ( path , rootPath ) { var isPug = / \.(?:pug|jade)$ / ; var isIgnored = / ([\/\\]_)|(^_) / ; var stat = fs . lstatSync ( path ) ; // Found pug file if ( stat . isFile ( ) && isPug . test ( path ) && ! isIgnored . test ( path ) ) { // Try to watch the file if needed. watchFile takes care of duplicates. if ( program . watch ) watchFile ( path , null , rootPath ) ; if ( program . nameAfterFile ) { options . name = getNameFromFileName ( path ) ; } var fn = options . client ? pug . compileFileClient ( path , options ) : pug . compileFile ( path , options ) ; if ( program . watch && fn . dependencies ) { // watch dependencies, and recompile the base fn . dependencies . forEach ( function ( dep ) { watchFile ( dep , path , rootPath ) ; } ) ; } // --extension var extname ; if ( program . extension ) extname = '.' + program . extension ; else if ( options . client ) extname = '.js' ; else if ( program . extension === '' ) extname = '' ; else extname = '.html' ; // path: foo.pug -> foo.<ext> path = path . replace ( isPug , extname ) ; if ( program . out ) { // prepend output directory if ( rootPath ) { // replace the rootPath of the resolved path with output directory path = relative ( rootPath , path ) ; } else { // if no rootPath handling is needed path = basename ( path ) ; } path = resolve ( program . out , path ) ; } var dir = resolve ( dirname ( path ) ) ; mkdirp . sync ( dir ) ; var output = options . client ? fn : fn ( options ) ; fs . writeFileSync ( path , output ) ; consoleLog ( '  ' + chalk . gray ( 'rendered' ) + ' ' + chalk . cyan ( '%s' ) , normalize ( path ) ) ; // Found directory } else if ( stat . isDirectory ( ) ) { var files = fs . readdirSync ( path ) ; files . map ( function ( filename ) { return path + '/' + filename ; } ) . forEach ( function ( file ) { render ( file , rootPath || path ) ; } ) ; } }
Process the given path, compiling the pug files found.
Always walk the subdirectories.

@param path      path of the file, might be relative
@param rootPath  path relative to the directory specified in the command
Process the given path compiling the pug files found . Always walk the subdirectories .