diff --git a/lib/box/index.js b/lib/box/index.js index 9517850ecb..5abb808557 100644 --- a/lib/box/index.js +++ b/lib/box/index.js @@ -4,7 +4,6 @@ var _ = require('lodash'); var File = require('./file'); var util = require('hexo-util'); var fs = require('hexo-fs'); -var prettyHrtime = require('pretty-hrtime'); var crypto = require('crypto'); var chalk = require('chalk'); @@ -291,7 +290,6 @@ Box.prototype._dispatch = function(item){ var self = this; var ctx = this.context; var base = this.base; - var start = process.hrtime(); // Skip processing files if (this.processingFiles[path]) return; @@ -317,8 +315,7 @@ Box.prototype._dispatch = function(item){ return Promise.method(processor.process).call(ctx, file).thenReturn(count + 1); }, 0).then(function(count){ if (count){ - var interval = prettyHrtime(process.hrtime(start)); - ctx.log.debug('Processed in %s: %s', chalk.cyan(interval), chalk.magenta(path)); + ctx.log.debug('Processed: %s', chalk.magenta(path)); } }, function(err){ ctx.log.error({err: err}, 'Process failed: %s', chalk.magenta(path)); diff --git a/lib/hexo/index.js b/lib/hexo/index.js index 4dcfc58e73..079ebff3d8 100644 --- a/lib/hexo/index.js +++ b/lib/hexo/index.js @@ -20,7 +20,6 @@ var Router = require('./router'); var Theme = require('../theme'); var defaultConfig = require('./default_config'); var loadDatabase = require('./load_database'); -var prettyHrtime = require('pretty-hrtime'); var libDir = pathFn.dirname(__dirname); var sep = pathFn.sep; @@ -301,20 +300,17 @@ Hexo.prototype._generate = function(options){ // Run generators return Promise.reduce(keys, function(result, key){ var generator = generators[key]; - var start = process.hrtime(); return generator.call(self, siteLocals).then(function(data){ - var interval = prettyHrtime(process.hrtime(start)); + log.debug('Generator: %s', chalk.magenta(key)); - log.debug('Generator in %s: %s', chalk.cyan(interval), chalk.magenta(key)); - - return data ? result.concat(data) : data; + return data ? result.concat(data) : result; }); }, []); }) + // Add routes .each(function(item){ - // Add routes - if (item.path == null) return; + if (typeof item !== 'object' || item.path == null) return; var path = route.format(item.path); var data = item.data; diff --git a/lib/plugins/console/generate.js b/lib/plugins/console/generate.js index 826ff0750b..de27a2b863 100644 --- a/lib/plugins/console/generate.js +++ b/lib/plugins/console/generate.js @@ -15,14 +15,12 @@ function generateConsole(args){ function generateFile(path){ var data = route.get(path); var dest = pathFn.join(publicDir, path); - var start = process.hrtime(); // TODO: Retry when EMFILE error occurred return fs.ensureWriteStream(dest).then(function(stream){ return pipeStream(data, stream); }).then(function(){ - var interval = prettyHrtime(process.hrtime(start)); - log.info('Generated in %s: %s', chalk.cyan(interval), chalk.magenta(path)); + log.info('Generated: %s', chalk.magenta(path)); }); } diff --git a/test/scripts/hexo/hexo.js b/test/scripts/hexo/hexo.js index 0a5b791fed..11074b69ef 100644 --- a/test/scripts/hexo/hexo.js +++ b/test/scripts/hexo/hexo.js @@ -404,6 +404,23 @@ describe('Hexo', function(){ }); }); + it('_generate() - return nothing in generator', function(){ + hexo.extend.generator.register('test_nothing', function(){ + // + }); + + hexo.extend.generator.register('test_normal', function(){ + return { + path: 'bar', + data: 'bar' + }; + }); + + return hexo._generate().then(function(){ + return checkStream(route.get('bar'), 'bar'); + }); + }); + it('_generate() - validate locals'); it('_generate() - do nothing if it\'s generating');