lib/util.js
function cleanDir( path, _preserveGit ) {
    const
    preserveGit = typeof _preserveGit !== 'undefined' ? _preserveGit : false,
    fullPath = Path.resolve( path );
    // If the pah does not exist, everything is fine!
    if ( !FS.existsSync( fullPath ) ) return;

    if ( preserveGit ) {

        /*
         * We must delete the content of this folder but preserve `.git`.
         * The `www` dir, for instance, can be used as a `gh-pages` branch.
         */
        const files = FS.readdirSync( path );
        files.forEach( function forEachFile( filename ) {
            if ( filename === '.git' ) return;
            const
            filepath = Path.join( path, filename ),
            stat = FS.statSync( filepath );
            if ( stat.isDirectory() ) {
                if ( filepath !== '.' && filepath !== '..' ) PathUtils.rmdir( filepath );
            } else FS.unlinkSync( filepath );
        } );
    } else {
        // Brutal clean: remove dir and recreate it.
        PathUtils.rmdir( path );
        PathUtils.mkdir( path );
    }
}
function cleanDir( path, _preserveGit ) {
    const
    preserveGit = typeof _preserveGit !== 'undefined' ? _preserveGit : false,
    fullPath = Path.resolve( path );
    // If the pah does not exist, everything is fine!
    if ( !FS.existsSync( fullPath ) ) return;

    if ( preserveGit ) {

        /*
         * We must delete the content of this folder but preserve `.git`.
         * The `www` dir, for instance, can be used as a `gh-pages` branch.
         */
        const files = FS.readdirSync( path );
        files.forEach( function forEachFile( filename ) {
            if ( filename === '.git' ) return;
            const
            filepath = Path.join( path, filename ),
            stat = FS.statSync( filepath );
            if ( stat.isDirectory() ) {
                if ( filepath !== '.' && filepath !== '..' ) PathUtils.rmdir( filepath );
            } else FS.unlinkSync( filepath );
        } );
    } else {
        // Brutal clean: remove dir and recreate it.
        PathUtils.rmdir( path );
        PathUtils.mkdir( path );
    }
}
function cleanDir ( path , _preserveGit ) { const preserveGit = typeof _preserveGit !== 'undefined' ? _preserveGit : false , fullPath = Path . resolve ( path ) ; // If the pah does not exist, everything is fine! if ( ! FS . existsSync ( fullPath ) ) return ; if ( preserveGit ) { /*
         * We must delete the content of this folder but preserve `.git`.
         * The `www` dir, for instance, can be used as a `gh-pages` branch.
         */ const files = FS . readdirSync ( path ) ; files . forEach ( function forEachFile ( filename ) { if ( filename === '.git' ) return ; const filepath = Path . join ( path , filename ) , stat = FS . statSync ( filepath ) ; if ( stat . isDirectory ( ) ) { if ( filepath !== '.' && filepath !== '..' ) PathUtils . rmdir ( filepath ) ; } else FS . unlinkSync ( filepath ) ; } ) ; } else { // Brutal clean: remove dir and recreate it. PathUtils . rmdir ( path ) ; PathUtils . mkdir ( path ) ; } }
Remove all files and directories found in `path`, but not `path` itself.
@param {string} path - The folder we want to clean the content.
@param {boolean} _preserveGit [false] - If `true`, the folder ".git" is not deleted.
@returns {undefined}
Remove all files and directories found in path but not path itself .