Nuxt.* Components

This commit is contained in:
Pooya Parsa 2017-06-13 00:46:27 +04:30
parent 754fcc2f59
commit a14819ca88

View File

@ -2,15 +2,16 @@ import _ from 'lodash'
import compression from 'compression' import compression from 'compression'
import fs from 'fs-extra' import fs from 'fs-extra'
import pify from 'pify' 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 serveStatic from 'serve-static'
import { resolve, join } from 'path' import { resolve, join } from 'path'
import defaults from './defaults' import * as Utils from './utils'
import Tapable from 'tapable' 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 { export default class Nuxt extends Tapable {
constructor (options = {}) { constructor (options = {}) {
@ -31,30 +32,32 @@ export default class Nuxt extends Tapable {
} }
// Apply defaults // Apply defaults
this.options = _.defaultsDeep(options, defaults) this.options = _.defaultsDeep(options, Nuxt.Defaults)
// Resolve dirs // Resolve dirs
this.options.rootDir = (typeof options.rootDir === 'string' && options.rootDir ? options.rootDir : process.cwd()) 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.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.options.buildDir = join(this.options.rootDir, options.buildDir)
this.Server = Server
this.componentTasks() this.componentTasks()
// Create instance of core components // Create instance of core components
this.builder = new Builder(this) this.builder = new Nuxt.Builder(this)
this.renderer = new Renderer(this) this.renderer = new Nuxt.Renderer(this)
this.generate = new Generate(this) this.generator = new Nuxt.Generator(this)
this.moduleContainer = new ModuleContainer(this) this.moduleContainer = new Nuxt.ModuleContainer(this)
// Backward compatibility // Backward compatibility
this.render = this.renderer.render.bind(this.renderer) this.render = this.renderer.render.bind(this.renderer)
this.renderRoute = this.renderer.renderRoute.bind(this.renderer) this.renderRoute = this.renderer.renderRoute.bind(this.renderer)
this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer) this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer)
this.build = this.ready.bind(this) this.build = this.ready.bind(this)
this.generate = this.generator.generate.bind(this.generator)
this.dir = options.rootDir this.dir = options.rootDir
this.srcDir = options.srcDir this.srcDir = options.srcDir
this.buildDir = options.buildDir this.buildDir = options.buildDir
this.Server = Nuxt.Server
this.Utils = Nuxt.Utils
// Wait for all core components be ready // Wait for all core components be ready
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
@ -99,8 +102,6 @@ export default class Nuxt extends Tapable {
} }
await this.moduleContainer.ready() await this.moduleContainer.ready()
await this.builder.ready() await this.builder.ready()
// eslint-disable-next-line no-console
console.log('[nuxt] ready')
return this 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