diff --git a/lib/modules/pipeline/index.js b/lib/modules/pipeline/index.js index 7f56a418d..4899e0e6e 100644 --- a/lib/modules/pipeline/index.js +++ b/lib/modules/pipeline/index.js @@ -74,26 +74,6 @@ class Pipeline { (req, res) => { const rootPath = fs.dappPath(); - function isFolder(object) { - return object.children && object.children.length; - } - - function isNotFolder(object){ - return !isFolder(object); - } - - function byName(a, b) { - return a.name.localeCompare(b.name); - } - - function fileTreeSort(objects){ - - const folders = objects.filter(isFolder).sort(byName); - const files = objects.filter(isNotFolder).sort(byName); - - return folders.concat(files); - } - const walk = (dir, filelist = []) => fs.readdirSync(dir).map(name => { let isRoot = rootPath === dir; if (fs.statSync(path.join(dir, name)).isDirectory()) { @@ -103,7 +83,7 @@ class Pipeline { dirname: dir, path: path.join(dir, name), isHidden: name.indexOf('.') === 0, - children: fileTreeSort(walk(path.join(dir, name), filelist))}; + children: utils.fileTreeSort(walk(path.join(dir, name), filelist))}; } return { name, @@ -113,7 +93,7 @@ class Pipeline { isHidden: name.indexOf('.') === 0 }; }); - const files = fileTreeSort(walk(fs.dappPath())); + const files = utils.fileTreeSort(walk(fs.dappPath())); res.send(files); } ); diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 436d48310..34ffe50ef 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -494,6 +494,25 @@ function timer(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } +function isFolder(node) { + return node.children && node.children.length; +} + +function isNotFolder(node){ + return !isFolder(node); +} + +function byName(a, b) { + return a.name.localeCompare(b.name); +} + +function fileTreeSort(nodes){ + const folders = nodes.filter(isFolder).sort(byName); + const files = nodes.filter(isNotFolder).sort(byName); + + return folders.concat(files); +} + module.exports = { joinPath, dirname, @@ -537,5 +556,6 @@ module.exports = { last, interceptLogs, errorMessage, - timer + timer, + fileTreeSort };