mirror of https://github.com/embarklabs/embark.git
Moved `fileTreeSort()` to `utils`
This commit is contained in:
parent
35a701fb90
commit
72a796c11b
|
@ -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);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue