scrollfinder

1.0.1 • Public • Published

Scrollfinder

A small module for traversing folder hierarchies and finding your very modular scripts (and scrolls), such that they can be used without compilation.

Installation

npm install scrollfinder --save

Usage

var sf = require('scrollfinder');
var pathList = sf.find(options);

Where options is an object with configurable (optional) options.

options.rootDirectory string Local root directory (inclusive) where to start the search. Relative or absolute. {Default: '.'}
options.rootURL string Prefix of the generated URL path for each found file. {Default: ''}
options.fileExtension string File ending to match, empty string to match all. Unmatched files will be ignored. {Default: ''}
options.objectForm string If set, the returned list will be a list of objects where the key is the value of options.objectForm. If not set, a list of strings is returned. {Default: ''}
options.ignore[] [string] A list of strings (files or directories, either just filename or full paths) to ignore. Upon searching, this list will be appended to with each found local path to allow for chaining without repetition. {Default: []}

Important: There is no guarantee on the order of two files in the same folder. However files higher in the tree will always come before lower ones.

Example

Given the following folder structure

client/
    app/
        module1/
            module1Ctrl.js
            module1View.html
        module2/
            module2Ctrl.js
            module2View.html
        app.js
    assets/
        js/
            angular.js
            bootstrap.js
        css/
            styles.css
node_modules/
server.js

we want to generate a list of javascript include paths to everything in client/app prefixed with /app in the url.

var scriptList = sf.find({
    rootDirectory: 'client/app',
    rootURL: '/app',
    fileExtension: '.js'
});

This will generate a list similar to

['/app/app.js',
 '/app/module1/module1Ctrl.js'
 '/app/module2/module2Ctrl.js'];

Note: there is no guarantee to the order of the two files in the same folder.

If we wanted to use it to generate script includes in express.js with hogan templates we could use the following options.

var options = {
    rootDirectory: 'client/app',
    rootURL: '/app',
    fileExtension: '.js',
    objectForm: 'url'
};

var app = express();
app.locals.appIncludes = sf.find(options);

Then in a template

{{# appIncludes }}
<script src="{{{ url }}}"></script>
{{/ appIncludes }}

Package Sidebar

Install

npm i scrollfinder

Weekly Downloads

0

Version

1.0.1

License

none

Last publish

Collaborators

  • xtoffer