From 10d18bc454d162e904eef34a2424336f9f94722d Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Tue, 25 Apr 2017 15:00:42 +0200 Subject: [PATCH] Add generate.interval --- lib/generate.js | 22 ++++------------------ test/fixtures/basic/nuxt.config.js | 2 +- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/lib/generate.js b/lib/generate.js index 09577631ee..a080e89509 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -5,7 +5,7 @@ import co from 'co' import pify from 'pify' import _ from 'lodash' import { resolve, join, dirname, sep } from 'path' -import { isUrl, promisifyRoute } from './utils' +import { isUrl, promisifyRoute, waitFor } from './utils' import { minify } from 'html-minifier' const debug = require('debug')('nuxt:generate') const copy = pify(fs.copy) @@ -16,6 +16,7 @@ const mkdirp = pify(fs.mkdirp) const defaults = { dir: 'dist', routes: [], + interval: 0, minify: { collapseBooleanAttributes: true, collapseWhitespace: true, @@ -89,28 +90,13 @@ export default function () { this.routes.push(route) } }) - var n = 0 - function timer () { - let promise = new Promise( - (resolve, reject) => { - setTimeout( () => { - resolve() - }, self.options.generate.wait * n) - } - ) - n++ - return promise - - } - let routes = this.routes return co(function * () { while (routes.length) { + let n = 0 yield routes.splice(0, 500).map((route) => { return co(function * () { - if(self.options.generate.wait) { - yield timer() - } + yield waitFor(n++ * self.options.generate.interval) var { html } = yield self.renderRoute(route, { _generate: true }) html = minify(html, self.options.generate.minify) var path = join(route, sep, 'index.html') // /about -> /about/index.html diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixtures/basic/nuxt.config.js index daf0f9f260..d6ba223b68 100644 --- a/test/fixtures/basic/nuxt.config.js +++ b/test/fixtures/basic/nuxt.config.js @@ -5,6 +5,6 @@ module.exports = { '/users/2', '/users/3' ], - wait : 1000 + interval: 200 } }