0.4.0 • Published 7 years ago
directory-shaker v0.4.0
Directory Shaker
Convert JS files (include ES6) structure into object, extract data
Installation
npm install directory-shakerUsage
const path = require('path');
const getTreeObj = require('directory-shaker');
.........
const folder = path.resolve(__dirname, 'folder');
const { tree, parserName1, parserName2 } = getTreeObj(folder, {
recursive: true,
spreadIndex: true,
pattern: /^.*\.js$/,
filter: () => true,
}, { // parser }, { // parser } )
.........Check test folder for more examples
Arguments
path: string:path to the root folder to start withoptions: object:configuration optionsparser: object:parser to extract data separately
Options
recursive: boolean: truedeep object constructionspreadIndex: boolean: trueassign index props to the root or in 'index' nodepattern: RegExp: /^.*\.js$/file pattern to be included in the treefilter: function:filter files to be included in the tree
Parser
{
name: 'paths',
key: 'name',
map: ({ name, page }, meta) => ({ name, page, meta}),
}name: string:name of the object to be returnedkey: string:key in the result object to assign result of the map functionmap: function:function to prepare object data to be returned
Map Function
data: object:file default exported objectmeta: object:file meta data: 'name' and 'path'
Limitations
See 'esm' library documentation for the limitations