nl_tokens: Recursively copies sourceDir into destDir Adapted from https : // github . com / ryanmcgrath / wrench - js Copyright ( c ) 2010 Ryan McGrath Copyright ( c ) 2012 Artur Adib Licensed under the MIT License http : // www . opensource . org / licenses / mit - license . php
pl_tokens: function cpdirSyncRecursive ( sourceDir , destDir , opts ) { if ( ! opts ) opts = { } ; /* Create the directory where all our junk is moving to; read the mode of the source directory and mirror it */ var checkDir = fs . statSync ( sourceDir ) ; try { fs . mkdirSync ( destDir , checkDir . mode ) ; } catch ( e ) { //if the directory already exists, that's okay if ( e . code !== 'EEXIST' ) throw e ; } var files = fs . readdirSync ( sourceDir ) ; for ( var i = 0 ; i < files . length ; i ++ ) { var srcFile = sourceDir + "/" + files [ i ] ; var destFile = destDir + "/" + files [ i ] ; var srcFileStat = fs . lstatSync ( srcFile ) ; if ( srcFileStat . isDirectory ( ) ) { /* recursion this thing right on back. */ cpdirSyncRecursive ( srcFile , destFile , opts ) ; } else if ( srcFileStat . isSymbolicLink ( ) ) { var symlinkFull = fs . readlinkSync ( srcFile ) ; fs . symlinkSync ( symlinkFull , destFile , os . platform ( ) === "win32" ? "junction" : null ) ; } else { /* At this point, we've hit a file actually worth copying... so copy it on over. */ if ( <mask> . existsSync ( destFile ) && ! opts . force ) { common . log ( 'skipping existing file: ' + files [ i ] ) ; } else { copyFileSync ( srcFile , destFile ) ; } } } // for files }