2
0
Fork 0
node-ff-assets/README.md

103 lines
3.6 KiB
Markdown
Raw Permalink Normal View History

2015-02-24 11:39:38 +00:00
node-ff-assets
=========
A small library providing automatic site assets local/remote aggregation with minify.
## Installation
npm install node-ff-assets --save
## Usage
// Create config object;
var buildConfig = {
downloadStartDelay: null,
downloadForce: false,
downloadOptions: {
timeout: 10000,
maxResponseLength: 10000000,
agent: 'node-ff-assets asset fetcher'
},
linkTargetSingleResult: true,
linkTarget: null,
linkSources: [],
linkMapping: [],
assetHeader: '\n/* node-ff-assets: begin */\n\n',
assetFooter: '\n/* node-ff-assets: end */\n\n',
assetSeperator: '\n/* node-ff-assets: next */\n',
}
// Create builder
var NodeFFAssets = require('node-ff-assets');
var assetBuilderA = new NodeFFAssets.ResourceBuilder(buildConfig);
var assetBuilderB = new NodeFFAssets.ResourceBuilder(buildConfig,NodeFFAssets.FunctionFactory.Constructor.readFile());
var assetBuilderC = new NodeFFAssets.ResourceBuilder(buildConfig,NodeFFAssets.FunctionFactory.Constructor.readFileMinify());
var assetBuilderD = new NodeFFAssets.ResourceBuilder(buildConfig,NodeFFAssets.FunctionFactory.Constructor.readFileMinify(minifyOptions));
var assetBuilderE = new NodeFFAssets.ResourceBuilder(buildConfig,function(file,callback) {
// return file data to callback(err,data);
);
// Create events
assetBuilderA.on('begin', function() { });
assetBuilderA.on('end', function() { });
assetBuilderA.on('log', function(logLevel, logMessage) { });
assetBuilderA.on('error', function(err) { });
assetBuilderA.on('result', function(resultValue) { });
assetBuilderA.on('file-download-pre', function(remoteUrl) { });
assetBuilderA.on('file-download-post', function(localFile) { });
assetBuilderA.on('file-read-pre', function(localFile) { });
assetBuilderA.on('file-read-post', function(localFile) { });
assetBuilderA.on('file-write-pre', function(targetFile) { });
assetBuilderA.on('file-write-post', function(targetFile) { });
// Use build in event functions
assetBuilderB.on('log', NodeFFAssets.FunctionFactory.Event.log.console('css'));
assetBuilderB.on('result', NodeFFAssets.FunctionFactory.Event.result.objectSet(server,'includeCssFiles'));
// Run builder
assetBuilderC.run(function(err) {
//done
});
## Example simple
// note1: www_static/[js/css]/lib is versioned ingored.
// note2: server routes;
// app.use('/static',express.static(path.join(__dirname,'www_static')));
// app.use('/static/module/bootstrap',express.static(path.join(__dirname,'node_modules/bootstrap/dist')));
var NodeFFAssets = require('node-ff-assets');
var buildCss = new NodeFFAssets.ResourceBuilder({
linkMapping: {
'/static/module/bootstrap/': 'node_modules/bootstrap/dist/',
'/static/': 'www_static/',
},
linkTarget: '/static/css/lib/assets.css',
linkSources: [
'/static/module/bootstrap/css/bootstrap.css',
'/static/css/site.css',
],
});
buildCss.on('log', NodeFFAssets.FunctionFactory.Event.log.console('css'));
buildCss.on('result', NodeFFAssets.FunctionFactory.Event.result.objectSet(server,'includeCssFiles'));
buildCss.run(function(err) {
// done
})
## Tests
npm test (TODO)
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality. Lint and test your code.
## Release History
* 0.1.0 Initial release