plugins/watcher/watcher.js
function getFileList(dir, sort = true) {
    return new Promise((resolve, reject) => {
        readdir(dir, (error, files) => {
            if (error) {
                reject(error);
                return;
            }
            let resultantFilesList;

            if (sort) {
                const stripLength = (dir.substr(0, 2) === './') ? dir.length - 1 : dir.length + 1;
                let pathsUnified = files.map((pth => pth.substr(stripLength).replace(/[\\/]/gm, '-')));
                const temporaryIndex = {};
                files.forEach((file, i) => {
                    temporaryIndex[pathsUnified[i]] = file;
                });
                pathsUnified = pathsUnified.sort();
                const filesSorted = [];
                pathsUnified.forEach((key) => {
                    filesSorted.push(temporaryIndex[key]);
                });

                resultantFilesList = filesSorted;
            } else {
                resultantFilesList = files;
            }
            resolve(resultantFilesList);
        });
    });
}
function getFileList(dir, sort = true) {
    return new Promise((resolve, reject) => {
        readdir(dir, (error, files) => {
            if (error) {
                reject(error);
                return;
            }
            let resultantFilesList;

            if (sort) {
                const stripLength = (dir.substr(0, 2) === './') ? dir.length - 1 : dir.length + 1;
                let pathsUnified = files.map((pth => pth.substr(stripLength).replace(/[\\/]/gm, '-')));
                const temporaryIndex = {};
                files.forEach((file, i) => {
                    temporaryIndex[pathsUnified[i]] = file;
                });
                pathsUnified = pathsUnified.sort();
                const filesSorted = [];
                pathsUnified.forEach((key) => {
                    filesSorted.push(temporaryIndex[key]);
                });

                resultantFilesList = filesSorted;
            } else {
                resultantFilesList = files;
            }
            resolve(resultantFilesList);
        });
    });
}
function getFileList ( dir , sort = true ) { return new Promise ( ( resolve , reject ) => { readdir ( dir , ( error , files ) => { if ( error ) { reject ( error ) ; return ; } let resultantFilesList ; if ( sort ) { const stripLength = ( dir . substr ( 0 , 2 ) === './' ) ? dir . length - 1 : dir . length + 1 ; let pathsUnified = files . map ( ( pth => pth . substr ( stripLength ) . replace ( / [\\/] / gm , '-' ) ) ) ; const temporaryIndex = { } ; files . forEach ( ( file , i ) => { temporaryIndex [ pathsUnified [ i ] ] = file ; } ) ; pathsUnified = pathsUnified . sort ( ) ; const filesSorted = [ ] ; pathsUnified . forEach ( ( key ) => { filesSorted . push ( temporaryIndex [ key ] ) ; } ) ; resultantFilesList = filesSorted ; } else { resultantFilesList = files ; } resolve ( resultantFilesList ) ; } ) ; } ) ; }
Returns a file list from a directory.
@param {string} dir - dir path
@returns {Promise<Array>}
Returns a file list from a directory .