diff --git a/README.md b/README.md index 3051c5a..87a0cd5 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ A Node.js library providing automatic site assets aggregation. ## Example Application There is a fully working express example application in the example folder. - This contains bootstrap and angularjs and ejs templates and results in single js and css file. + This contains bootstrap and angularjs and ejs templates and results in single html/js/css file. ## Usage - note: www_static/[js/css]/lib are version ignored. + note: www_static/[js/css]/lib are scm version ignored. ### example-assets.json @@ -293,7 +293,7 @@ A Node.js library providing automatic site assets aggregation. // Registrate events (note: may change a bit) assetAssemblerA.on('begin', function() { }); assetAssemblerA.on('end', function() { }); - assetAssemblerA.on('log', function(logLevel, logMessage) { }); + assetAssemblerA.on('log', function(logMessage) { }); assetAssemblerA.on('result', function(resultValue) { }); assetAssemblerA.on('file-download-pre', function(remoteUrl) { }); assetAssemblerA.on('file-download-post', function(localFile) { }); @@ -313,94 +313,58 @@ A Node.js library providing automatic site assets aggregation. ## Example log output - // Result First run - info: node-ff-assets-css build begin for: /static/css/lib/assets.css - 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 - debug: node-ff-assets-css readFile: www_static/css/panel.css size: 545 - debug: node-ff-assets-css readFile: www_static/css/style.css size: 10419 - debug: node-ff-assets-css target size: 298318 - info: node-ff-assets-css build result size: 1 from: 5 - info: node-ff-assets-css build done in: 33 ms. - info: node-ff-assets-js build begin for: /static/js/lib/assets.js - debug: node-ff-assets-js downloadFile: http://code.jquery.com/jquery-2.1.3.js - debug: node-ff-assets-js downloadFile: https://code.angularjs.org/1.4.0-beta.4/angular.js - debug: node-ff-assets-js downloadFile: https://code.angularjs.org/1.4.0-beta.4/angular-route.js - debug: node-ff-assets-js downloadFile: https://code.angularjs.org/1.4.0-beta.4/angular-resource.js - debug: node-ff-assets-js downloadFile: https://code.angularjs.org/1.4.0-beta.4/angular-touch.js - debug: node-ff-assets-js downloadFile: http://localhost:8008/ui/include/js/controller/test1 - GET /ui/include/js/controller/test1 200 7.931 ms - - - debug: node-ff-assets-js downloadFile: http://localhost:8008/ui/include/js/controller/test2 - GET /ui/include/js/controller/test2 200 5.215 ms - - - debug: node-ff-assets-js downloadFile: http://localhost:8008/ui/include/js/controller/test3 - GET /ui/include/js/controller/test3 200 1.583 ms - - - debug: node-ff-assets-js readFile: www_static/js/lib/jquery-2.1.3/jquery.js size: 247387 - debug: node-ff-assets-js readFile: node_modules/bootstrap/dist/js/bootstrap.js size: 66732 - debug: node-ff-assets-js readFile: node_modules/flot/jquery.flot.js size: 110008 - debug: node-ff-assets-js readFile: node_modules/flot/jquery.flot.resize.js size: 2504 - debug: node-ff-assets-js readFile: node_modules/flot/jquery.flot.pie.js size: 23405 - debug: node-ff-assets-js readFile: www_static/js/lib/angularjs-1.4.0-b4/angular.js size: 988198 - debug: node-ff-assets-js readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-route.js size: 35796 - debug: node-ff-assets-js readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-resource.js size: 26780 - debug: node-ff-assets-js readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-touch.js size: 22887 - debug: node-ff-assets-js readFile: www_static/js/app-directives.js size: 185 - debug: node-ff-assets-js readFile: www_static/js/app-filters.js size: 202 - debug: node-ff-assets-js readFile: www_static/js/app-services.js size: 80 - debug: node-ff-assets-js readFile: www_static/js/app.js size: 766 - debug: node-ff-assets-js readFile: www_static/js/controller/page-about.js size: 364 - debug: node-ff-assets-js readFile: www_static/js/controller/page-foobar.js size: 361 - debug: node-ff-assets-js readFile: www_static/js/controller/page-index.js size: 351 - debug: node-ff-assets-js readFile: www_static/js/controller/page-help.js size: 376 - debug: node-ff-assets-js readFile: www_static/js/lib/xcrud/test1.js size: 2010 - debug: node-ff-assets-js readFile: www_static/js/lib/xcrud/test2.js size: 2138 - debug: node-ff-assets-js readFile: www_static/js/lib/xcrud/test3.js size: 2218 - debug: node-ff-assets-js target size: 1540945 - info: node-ff-assets-js build result size: 1 from: 24 - info: node-ff-assets-js build done in: 3497 ms. - info: Server init done. - - // Result Next runs - info: node-ff-assets-css build begin for: /static/css/lib/assets.css - 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 - debug: node-ff-assets-css readFile: www_static/css/panel.css size: 545 - debug: node-ff-assets-css readFile: www_static/css/style.css size: 10419 - debug: node-ff-assets-css target size: 298318 - info: node-ff-assets-css build result size: 1 from: 5 - info: node-ff-assets-css build done in: 36 ms. - info: node-ff-assets-js build begin for: /static/js/lib/assets.js - debug: node-ff-assets-js downloadFile: http://localhost:8008/ui/include/js/controller/test1 - GET /ui/include/js/controller/test1 200 7.931 ms - - - debug: node-ff-assets-js downloadFile: http://localhost:8008/ui/include/js/controller/test2 - GET /ui/include/js/controller/test2 200 5.215 ms - - - debug: node-ff-assets-js downloadFile: http://localhost:8008/ui/include/js/controller/test3 - GET /ui/include/js/controller/test3 200 1.583 ms - - - debug: node-ff-assets-js readFile: www_static/js/lib/jquery-2.1.3/jquery.js size: 247387 - debug: node-ff-assets-js readFile: node_modules/bootstrap/dist/js/bootstrap.js size: 66732 - debug: node-ff-assets-js readFile: node_modules/flot/jquery.flot.js size: 110008 - debug: node-ff-assets-js readFile: node_modules/flot/jquery.flot.resize.js size: 2504 - debug: node-ff-assets-js readFile: node_modules/flot/jquery.flot.pie.js size: 23405 - debug: node-ff-assets-js readFile: www_static/js/lib/angularjs-1.4.0-b4/angular.js size: 988198 - debug: node-ff-assets-js readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-route.js size: 35796 - debug: node-ff-assets-js readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-resource.js size: 26780 - debug: node-ff-assets-js readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-touch.js size: 22887 - debug: node-ff-assets-js readFile: www_static/js/app-directives.js size: 185 - debug: node-ff-assets-js readFile: www_static/js/app-filters.js size: 202 - debug: node-ff-assets-js readFile: www_static/js/app-services.js size: 80 - debug: node-ff-assets-js readFile: www_static/js/app.js size: 766 - debug: node-ff-assets-js readFile: www_static/js/controller/page-about.js size: 364 - debug: node-ff-assets-js readFile: www_static/js/controller/page-foobar.js size: 361 - debug: node-ff-assets-js readFile: www_static/js/controller/page-index.js size: 351 - debug: node-ff-assets-js readFile: www_static/js/controller/page-help.js size: 376 - debug: node-ff-assets-js readFile: www_static/js/lib/xcrud/test1.js size: 2010 - debug: node-ff-assets-js readFile: www_static/js/lib/xcrud/test2.js size: 2138 - debug: node-ff-assets-js readFile: www_static/js/lib/xcrud/test3.js size: 2218 - debug: node-ff-assets-js target size: 1540945 - info: node-ff-assets-js build result size: 1 from: 24 - info: node-ff-assets-js build done in: 105 ms. - info: Server init done. + First run with downloads and with DEBUG="*" + + ff:assets:assets-builder runAll started. +0ms + ff:assets:assets-builder runAsset started for: css +1ms + ff:assets:assets-builder runAsset started for: js +0ms + ff:assets:assets-builder assemblerCreate from default +2ms + ff:assets:assets-builder assemblerFill from default +0ms + ff:assets:assets-builder runAssembler type: css +0ms + node-ff-assets:css build begin for: /static/css/lib/assets.css + ff:assets:asset-assembler downloadList size: 0 +4ms + ff:assets:asset-assembler readFileList size: 5 +1ms + ff:assets:asset-assembler readFile: node_modules/bootstrap/dist/css/bootstrap.css size: 129940 +4ms + ff:assets:asset-assembler readFile: www_static/css/boot.css size: 1824 +1ms + ff:assets:asset-assembler readFile: www_static/css/flot.css size: 94 +0ms + ff:assets:asset-assembler readFile: www_static/css/panel.css size: 605 +1ms + ff:assets:asset-assembler readFile: www_static/css/style.css size: 448 +0ms + ff:assets:asset-assembler target file: www_static/css/lib/assets.css +0ms + ff:assets:asset-assembler target size: 133244 +0ms + node-ff-assets:css build result size: 1 from: 5 + node-ff-assets:css build done in: 10 ms. + ff:assets:assets-builder assemblerCreate from default +1ms + ff:assets:assets-builder assemblerFill from default +0ms + ff:assets:assets-builder runAssembler type: js +0ms + node-ff-assets:js build begin for: /static/js/lib/assets.js + ff:assets:asset-assembler downloadList size: 5 +1ms + ff:assets:asset-assembler readFileList size: 13 +0ms + ff:assets:asset-assembler downloadFile: http://code.jquery.com/jquery-2.1.3.js +0ms + ff:assets:asset-assembler downloadFile: https://code.angularjs.org/1.4.0-beta.4/angular.js +90ms + ff:assets:asset-assembler downloadFile: https://code.angularjs.org/1.4.0-beta.4/angular-route.js +2s + ff:assets:asset-assembler downloadFile: https://code.angularjs.org/1.4.0-beta.4/angular-resource.js +579ms + ff:assets:asset-assembler downloadFile: https://code.angularjs.org/1.4.0-beta.4/angular-touch.js +567ms + ff:assets:asset-assembler readFile: www_static/js/lib/jquery-2.1.3/jquery.js size: 151917 +593ms + ff:assets:asset-assembler readFile: node_modules/bootstrap/dist/js/bootstrap.js size: 49199 +4ms + ff:assets:asset-assembler readFile: node_modules/flot/jquery.flot.js size: 54509 +7ms + ff:assets:asset-assembler readFile: node_modules/flot/jquery.flot.resize.js size: 1439 +1ms + ff:assets:asset-assembler readFile: node_modules/flot/jquery.flot.pie.js size: 13451 +2ms + ff:assets:asset-assembler readFile: www_static/js/lib/angularjs-1.4.0-b4/angular.js size: 297085 +61ms + ff:assets:asset-assembler readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-route.js size: 8360 +5ms + ff:assets:asset-assembler readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-resource.js size: 6847 +1ms + ff:assets:asset-assembler readFile: www_static/js/lib/angularjs-1.4.0-b4/angular-touch.js size: 7568 +2ms + ff:assets:asset-assembler readFile: www_static/js/example-app.js size: 401 +0ms + ff:assets:asset-assembler readFile: www_static/js/controller/page-bar.js size: 205 +0ms + ff:assets:asset-assembler readFile: www_static/js/controller/page-foo.js size: 205 +0ms + ff:assets:asset-assembler readFile: www_static/js/controller/page-index.js size: 207 +1ms + ff:assets:asset-assembler target file: www_static/js/lib/assets.js +0ms + ff:assets:asset-assembler target size: 592332 +0ms + node-ff-assets:js build result size: 1 from: 13 + node-ff-assets:js build done in: 3502 ms. + Server assets done. + Server config done. + Server started on port 8080 + ## Tests @@ -413,6 +377,11 @@ Add unit tests for any new or changed functionality. Lint and test your code. ## Release History +### 0.2.5 +* Switched debug logging to debug library. +* Removed events from AssetsBuilder. +* Removed logLevel from log event in AssetAssembler. + ### 0.2.4 * Added json config reader. * Added readFileRegex data filter. diff --git a/lib/asset-assembler.js b/lib/asset-assembler.js index 118729c..29a39ab 100644 --- a/lib/asset-assembler.js +++ b/lib/asset-assembler.js @@ -1,5 +1,6 @@ 'use strict'; +var debug = require('debug')('ff:assets:asset-assembler'); var u = require('underscore'); var events = require('events'); var fetch = require('fetch'); @@ -26,10 +27,10 @@ function buildEnd(assembler, targetFile, resultUriList, callback) { resultUriList = [assembler.config.linkTarget]; } assembler.emit('file-write-post',targetFile); - assembler.emit('log','debug','target file: '+targetFile); - assembler.emit('log','debug','target size: '+targetSize); - assembler.emit('log','info','build result size: '+resultUriList.length+' from: '+buildResultSize); - assembler.emit('log','info','build done in: '+buildTime+' ms.'); + debug('target file: %s',targetFile); + debug('target size: %s',targetSize); + assembler.emit('log','build result size: '+resultUriList.length+' from: '+buildResultSize); + assembler.emit('log','build done in: '+buildTime+' ms.'); assembler.emit('result',resultUriList); assembler.emit('end'); callback(); @@ -40,7 +41,7 @@ function buildEnd(assembler, targetFile, resultUriList, callback) { function downloadFile(assembler, remoteUrl, localFile, callback) { assembler.emit('file-download-pre',remoteUrl); - assembler.emit('log','debug','downloadFile: '+remoteUrl); + debug('downloadFile: %s',remoteUrl); fs.ensureFile(localFile, function(err) { if (err) { callback(err); @@ -101,7 +102,7 @@ function aggregateFileList(assembler, targetFile, aggregateList, readFile, callb callback(err); } else { assembler.emit('file-read-post',aggregateFile); - assembler.emit('log','debug','readFile: '+aggregateFile+' size: '+data.length); + debug('readFile: '+aggregateFile+' size: '+data.length); if (assembler.config.assetSeperator !== null && assembler.config.assetSeperator.length > 0) { var seperatorTemplate = u.template(assembler.config.assetSeperator); data = seperatorTemplate({file: aggregateFile}) + data; @@ -175,8 +176,8 @@ function buildAsset(assembler, targetFile, readFile, callback) { downloadList.reverse(); readFileList.reverse(); - assembler.emit('log','debug','downloadList size: '+downloadList.length); - assembler.emit('log','debug','readFileList size: '+readFileList.length); + debug('downloadList size: %s',downloadList.length); + debug('readFileList size: %s',readFileList.length); downloadFileList(assembler, downloadList, function(err) { if (err) { @@ -201,9 +202,9 @@ function buildAsset(assembler, targetFile, readFile, callback) { function buildStart(assembler, readFile, callback) { assembler.startTime = new Date().getTime(); assembler.emit('begin'); - assembler.emit('log','info','build begin for: '+assembler.config.linkTarget); + assembler.emit('log','build begin for: '+assembler.config.linkTarget); if (assembler.config.downloadForce) { - assembler.emit('log','info','build using forced downloads.'); + assembler.emit('log','build using forced downloads.'); } var targetFile = mapLocalFileSync(assembler, assembler.config.linkTarget); fs.ensureFile(targetFile, function (err) { diff --git a/lib/assets-builder.js b/lib/assets-builder.js index 392fa3f..84b7eaa 100644 --- a/lib/assets-builder.js +++ b/lib/assets-builder.js @@ -1,17 +1,20 @@ 'use strict'; -var events = require('events'); +var debug = require('debug')('ff:assets:assets-builder'); var async = require('async'); var config = require('./assets-builder-config'); function buildStepAssemblerRun(builder, buildConfig, assembler, callback) { - builder.emit('log','debug','runAssembler '+assembler.config.assetType); + debug('runAssembler type: %s',assembler.config.assetType); assembler.run(callback); } function buildStepAssemblerFill(builder, buildConfig, assembler, callback) { - var assemblerFill = buildConfig.assemblerFill || builder.config.assemblerFill; - builder.emit('log','debug','assemblerFill: '+Object.keys(assemblerFill)); + var assemblerFill = buildConfig.assemblerFill; + if (assemblerFill === undefined) { + assemblerFill = builder.config.assemblerFill; + debug('assemblerFill from default'); + } assemblerFill(assembler, function(err) { if (err) { callback(err); @@ -22,8 +25,11 @@ function buildStepAssemblerFill(builder, buildConfig, assembler, callback) { } function buildStepAssemblerCreate(builder, buildConfig, assemblerConfig, callback) { - var assemblerCreate = buildConfig.assemblerCreate || builder.config.assemblerCreate; - builder.emit('log','debug','assemblerCreate: '+Object.keys(assemblerCreate)); + var assemblerCreate = buildConfig.assemblerCreate; + if (assemblerCreate === undefined) { + assemblerCreate = builder.config.assemblerCreate; + debug('assemblerCreate from default'); + } assemblerCreate(assemblerConfig, function(err, assembler) { if (err) { callback(err); @@ -34,12 +40,14 @@ function buildStepAssemblerCreate(builder, buildConfig, assemblerConfig, callbac } function buildStepConfigFill(builder, buildConfig, assemblerConfig, callback) { - var configFill = buildConfig.configFill || builder.config.configFill; - + var configFill = buildConfig.configFill; + if (configFill === undefined) { + configFill = builder.config.configFill; + debug('configFill from default'); + } if (assemblerConfig.assetType === undefined) { assemblerConfig.assetType = builder.currentAssetType; } - builder.emit('log','debug','configFill: '+Object.keys(configFill)); configFill(assemblerConfig, function(err) { if (err) { callback(err); @@ -50,8 +58,11 @@ function buildStepConfigFill(builder, buildConfig, assemblerConfig, callback) { } function buildStepConfigCreate(builder, buildConfig, callback) { - var configCreate = buildConfig.configCreate || builder.config.configCreate; - builder.emit('log','debug','configCreate: '+Object.keys(configCreate)); + var configCreate = buildConfig.configCreate; + if (configCreate === undefined) { + configCreate = builder.config.configCreate; + debug('configCreate from default'); + } configCreate(function(err, assemblerConfig) { if (err) { callback(err); @@ -68,14 +79,11 @@ function AssetsBuilder(config) { this.config = config; this.startTime = 0; this.currentAssetType = ''; - events.EventEmitter.call(this); } -AssetsBuilder.prototype.__proto__ = events.EventEmitter.prototype; - AssetsBuilder.prototype.runAll = function(callback) { var self = this; - self.emit('log','debug','runAll started.'); + debug('runAll started.'); config.checkConfig(self.config,function(err) { if (err) { callback(err); @@ -101,7 +109,7 @@ AssetsBuilder.prototype.runAsset = function(name) { if (name === undefined) { throw new Error('no name'); } - self.emit('log','debug','runAsset started for: '+name); + debug('runAsset started for: %s',name); return function(callback) { if (callback === undefined) { throw new Error('no callback'); diff --git a/lib/factory.js b/lib/factory.js index 2ec7fd4..1b6f9a5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -69,8 +69,8 @@ var assemblerEventLog = { if (logType === undefined) { throw new Error('no logType'); } - return function(logLevel, logMessage) { - console.log(logLevel + ': node-ff-assets-' + logType + ' ' + logMessage); + return function(logMessage) { + console.log('node-ff-assets:' + logType + ' ' + logMessage); }; }, winston: function(logger, logType) { @@ -80,8 +80,8 @@ var assemblerEventLog = { if (logType === undefined) { throw new Error('no logType'); } - return function(logLevel, logMessage) { - logger.log(logLevel, 'node-ff-assets-'+logType+' '+logMessage); + return function(logMessage) { + logger.log('node-ff-assets:'+logType+' '+logMessage); }; }, }; diff --git a/package.json b/package.json index 721c22c..6601541 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,12 @@ { "name": "node-ff-assets", - "version": "0.2.4", + "version": "0.2.5", "description": "Site assets local/remote aggregation with minify.", "main": "lib/node-ff-assets.js", "scripts": { "test": "npm run-script test-clean;npm run-script test-mocha", "test-clean": "rm test/data/* -rf", "test-mocha": "export JUNIT_REPORT_PATH=test/data/report.xml;export JUNIT_REPORT_STACK=1;node_modules/mocha/bin/mocha --reporter mocha-jenkins-reporter" - }, "author": "Willem (http://forwardfire.net/)", "license": "BSD-2-Clause", @@ -16,6 +15,7 @@ "url": "https://bitbucket.org/im_ik/node-ff-assets.git" }, "dependencies": { + "debug": "^2.2.0", "fetch": "^0.3.6", "fs-extra": "^0.16.3", "minify": "^1.4.8", diff --git a/test/test-asset-assembler.js b/test/test-asset-assembler.js index 6d4063e..a994426 100644 --- a/test/test-asset-assembler.js +++ b/test/test-asset-assembler.js @@ -14,9 +14,8 @@ function createTestAssembler(suite, readFile) { '/static-test/input1.css', ], },readFile); - assetAssembler.on ('log',function (logLevel, logMessage) { - var level = (logLevel+' ').substring(0,6); - console.log(' '+ level + ' ' + suite.title + ' ' +logMessage); + assetAssembler.on ('log',function (logMessage) { + console.log(' ' + ' ' + suite.title + ' ' +logMessage); }); return assetAssembler; } diff --git a/test/test-assets-builder.js b/test/test-assets-builder.js index aa4d081..8a55b5d 100644 --- a/test/test-assets-builder.js +++ b/test/test-assets-builder.js @@ -33,9 +33,8 @@ function createTestBuilder(suite) { var testConfig = { assemblerFill: function (assembler, callback) { var serverResultKey = 'ff_assets_'+assembler.config.assetType; - assembler.on ('log',function (logLevel, logMessage) { - var level = (logLevel+' ').substring(0,6); - console.log(' '+ level + ' ' + suite.title + ' assembler ' +logMessage); // == -2 space from asm + assembler.on ('log',function (logMessage) { + console.log(' ' + ' ' + suite.title + ' assembler ' +logMessage); // == -2 space from asm }); callback(); }, @@ -48,12 +47,7 @@ function createTestBuilder(suite) { } } }; - var assetsBuilder = new assets.AssetsBuilder(testConfig); - assetsBuilder.on ('log',function (logLevel, logMessage) { - var level = (logLevel+' ').substring(0,6); - console.log(' '+ level + ' ' + suite.title + ' builder ' +logMessage); // == -1 space from asm - }); - return assetsBuilder; + return new assets.AssetsBuilder(testConfig); } describe('lib/assets-builder.js', function() {