init() ~> ready()

This commit is contained in:
Pooya Parsa 2017-06-15 19:29:26 +04:30
parent d882b1ac77
commit 2576e8795e
13 changed files with 26 additions and 26 deletions

View File

@ -61,7 +61,7 @@ if (argv.analyze) {
console.log('[nuxt] Building...') // eslint-disable-line no-console
var nuxt = module.exports = new Nuxt(options)
nuxt.init()
nuxt.ready()
.then(() => {
console.log('[nuxt] Building done') // eslint-disable-line no-console
})

View File

@ -31,7 +31,7 @@ export default class Generator extends Tapable {
let distNuxtPath = join(distPath, (isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath))
// Wait for nuxt be ready
await this.nuxt.init()
await this.nuxt.ready()
// Clean destination folder
await remove(distPath)

View File

@ -36,12 +36,12 @@ export default class Nuxt extends Tapable {
}
})
this._init = this.init().catch(this.errorHandler)
this._ready = this.ready().catch(this.errorHandler)
}
async init () {
if (this._init) {
return this._init
async ready () {
if (this._ready) {
return this._ready
}
// Wait for all components to be ready

View File

@ -41,19 +41,19 @@ export default class Renderer extends Tapable {
if (nuxt.initialized) {
// If nuxt already initialized
this._init = this.init().catch(this.nuxt.errorHandler)
this._ready = this.ready().catch(this.nuxt.errorHandler)
} else {
// Wait for hook
this.nuxt.plugin('afterInit', () => {
this._init = this.init()
return this._init
this._ready = this.ready()
return this._ready
})
}
}
async init () {
if (this._init) {
return this._init
async ready () {
if (this._ready) {
return this._ready
}
// For serving static/ files to /

View File

@ -10,7 +10,7 @@ class Server {
// Initialize
this.app = connect()
this.server = http.createServer(this.app)
this.nuxt.init()
this.nuxt.ready()
.then(() => {
// Add Middleware
this.options.serverMiddleware.forEach(m => {
@ -48,7 +48,7 @@ class Server {
listen (port, host) {
host = host || 'localhost'
port = port || 3000
this.nuxt.init()
this.nuxt.ready()
.then(() => {
this.server.listen(port, host, () => {
let _host = host === '0.0.0.0' ? 'localhost' : host

View File

@ -15,7 +15,7 @@ test.before('Init Nuxt.js', async t => {
dev: true
}
nuxt = new Nuxt(options)
await nuxt.init()
await nuxt.ready()
server = new Nuxt.Server(nuxt)
server.listen(port, 'localhost')
})

View File

@ -18,7 +18,7 @@ test.before('Init Nuxt.js', async t => {
runBuild: true
}
nuxt = new Nuxt(options)
await nuxt.init()
await nuxt.ready()
server = new Nuxt.Server(nuxt)
server.listen(port, 'localhost')
})

View File

@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => {
runBuild: true
}
nuxt = new Nuxt(options)
await nuxt.init()
await nuxt.ready()
server = new Nuxt.Server(nuxt)
server.listen(port, 'localhost')
})

View File

@ -12,7 +12,7 @@ test.before('Init Nuxt.js', async t => {
dev: false,
runBuild: true
})
await nuxt.init()
await nuxt.ready()
})
test('Check .nuxt/router.js', t => {

View File

@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => {
runBuild: true
}
nuxt = new Nuxt(options)
await nuxt.init()
await nuxt.ready()
server = new Nuxt.Server(nuxt)
server.listen(port, 'localhost')
})

View File

@ -15,8 +15,8 @@ test.serial('Nuxt.js Instance', async t => {
t.is(nuxt.options.dev, true)
t.is(typeof nuxt.generate, 'function')
t.is(typeof nuxt._init.then, 'function')
await nuxt.init()
t.is(nuxt.initialized, true)
await nuxt.ready()
t.is(nuxt.readyialized, true)
})
test.serial('Fail to build when no pages/ directory but is in the parent', t => {
@ -25,7 +25,7 @@ test.serial('Fail to build when no pages/ directory but is in the parent', t =>
runBuild: true,
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
})
return nuxt.init().catch(err => {
return nuxt.ready().catch(err => {
let s = String(err)
t.true(s.includes('No `pages` directory found'))
t.true(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?'))
@ -38,7 +38,7 @@ test.serial('Fail to build when no pages/ directory', t => {
runBuild: true,
rootDir: resolve(__dirname)
})
return nuxt.init().catch(err => {
return nuxt.ready().catch(err => {
let s = String(err)
t.true(s.includes('Couldn\'t find a `pages` directory'))
t.true(s.includes('Please create one under the project root'))

View File

@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
config.dev = false
config.runBuild = true
nuxt = new Nuxt(config)
await nuxt.init()
await nuxt.ready()
server = new Nuxt.Server(nuxt)
server.listen(port, 'localhost')
})

View File

@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
config.dev = false
config.runBuild = true
nuxt = new Nuxt(config)
await nuxt.init()
await nuxt.ready()
server = new Nuxt.Server(nuxt)
server.listen(port, 'localhost')
})
@ -113,5 +113,5 @@ test.after('Should be able to start Nuxt with build done', async t => {
config.dev = false
config.runBuild = true
nuxt = new Nuxt(config)
await nuxt.init()
await nuxt.ready()
})