Install all modules in sequence before nuxt init

For this functionality Nuxt constructor would return a Promise so all bin commands updated to resolve promise before using nuxt
This commit is contained in:
Pooya Parsa 2017-05-11 15:53:58 +04:30
parent 5039459f06
commit 497d673727
6 changed files with 46 additions and 32 deletions

View File

@ -52,12 +52,13 @@ if (analyzeBuild) {
} }
console.log('[nuxt] Building...') // eslint-disable-line no-console console.log('[nuxt] Building...') // eslint-disable-line no-console
var nuxt = new Nuxt(options) new Nuxt(options).then(nuxt => {
nuxt.build() nuxt.build()
.then(() => { .then(() => {
console.log('[nuxt] Building done') // eslint-disable-line no-console console.log('[nuxt] Building done') // eslint-disable-line no-console
}) })
.catch((err) => { .catch((err) => {
console.error(err) // eslint-disable-line no-console console.error(err) // eslint-disable-line no-console
process.exit(1) process.exit(1)
})
}) })

View File

@ -39,15 +39,16 @@ if (typeof options.rootDir !== 'string') {
} }
options.dev = true // Add hot reloading and watching changes options.dev = true // Add hot reloading and watching changes
var nuxt = new Nuxt(options) new Nuxt(options).then(nuxt => {
var server = new nuxt.Server(nuxt) var server = new nuxt.Server(nuxt)
.listen(process.env.PORT || process.env.npm_package_config_nuxt_port, process.env.HOST || process.env.npm_package_config_nuxt_host) .listen(process.env.PORT || process.env.npm_package_config_nuxt_port, process.env.HOST || process.env.npm_package_config_nuxt_host)
listenOnConfigChanges(nuxt, server) listenOnConfigChanges(nuxt, server)
nuxt.build() nuxt.build()
.catch((err) => { .catch((err) => {
console.error(err) // eslint-disable-line no-console console.error(err) // eslint-disable-line no-console
process.exit(1) process.exit(1)
})
}) })
function listenOnConfigChanges (nuxt, server) { function listenOnConfigChanges (nuxt, server) {

View File

@ -20,12 +20,13 @@ if (typeof options.rootDir !== 'string') {
options.dev = false // Force production mode (no webpack middleware called) options.dev = false // Force production mode (no webpack middleware called)
console.log('[nuxt] Generating...') // eslint-disable-line no-console console.log('[nuxt] Generating...') // eslint-disable-line no-console
var nuxt = new Nuxt(options) new Nuxt(options).then(nuxt => {
nuxt.generate() nuxt.generate()
.then(() => { .then(() => {
console.log('[nuxt] Generate done') // eslint-disable-line no-console console.log('[nuxt] Generate done') // eslint-disable-line no-console
}) })
.catch((err) => { .catch((err) => {
console.error(err) // eslint-disable-line no-console console.error(err) // eslint-disable-line no-console
process.exit(1) process.exit(1)
})
}) })

View File

@ -16,10 +16,10 @@ if (typeof options.rootDir !== 'string') {
} }
options.dev = false // Force production mode (no webpack middleware called) options.dev = false // Force production mode (no webpack middleware called)
var nuxt = new Nuxt(options) new Nuxt(options).then(nuxt => {
new nuxt.Server(nuxt)
new nuxt.Server(nuxt) .listen(
.listen( process.env.PORT || process.env.npm_package_config_nuxt_port,
process.env.PORT || process.env.npm_package_config_nuxt_port, process.env.HOST || process.env.npm_package_config_nuxt_host
process.env.HOST || process.env.npm_package_config_nuxt_host )
) })

View File

@ -114,7 +114,14 @@ class Nuxt {
this.utils = utils this.utils = utils
// Add module integration // Add module integration
this.module = new Module(this) this.module = new Module(this)
return this // Install all modules in sequence and then return `this` instance
return utils.sequence(options.modules, this.module.installModule.bind(this.module))
.then(() => this)
.catch((err) => {
console.error('[nuxt] error while initializing modules') // eslint-disable-line no-console
console.error(err) // eslint-disable-line no-console
process.exit(1)
})
} }
close (callback) { close (callback) {

View File

@ -57,3 +57,7 @@ export function promisifyRoute (fn) {
} }
return promise return promise
} }
export function sequence (tasks, fn) {
return tasks.reduce((promise, task) => promise.then(() => fn(task)), Promise.resolve())
}