sample compressed tree

This commit is contained in:
Joao Moreno
2019-07-23 10:58:01 +02:00
parent 5bbf920131
commit c0ee1a958f
2 changed files with 25 additions and 10 deletions

24
test/tree/tree.js Normal file
View File

@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const path = require('path');
const fs = require('fs');
function collect(location) {
const element = path.basename(location);
const stat = fs.statSync(location);
if (!stat.isDirectory()) {
return { element };
}
const children = fs.readdirSync(location)
.map(child => path.join(location, child))
.map(collect);
return { element, children };
}
console.log(JSON.stringify(collect(process.cwd())));