Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions app/Commands/NuxtBuild.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/Controllers/Http/NuxtController.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const NuxtService = use('App/Services/Nuxt')

class NuxtController {
async render ({ request, response, session }) {
const NuxtService = await use('Nuxt')

/**
* Do not end the response when this method has been executed.
* Nuxt will write the response in background and will close
Expand Down
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@
"private": true,
"main": "server.js",
"scripts": {
"serve:dev": "npm run dev",
"dev": "nodemon --watch app --watch bootstrap --watch config --watch .env -x node server.js",
"build": "node ./ace nuxtbuild",
"dev": "cross-env NODE_ENV=development adonis serve --dev",
"build": "nuxt build -c config/nuxt.js",
"start": "cross-env NODE_ENV=production node server.js",
"precommit": "npm run lint",
"lint": "standard && eslint --ext .js,.vue resources/"
},
"dependencies": {
"@adonisjs/ace": "^4.0.7",
"@adonisjs/auth": "^2.0.10",
"@adonisjs/bodyparser": "^1.0.8",
"@adonisjs/cors": "^1.0.2",
"@adonisjs/fold": "^4.0.5",
"@adonisjs/framework": "^4.0.27",
"@adonisjs/ignitor": "^1.0.14",
"@adonisjs/lucid": "^4.0.22",
"@adonisjs/session": "^1.0.19",
"@adonisjs/shield": "^1.0.4",
"@adonisjs/ace": "^5.0.0",
"@adonisjs/auth": "^3.0.1",
"@adonisjs/bodyparser": "^2.0.2",
"@adonisjs/cors": "^1.0.5",
"@adonisjs/fold": "^4.0.7",
"@adonisjs/framework": "^5.0.4",
"@adonisjs/ignitor": "^2.0.5",
"@adonisjs/lucid": "^5.0.2",
"@adonisjs/session": "^1.0.20",
"@adonisjs/shield": "^1.0.6",
"cross-env": "^3.1.4",
"nuxt": "latest",
"standard": "^8.6.0",
Expand All @@ -46,7 +45,6 @@
"eslint-plugin-html": "^2.0.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"nodemon": "^1.11.0",
"standard": "^8.6.0"
}
}
26 changes: 16 additions & 10 deletions app/Services/Nuxt.js → providers/Nuxt/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict'

const Env = use('Env')
const Config = use('Config')
const { Nuxt, Builder } = require('nuxt')
const Logger = use('Logger')

class NuxtService {
constructor () {
constructor (Config, Env) {
this.Config = Config
this.Env = Env
this.nuxt = null
}

Expand All @@ -14,12 +15,18 @@ class NuxtService {
*
* @method boot
*
* @return {void}
* @return {Promise}
*/
build (dev = Env.get('NODE_ENV') === 'development') {
const config = Config.merge('nuxt', { dev })
this.nuxt = new Nuxt(config)
return new Builder(this.nuxt).build()
build (dev = this.Env.get('NODE_ENV') === 'development') {
const config = this.Config.merge('nuxt', { dev })
return new Promise(async (resolve, reject) => {
this.nuxt = await new Nuxt(config)
if (dev) {
await new Builder(this.nuxt).build()
}
Logger.info('Nuxt is ready to handle requests')
resolve(this)
})
}

/**
Expand All @@ -41,5 +48,4 @@ class NuxtService {
})
}
}

module.exports = new NuxtService()
module.exports = NuxtService
29 changes: 29 additions & 0 deletions providers/Nuxt/provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

const { ServiceProvider } = require('@adonisjs/fold')

class NuxtProvider extends ServiceProvider {
register () {
this.app.singleton('Adonuxt/Nuxt', () => {
const Config = this.app.use('Adonis/Src/Config')
const Env = this.app.use('Adonis/Src/Env')
const dev = Env.get('NODE_ENV') === 'development'
const instance = new (require('.'))(Config, Env)
if (!dev) {
return instance
}
return instance.build()
})
}

boot () {
const Env = this.app.use('Adonis/Src/Env')
const dev = Env.get('NODE_ENV') === 'development'
if (!dev) {
const instance = this.app.use('Adonuxt/Nuxt')
instance.build()
}
}
}

module.exports = NuxtProvider
6 changes: 0 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,4 @@ const { Ignitor } = require('@adonisjs/ignitor')
new Ignitor(require('@adonisjs/fold'))
.appRoot(__dirname)
.fireHttpServer()
.then(() => {
return use('App/Services/Nuxt').build()
})
.then(() => {
use('Logger').info('Nuxt is ready to handle requests')
})
.catch(console.error)
13 changes: 8 additions & 5 deletions start/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const path = require('path')

/*
|--------------------------------------------------------------------------
| Providers
Expand All @@ -18,7 +20,8 @@ const providers = [
'@adonisjs/cors/providers/CorsProvider',
'@adonisjs/shield/providers/ShieldProvider',
'@adonisjs/session/providers/SessionProvider',
'@adonisjs/auth/providers/AuthProvider'
'@adonisjs/auth/providers/AuthProvider',
path.join(__dirname, '..', 'providers', 'Nuxt/provider')
]

/*
Expand Down Expand Up @@ -46,7 +49,9 @@ const aceProviders = [
| { Route: 'Adonis/Src/Route' }
|
*/
const aliases = {}
const aliases = {
Nuxt: 'Adonuxt/Nuxt'
}

/*
|--------------------------------------------------------------------------
Expand All @@ -56,8 +61,6 @@ const aliases = {}
| Here you store ace commands for your package
|
*/
const commands = [
'App/Commands/NuxtBuild'
]
const commands = []

module.exports = { providers, aceProviders, aliases, commands }