1.0.1 • Published 8 years ago

scrollfinder v1.0.1

Weekly downloads
13
License
-
Repository
github
Last release
8 years ago

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.

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 }}