added addObject
This commit is contained in:
parent
5c3f150147
commit
8bb333ae8d
65
README.md
65
README.md
|
@ -1,12 +1,38 @@
|
|||
node-ff-assets
|
||||
=========
|
||||
|
||||
A small library providing automatic site assets local/remote aggregation with minify.
|
||||
A Node.js library providing automatic site assets aggregation and content modifiers.
|
||||
|
||||
## Installation
|
||||
|
||||
npm install node-ff-assets --save
|
||||
|
||||
## Target/Source locations
|
||||
|
||||
The asset target file location is a derived value.
|
||||
Its created by mapping the buildConfig.linkTarget in the buildConfig.linkMapping keys
|
||||
to get a prefix for the local file system location.
|
||||
The same is also true for the buildConfig.linkSources list which are url paths
|
||||
which need to be mapped to the file system files by the buildConfig.linkMapping data.
|
||||
|
||||
linkTarget: '/static/js/ffa/assets.js',
|
||||
linkMapping: ['/static/':'www_static/',],
|
||||
linkSources: ['/static/js/site.js','/static/js/ffa/jquery-2.1.3/jquery.js@http://code.jquery.com/jquery-2.1.3.js'],
|
||||
Gives;
|
||||
public js file: http://localhost:8080/static/js/site.js
|
||||
public js file: http://localhost:8080/static/js/ffa/assets.js
|
||||
public js file: http://localhost:8080/static/js/ffa/jquery-2.1.3/jquery.js
|
||||
filesystem file: www_static/js/site.js
|
||||
filesystem file: www_static/js/ffa/assets.js
|
||||
filesystem file: www_static/js/ffa/jquery-2.1.3/jquery.js
|
||||
.gitignore line: www_static/js/ffa
|
||||
|
||||
if buildConfig.linkTargetSingleResult = true render
|
||||
static/js/ffa/assets.js
|
||||
else
|
||||
static/js/site.js
|
||||
static/js/ffa/jquery-2.1.3/jquery.js
|
||||
|
||||
## Usage
|
||||
|
||||
// Create config object
|
||||
|
@ -19,10 +45,11 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
agent: 'node-ff-assets asset fetcher'
|
||||
},
|
||||
|
||||
linkTargetSingleResult: process.env.DEV_ASSETS_SINGLE_RESULT || true,
|
||||
linkTargetSingleResult: true,
|
||||
linkTarget: '/static-uri/js/assets.js',
|
||||
linkSources: [
|
||||
'/static/js/lib/jquery-2.1.3/jquery.js@http://code.jquery.com/jquery-2.1.3.js',
|
||||
'/static/js/lib/foobar/dyna.js@@http://localhost/force-download-on-every-build-for-this-file.js',
|
||||
'/static/js/site.js'
|
||||
],
|
||||
linkMapping: ['/static-uri/':'www_static/',],
|
||||
|
@ -40,14 +67,22 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
NodeFFAssets.pushLinkSourcesSync(buildConfig, '/static-uri/js/model/', 'www_public/js/model/');
|
||||
NodeFFAssets.pushLinkSourcesSync(buildConfig, '/static-uri/js/model/meta', 'www_public/js/model/meta');
|
||||
|
||||
// Create builder
|
||||
// Require library
|
||||
var NodeFFAssets = require('node-ff-assets');
|
||||
|
||||
// Create simpel builder
|
||||
var assetBuilderA = new NodeFFAssets.ResourceBuilder(buildConfig);
|
||||
|
||||
// Same as default, plain inclusion of content.
|
||||
var assetBuilderB = new NodeFFAssets.ResourceBuilder(buildConfig,NodeFFAssets.FunctionFactory.Constructor.readFile());
|
||||
|
||||
// Minify content, with optional Minify config options.
|
||||
var assetBuilderC = new NodeFFAssets.ResourceBuilder(buildConfig,NodeFFAssets.FunctionFactory.Constructor.readFileMinify());
|
||||
var assetBuilderD = new NodeFFAssets.ResourceBuilder(buildConfig,NodeFFAssets.FunctionFactory.Constructor.readFileMinify(minifyOptions));
|
||||
|
||||
// Third party content modifiers, with readFile function
|
||||
var assetBuilderE = new NodeFFAssets.ResourceBuilder(buildConfig,function(file,callback) {
|
||||
// return file data to callback(err,data);
|
||||
// should return file data to callback(err,data);
|
||||
);
|
||||
|
||||
// Hook events
|
||||
|
@ -81,8 +116,7 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
// all done
|
||||
});
|
||||
|
||||
// Use result
|
||||
|
||||
// Render result
|
||||
function renderIndex(app) {
|
||||
return function (req, res, next) {
|
||||
res.render('index', {
|
||||
|
@ -93,6 +127,7 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
};
|
||||
app.get('/',renderIndex(app));
|
||||
|
||||
// Template
|
||||
index.jade
|
||||
doctype html
|
||||
html(lang='en',ng-app='ffUI')
|
||||
|
@ -116,7 +151,15 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
script(src='#{jsFile}')
|
||||
|
||||
|
||||
## Example simple
|
||||
## Example mapping node_modules
|
||||
|
||||
Some js libraries can be directly served from node_packages and thus also be
|
||||
included the node-ff-assets output, but these required there own reverse mapping;
|
||||
|
||||
'/static/module/bootstrap/': 'node_modules/bootstrap/dist/',
|
||||
|
||||
This will let the parse find the /static/module/bootstrap/css/bootstrap.css resource and
|
||||
maps it the local file; node_modules/bootstrap/dist/css/bootstrap.css
|
||||
|
||||
// note1: www_static/[js/css]/lib is versioned ingored.
|
||||
// note2: server routes;
|
||||
|
@ -141,7 +184,7 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
// done
|
||||
})
|
||||
|
||||
// Use result as in simple example.
|
||||
// Render result as in usage example.
|
||||
|
||||
|
||||
## Example complex
|
||||
|
@ -152,7 +195,7 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
var NodeFFAssets = require('node-ff-assets');
|
||||
|
||||
function createBuildConfig(type) {
|
||||
var singleResult = true || process.env.DEV_ASSETS_SINGLE_RESULT;
|
||||
var singleResult = 'false' != process.env.DEV_ASSETS_SINGLE_RESULT;
|
||||
var linkMapping = {
|
||||
'/static/module/bootstrap/': 'node_modules/bootstrap/dist/',
|
||||
'/static/module/flot/': 'node_modules/flot/',
|
||||
|
@ -175,7 +218,6 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
linkTarget: '/static/js/lib/assets.js',
|
||||
linkSources: [
|
||||
'/static/js/lib/jquery-2.1.3/jquery.js@http://code.jquery.com/jquery-2.1.3.js',
|
||||
'/static/js/lib/foobar/dyna.js@@http://localhost/force-download-on-every-build-for-this-file.js',
|
||||
'/static/module/bootstrap/js/bootstrap.js',
|
||||
'/static/module/flot/jquery.flot.js',
|
||||
'/static/module/flot/jquery.flot.resize.js',
|
||||
|
@ -283,7 +325,6 @@ A small library providing automatic site assets local/remote aggregation with mi
|
|||
|
||||
// Result Next runs
|
||||
info: node-ff-assets-css build begin for: /static/css/lib/assets.css
|
||||
info: Started on port: 8008
|
||||
debug: node-ff-assets-css readFile: node_modules/bootstrap/dist/css/bootstrap.css size: 285496
|
||||
debug: node-ff-assets-css readFile: www_static/css/boot.css size: 1606
|
||||
debug: node-ff-assets-css readFile: www_static/css/flot.css size: 82
|
||||
|
@ -335,6 +376,8 @@ Add unit tests for any new or changed functionality. Lint and test your code.
|
|||
|
||||
## Release History
|
||||
|
||||
* 0.1.2 added objectAdd
|
||||
|
||||
* 0.1.1 Doc updates
|
||||
|
||||
* 0.1.0 Initial release
|
||||
|
|
22
index.js
22
index.js
|
@ -4,12 +4,14 @@ var NodeEvents = require('events');
|
|||
var NodeFetch = require('fetch');
|
||||
var NodeFs = require('fs');
|
||||
|
||||
var FULL_OPTIONS = {
|
||||
var DEFAULT_DOWNLOAD_MAX_SIZE = (1024*1024) * 10; // 10mb
|
||||
var DEFAULT_DOWNLOAD_TIMEOUT = (1000*60) * 1; // 1min
|
||||
var DEFAULT_OPTIONS = {
|
||||
downloadStartDelay: null,
|
||||
downloadForce: false,
|
||||
downloadOptions: {
|
||||
timeout: 10000,
|
||||
maxResponseLength: 10000000,
|
||||
timeout: DEFAULT_DOWNLOAD_TIMEOUT,
|
||||
maxResponseLength: DEFAULT_DOWNLOAD_MAX_SIZE,
|
||||
agent: 'node-ff-assets asset fetcher'
|
||||
},
|
||||
|
||||
|
@ -23,17 +25,6 @@ var FULL_OPTIONS = {
|
|||
assetSeperator: '\n/* node-ff-assets: next */\n',
|
||||
}
|
||||
|
||||
var DEFAULT_OPTIONS = {
|
||||
downloadOptions: {
|
||||
timeout: 10000,
|
||||
maxResponseLength: 10000000,
|
||||
agent: 'node-ff-assets asset fetcher'
|
||||
},
|
||||
assetHeader: '\n/* node-ff-assets: begin */\n\n',
|
||||
assetFooter: '\n/* node-ff-assets: end */\n\n',
|
||||
assetSeperator: '\n/* node-ff-assets: next */\n',
|
||||
}
|
||||
|
||||
function ResourceBuilder(config, readFile) {
|
||||
this.config = config;
|
||||
this.startTime = 0;
|
||||
|
@ -104,6 +95,9 @@ var FunctionFactory = {
|
|||
}
|
||||
};
|
||||
},
|
||||
objectAdd: function(object,resultKey) {
|
||||
return FunctionFactory.Event.result.objectFunction(object,'add',resultKey);
|
||||
},
|
||||
objectSet: function(object,resultKey) {
|
||||
return FunctionFactory.Event.result.objectFunction(object,'set',resultKey);
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "node-ff-assets",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"description": "Site assets local/remote aggregation with minify.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in a new issue