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
var nuxt = new Nuxt(options)
nuxt.build()
.then(() => {
console.log('[nuxt] Building done') // eslint-disable-line no-console
})
.catch((err) => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
new Nuxt(options).then(nuxt => {
nuxt.build()
.then(() => {
console.log('[nuxt] Building done') // eslint-disable-line no-console
})
.catch((err) => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})
})

View File

@ -39,15 +39,16 @@ if (typeof options.rootDir !== 'string') {
}
options.dev = true // Add hot reloading and watching changes
var nuxt = new Nuxt(options)
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)
listenOnConfigChanges(nuxt, server)
new Nuxt(options).then(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)
listenOnConfigChanges(nuxt, server)
nuxt.build()
.catch((err) => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
nuxt.build()
.catch((err) => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})
})
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)
console.log('[nuxt] Generating...') // eslint-disable-line no-console
var nuxt = new Nuxt(options)
nuxt.generate()
.then(() => {
console.log('[nuxt] Generate done') // eslint-disable-line no-console
})
.catch((err) => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
new Nuxt(options).then(nuxt => {
nuxt.generate()
.then(() => {
console.log('[nuxt] Generate done') // eslint-disable-line no-console
})
.catch((err) => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})
})

View File

@ -16,10 +16,10 @@ if (typeof options.rootDir !== 'string') {
}
options.dev = false // Force production mode (no webpack middleware called)
var nuxt = new Nuxt(options)
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
)
new Nuxt(options).then(nuxt => {
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
)
})

View File

@ -114,7 +114,14 @@ class Nuxt {
this.utils = utils
// Add module integration
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) {

View File

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