added test and updated readme prep next release
This commit is contained in:
parent
144854400f
commit
95478f85c3
8 changed files with 304 additions and 210 deletions
27
example/example-assets.json
Normal file
27
example/example-assets.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"linkMapping" : {
|
||||
"/static/module/bootstrap/": "node_modules/bootstrap/dist/",
|
||||
"/static/module/flot/": "node_modules/flot/",
|
||||
"/static/": "www_static/"
|
||||
},
|
||||
"css": {
|
||||
"linkTarget": "/static/css/lib/assets.css",
|
||||
"linkSources": [
|
||||
"/static/module/bootstrap/css/bootstrap.css"
|
||||
]
|
||||
},
|
||||
"js": {
|
||||
"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/module/bootstrap/js/bootstrap.js",
|
||||
"/static/module/flot/jquery.flot.js",
|
||||
"/static/module/flot/jquery.flot.resize.js",
|
||||
"/static/module/flot/jquery.flot.pie.js",
|
||||
"/static/js/lib/angularjs-1.4.0-b4/angular.js@https://code.angularjs.org/1.4.0-beta.4/angular.js",
|
||||
"/static/js/lib/angularjs-1.4.0-b4/angular-route.js@https://code.angularjs.org/1.4.0-beta.4/angular-route.js",
|
||||
"/static/js/lib/angularjs-1.4.0-b4/angular-resource.js@https://code.angularjs.org/1.4.0-beta.4/angular-resource.js",
|
||||
"/static/js/lib/angularjs-1.4.0-b4/angular-touch.js@https://code.angularjs.org/1.4.0-beta.4/angular-touch.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -5,59 +5,13 @@ var async = require('async');
|
|||
var path = require('path');
|
||||
var assets = require('../lib/node-ff-assets');
|
||||
|
||||
var assetsConfig = {
|
||||
// Map from uri paths to file systems paths.
|
||||
linkMapping : {
|
||||
'/static/module/bootstrap/': 'node_modules/bootstrap/dist/',
|
||||
'/static/module/flot/': 'node_modules/flot/',
|
||||
'/static/': 'www_static/',
|
||||
},
|
||||
linkSourcesCss : [
|
||||
'/static/module/bootstrap/css/bootstrap.css',
|
||||
],
|
||||
linkSourcesJs : [
|
||||
'/static/js/lib/jquery-2.1.3/jquery.js@http://code.jquery.com/jquery-2.1.3.js',
|
||||
'/static/module/bootstrap/js/bootstrap.js',
|
||||
'/static/module/flot/jquery.flot.js',
|
||||
'/static/module/flot/jquery.flot.resize.js',
|
||||
'/static/module/flot/jquery.flot.pie.js',
|
||||
'/static/js/lib/angularjs-1.4.0-b4/angular.js@https://code.angularjs.org/1.4.0-beta.4/angular.js',
|
||||
'/static/js/lib/angularjs-1.4.0-b4/angular-route.js@https://code.angularjs.org/1.4.0-beta.4/angular-route.js',
|
||||
'/static/js/lib/angularjs-1.4.0-b4/angular-resource.js@https://code.angularjs.org/1.4.0-beta.4/angular-resource.js',
|
||||
'/static/js/lib/angularjs-1.4.0-b4/angular-touch.js@https://code.angularjs.org/1.4.0-beta.4/angular-touch.js',
|
||||
],
|
||||
};
|
||||
|
||||
//callback helper to return an assembler config per asset type
|
||||
function createBuildConfig(type) {
|
||||
return function(callback) {
|
||||
var singleResult = 'false' !== process.env.DEV_ASSETS_SINGLE_RESULT;
|
||||
console.info('Asset single page result: '+singleResult+' for: '+type);
|
||||
if (type === 'css') {
|
||||
callback(null,{
|
||||
linkMapping: assetsConfig.linkMapping,
|
||||
linkTargetSingleResult: singleResult,
|
||||
linkTarget: '/static/css/lib/assets.css',
|
||||
linkSources: assetsConfig.linkSourcesCss,
|
||||
assetType: type,
|
||||
});
|
||||
} else {
|
||||
callback(null, {
|
||||
linkTargetSingleResult: singleResult,
|
||||
linkMapping: assetsConfig.linkMapping,
|
||||
linkTarget: '/static/js/lib/assets.js',
|
||||
linkSources: assetsConfig.linkSourcesJs,
|
||||
assetType: type,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function buildAssets(server,callbackDone) {
|
||||
var singleResult = 'false' !== process.env.DEV_ASSETS_SINGLE_RESULT;
|
||||
var assetsConfig = require('./example-assets.json');
|
||||
assets.build({
|
||||
assets: {
|
||||
js: {
|
||||
configCreate: createBuildConfig('js'),
|
||||
configCreate: assets.factory.builder.configCreate.fromJSON(assetsConfig,'js'),
|
||||
configFill: function (config, callback) {
|
||||
async.series([
|
||||
assets.factory.lib.async.pushLinkSources(config, '/static/js/', 'www_static/js/'),
|
||||
|
|
@ -66,34 +20,33 @@ function buildAssets(server,callbackDone) {
|
|||
},
|
||||
},
|
||||
css: {
|
||||
configCreate: createBuildConfig('css'),
|
||||
configCreate: assets.factory.builder.configCreate.fromJSON(assetsConfig,'css'),
|
||||
configFill: function (config, callback) {
|
||||
async.series([
|
||||
assets.factory.lib.async.pushLinkSources(config, '/static/css/', 'www_static/css/'),
|
||||
assets.factory.lib.async.pushLinkSources(config, '/static/css/', 'www_static/css/'),
|
||||
],callback);
|
||||
|
||||
},
|
||||
assemblerCreate: function (assemblerConfig, callback) {
|
||||
callback(null,new assets.AssetAssembler(assemblerConfig,assets.factory.assembler.constructor.readFileMinify()));
|
||||
},
|
||||
},
|
||||
},
|
||||
assemblerCreate: assets.factory.builder.assemblerCreate.readFileRegex(),
|
||||
assemblerFill: function (assembler, callback) {
|
||||
var serverResultKey = 'ff_assets_'+assembler.config.assetType;
|
||||
assembler.on ('log', assets.factory.assembler.event.log.console(assembler.config.assetType));
|
||||
assembler.on ('result', assets.factory.assembler.event.result.objectSet(server,serverResultKey));
|
||||
assembler.config.linkTargetSingleResult = singleResult;
|
||||
callback();
|
||||
},
|
||||
},callbackDone);
|
||||
}
|
||||
|
||||
function renderTemplate() {
|
||||
function renderTemplatePath(viewPath) {
|
||||
return function (req, res) {
|
||||
if (req.params.sub) {
|
||||
res.render('thtml/' + req.params.page + '/' + req.params.sub);
|
||||
} else {
|
||||
res.render('thtml/' + req.params.page);
|
||||
res.locals.query = req.query;
|
||||
var qi = req.url.indexOf('?');
|
||||
if (qi === -1) {
|
||||
qi = req.url.length;
|
||||
}
|
||||
res.render(viewPath + req.url.substring(req.route.path.length-1, qi));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -123,14 +76,13 @@ buildAssets(server,function(err) {
|
|||
console.info('Server assets done.');
|
||||
|
||||
server.set('view engine', 'ejs');
|
||||
server.set('views', path.join(__dirname, 'www_views'));
|
||||
server.use('/static',express.static(path.join(__dirname,'www_static')));
|
||||
server.use('/static/module/bootstrap',express.static(path.join(__dirname,'node_modules/bootstrap/dist')));
|
||||
server.use('/static/module/flot',express.static(path.join(__dirname,'node_modules/flot')));
|
||||
server.set('views', path.join(__dirname,'www_views'));
|
||||
server.use('/static', express.static(path.join(__dirname,'www_static')));
|
||||
server.use('/static/module/bootstrap', express.static(path.join(__dirname,'node_modules/bootstrap/dist')));
|
||||
server.use('/static/module/flot', express.static(path.join(__dirname,'node_modules/flot')));
|
||||
|
||||
server.get('/example-ui/thtml/:page', renderTemplate());
|
||||
server.get('/example-ui/thtml/:page/:sub', renderTemplate());
|
||||
server.get('/', sendRedirect());
|
||||
server.get('/example-ui/thtml/*', renderTemplatePath('thtml/'));
|
||||
server.get('/example-ui', renderPage(server));
|
||||
server.get('/example-ui/*', renderPage(server)); // must be last; for HTML5 history
|
||||
console.info('Server config done.');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue