Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

feat(ignitor): add loadOnlyOnHttp file list #16

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Ignitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Ignitor {
this._appRoot = null
this._modulesRoot = null
this._loadCommands = false
this.environment = null

/**
* Files to be preloaded
Expand All @@ -58,8 +59,16 @@ class Ignitor {
this._preLoadFiles = [
'start/routes',
'start/events',
'start/kernel'
]

/**
* Files to be preloaded only on Http
*
* @type {Array}
*/
this._preLoadOnHttpOnly = [
'start/socket',
'start/kernel',
'start/wsKernel'
]

Expand Down Expand Up @@ -365,7 +374,11 @@ class Ignitor {
debug('preloading files %j', this._preLoadFiles)
debug('optional set %j', this._optionals)

this._preLoadFiles.forEach((file) => {
const isHttp = this.environment === 'http'
const isTesting = process.env.NODE_ENV === 'testing'
const filesToPreload = this._preLoadFiles.concat(isHttp || isTesting ? this._preLoadOnHttpOnly : [])

filesToPreload.forEach((file) => {
const filePath = path.isAbsolute(file) ? file : path.join(this._appRoot, file)

/**
Expand Down Expand Up @@ -807,6 +820,8 @@ class Ignitor {
* @return {void}
*/
async fireHttpServer (httpServerCallback) {
this.environment = 'http'

try {
await this.fire()
await this._startHttpServer(httpServerCallback)
Expand Down Expand Up @@ -836,6 +851,11 @@ class Ignitor {
process.env.NODE_ENV = 'testing'
}

/**
* Setting the environment
*/
this.environment = 'ace'

/**
* Load database/factory.js file when loading
* ace commands
Expand Down
10 changes: 10 additions & 0 deletions test/ignitor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ test.group('Ignitor', (group) => {
await ignitor.fireHttpServer()
})

test('do not load http only files when firing ace', async (assert) => {
const ignitor = new Ignitor(fold)
ignitor.appRoot(path.join(__dirname, './'))
ignitor._preLoadOnHttpOnly = ['start/emitsError']
ignitor._startHttpServer = function () {}
ignitor._gracefullyShutDown = function () {}

await ignitor.fireAce()
})

test('call preloading hooks', async (assert) => {
const ignitor = new Ignitor(fold)
const events = []
Expand Down