From a14819ca88f7e496b8812276a66b8eab09b287a8 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 13 Jun 2017 00:46:27 +0430 Subject: [PATCH] Nuxt.* Components --- lib/nuxt.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/nuxt.js b/lib/nuxt.js index c8cd78b7a4..bd826df691 100644 --- a/lib/nuxt.js +++ b/lib/nuxt.js @@ -2,15 +2,16 @@ import _ from 'lodash' import compression from 'compression' import fs from 'fs-extra' import pify from 'pify' -import Server from './server' -import ModuleContainer from './module-container' -import Builder from './builder' -import Renderer from './renderer' -import Generate from './generate' import serveStatic from 'serve-static' import { resolve, join } from 'path' -import defaults from './defaults' +import * as Utils from './utils' import Tapable from 'tapable' +import Builder from './builder' +import Renderer from './renderer' +import Generator from './generator' +import ModuleContainer from './module-container' +import Server from './server' +import Defaults from './defaults' export default class Nuxt extends Tapable { constructor (options = {}) { @@ -31,30 +32,32 @@ export default class Nuxt extends Tapable { } // Apply defaults - this.options = _.defaultsDeep(options, defaults) + this.options = _.defaultsDeep(options, Nuxt.Defaults) // Resolve dirs this.options.rootDir = (typeof options.rootDir === 'string' && options.rootDir ? options.rootDir : process.cwd()) this.options.srcDir = (typeof options.srcDir === 'string' && options.srcDir ? resolve(options.rootDir, options.srcDir) : this.options.rootDir) this.options.buildDir = join(this.options.rootDir, options.buildDir) - this.Server = Server this.componentTasks() // Create instance of core components - this.builder = new Builder(this) - this.renderer = new Renderer(this) - this.generate = new Generate(this) - this.moduleContainer = new ModuleContainer(this) + this.builder = new Nuxt.Builder(this) + this.renderer = new Nuxt.Renderer(this) + this.generator = new Nuxt.Generator(this) + this.moduleContainer = new Nuxt.ModuleContainer(this) // Backward compatibility this.render = this.renderer.render.bind(this.renderer) this.renderRoute = this.renderer.renderRoute.bind(this.renderer) this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer) this.build = this.ready.bind(this) + this.generate = this.generator.generate.bind(this.generator) this.dir = options.rootDir this.srcDir = options.srcDir this.buildDir = options.buildDir + this.Server = Nuxt.Server + this.Utils = Nuxt.Utils // Wait for all core components be ready // eslint-disable-next-line no-console @@ -99,8 +102,6 @@ export default class Nuxt extends Tapable { } await this.moduleContainer.ready() await this.builder.ready() - // eslint-disable-next-line no-console - console.log('[nuxt] ready') return this } @@ -133,3 +134,12 @@ export default class Nuxt extends Tapable { }) } } + +// Add core components to Nuxt class +Nuxt.Defaults = Defaults +Nuxt.Utils = Utils +Nuxt.Renderer = Renderer +Nuxt.Builder = Builder +Nuxt.ModuleContainer = ModuleContainer +Nuxt.Server = Server +Nuxt.Generator = Generator