mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
Makes generate asynchronous
This commit is contained in:
parent
93e3fe800d
commit
6a6b978cd1
@ -86,31 +86,32 @@ export default async function () {
|
||||
this.routes.push(route)
|
||||
}
|
||||
})
|
||||
let n = 0
|
||||
for (let route of this.routes) {
|
||||
await waitFor(n++ * self.options.generate.interval)
|
||||
try {
|
||||
var { html, error } = await self.renderRoute(route, { _generate: true })
|
||||
if (error) {
|
||||
errors.push({ type: 'handled', route, error })
|
||||
let routes = this.routes
|
||||
while (routes.length) {
|
||||
let n = 0
|
||||
await Promise.all(routes.splice(0, 500).map(async (route) => {
|
||||
await waitFor(n++ * self.options.generate.interval)
|
||||
try {
|
||||
var { html, error } = await self.renderRoute(route, { _generate: true })
|
||||
if (error) {
|
||||
errors.push({ type: 'handled', route, error })
|
||||
}
|
||||
} catch (err) {
|
||||
errors.push({ type: 'unhandled', route, error: err })
|
||||
}
|
||||
} catch (err) {
|
||||
errors.push({ type: 'unhandled', route, error: err })
|
||||
continue
|
||||
}
|
||||
try {
|
||||
var minifiedHtml = minify(html, self.options.generate.minify)
|
||||
} catch (err) {
|
||||
let minifyErr = new Error(`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`)
|
||||
errors.push({ type: 'unhandled', route, error: minifyErr })
|
||||
continue
|
||||
}
|
||||
var path = join(route, sep, 'index.html') // /about -> /about/index.html
|
||||
debug('Generate file: ' + path)
|
||||
path = join(distPath, path)
|
||||
// Make sure the sub folders are created
|
||||
await mkdirp(dirname(path))
|
||||
await writeFile(path, minifiedHtml, 'utf8')
|
||||
try {
|
||||
var minifiedHtml = minify(html, self.options.generate.minify)
|
||||
} catch (err) {
|
||||
let minifyErr = new Error(`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`)
|
||||
errors.push({ type: 'unhandled', route, error: minifyErr })
|
||||
}
|
||||
var path = join(route, sep, 'index.html') // /about -> /about/index.html
|
||||
debug('Generate file: ' + path)
|
||||
path = join(distPath, path)
|
||||
// Make sure the sub folders are created
|
||||
await mkdirp(dirname(path))
|
||||
await writeFile(path, minifiedHtml, 'utf8')
|
||||
}))
|
||||
}
|
||||
// Add .nojekyll file to let Github Pages add the _nuxt/ folder
|
||||
// https://help.github.com/articles/files-that-start-with-an-underscore-are-missing/
|
||||
|
@ -21,7 +21,7 @@ export function setAnsiColors (ansiHTML) {
|
||||
})
|
||||
}
|
||||
|
||||
export function * waitFor (ms) {
|
||||
export async function waitFor (ms) {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(resolve, (ms || 0))
|
||||
})
|
||||
|
@ -28,9 +28,9 @@ test('setAnsiColors', t => {
|
||||
t.pass()
|
||||
})
|
||||
|
||||
test('waitFor', function * (t) {
|
||||
test('waitFor', async (t) => {
|
||||
let s = Date.now()
|
||||
yield utils.waitFor(100)
|
||||
await utils.waitFor(100)
|
||||
t.true(Date.now() - s >= 100)
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user