From 2576e8795e328d8d7a10cb4ff7cc23baf4c79009 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 15 Jun 2017 19:29:26 +0430 Subject: [PATCH] init() ~> ready() --- bin/nuxt-build | 2 +- lib/generator.js | 2 +- lib/nuxt.js | 8 ++++---- lib/renderer.js | 12 ++++++------ lib/server.js | 4 ++-- test/basic.dev.test.js | 2 +- test/basic.test.js | 2 +- test/children.test.js | 2 +- test/dynamic-routes.test.js | 2 +- test/error.test.js | 2 +- test/index.test.js | 8 ++++---- test/module.test.js | 2 +- test/with-config.test.js | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bin/nuxt-build b/bin/nuxt-build index 8c4fffd038..0f7b956563 100755 --- a/bin/nuxt-build +++ b/bin/nuxt-build @@ -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 }) diff --git a/lib/generator.js b/lib/generator.js index 3cc54b6d93..e92907d32e 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -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) diff --git a/lib/nuxt.js b/lib/nuxt.js index e6aafdcde9..1a14ffd9d2 100644 --- a/lib/nuxt.js +++ b/lib/nuxt.js @@ -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 diff --git a/lib/renderer.js b/lib/renderer.js index 0aa1729356..c7deae435a 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -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 / diff --git a/lib/server.js b/lib/server.js index f18f2e1706..09bd816c09 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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 diff --git a/test/basic.dev.test.js b/test/basic.dev.test.js index 108bd5c35d..be75b6cac1 100644 --- a/test/basic.dev.test.js +++ b/test/basic.dev.test.js @@ -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') }) diff --git a/test/basic.test.js b/test/basic.test.js index 71372e0636..b29df1ead9 100755 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -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') }) diff --git a/test/children.test.js b/test/children.test.js index 5bae366e0b..01786707c9 100644 --- a/test/children.test.js +++ b/test/children.test.js @@ -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') }) diff --git a/test/dynamic-routes.test.js b/test/dynamic-routes.test.js index ebd1760d44..b2256a9951 100644 --- a/test/dynamic-routes.test.js +++ b/test/dynamic-routes.test.js @@ -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 => { diff --git a/test/error.test.js b/test/error.test.js index ddd3fa4ada..ab361c4d03 100644 --- a/test/error.test.js +++ b/test/error.test.js @@ -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') }) diff --git a/test/index.test.js b/test/index.test.js index 21e09014f3..066578f632 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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')) diff --git a/test/module.test.js b/test/module.test.js index bdb658a82e..eca4d7bfea 100755 --- a/test/module.test.js +++ b/test/module.test.js @@ -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') }) diff --git a/test/with-config.test.js b/test/with-config.test.js index 78668a2688..a7366ea65d 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -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() })