fs-scanner
Scans a given directory and get back a tree with the results of the path and its sub-paths.
What aims to?
This module aims to give you an object with a tree to get any directory found using the "dot" notation, an array collection of the sub-paths and some other options to help you more.
Where it can be used?
- It can be used only with node because it uses the "fs" modules of node.js
Where it can not be used?
- It cannot be used as a browser module because it uses the "fs" module of node.js, although in this repository I'm going to give you some examples which how can you make use of it as a simple workaround.
Pre-requisites
- A html file to use as template.
- The html file must include a div or any element with an id attribute to mount the component.
- The components path or a file with all the routes. (see react-router v4 docs)
Installation
npm install --save fs-scanner or yarn add fs-scanner
Usage
Whenever you import it, it will give you a class to create instances.
const Scanner = require('fs-scanner')
After having it imported you will need to pass some options to scan:
| path | string | __dirname | Absolute path of the directory to scan. |
| index | string | '_' | A name used in the tree to access to the root of each directory. |
| prefix | object | null | This lets you to prepend a text to alter the name of each directory. |
| suffix | object | null | This lets you to append a text to alter the name of each directory. |
| ignore | string/array | null | You can ignore a path using piece of string or an array with the name of the directories. |
Examples:
const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)
const scanner = new Scanner()
console.log(scanner)
Custom path:
const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)
const scanner = new Scanner({
path: root('./src')
})
console.log(scanner.tree)
console.log(scanner.collection)
Ignoring:
const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)
const scanner = new Scanner({
path: root('./src'),
ignore: '/assets',
})
console.log(scanner.tree)
console.log(scanner.collection)
Ignoring array:
const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)
const scanner = new Scanner({
path: root('./src'),
ignore: ['/assets', 'server'],
})
console.log(scanner.tree)
console.log(scanner.collection)
Using prefix and suffix:
const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)
const scanner = new Scanner({
path: root('./src'),
ignore: ['/assets', 'server'],
prefix: {
client: 'prefijo',
},
suffix: {
client: 'sufijo',
},
})
console.log(scanner.tree)
console.log(scanner.collection)
Using a custom index:
const { resolve } = require('path')
const root = src => resolve(process.cwd(), src)
const scanner = new Scanner({
path: root('./src'),
ignore: ['/assets', 'server'],
prefix: {
client: 'prefijo',
},
suffix: {
client: 'sufijo',
},
index: '__root__',
})
console.log(scanner.tree)
console.log(scanner.collection)
Maintainers:

Norman Carcamo
NPM - modules