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

Commit

Permalink
Merge branch 'release/1.0.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Oct 3, 2017
2 parents 008b8fa + 9833d3d commit 65a41dc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 19 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<a name="1.0.12"></a>
## [1.0.12](https://github.com/adonisjs/adonis-ignitor/compare/v1.0.11...v1.0.12) (2017-10-03)


### Bug Fixes

* **ignitor:** allow preload file path to be absolute ([bb35c48](https://github.com/adonisjs/adonis-ignitor/commit/bb35c48))


### Features

* **autoload:** register all autoload directories from package.json file ([39d9015](https://github.com/adonisjs/adonis-ignitor/commit/39d9015))



<a name="1.0.11"></a>
## [1.0.11](https://github.com/adonisjs/adonis-ignitor/compare/v1.0.10...v1.0.11) (2017-09-14)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adonisjs/ignitor",
"version": "1.0.11",
"version": "1.0.12",
"description": "Fire the adonis-app (in good sense)",
"main": "index.js",
"scripts": {
Expand Down
67 changes: 50 additions & 17 deletions src/Ignitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,38 +131,69 @@ class Ignitor {
}

/**
* Sets up resolver by registering paths to important
* directories and setting up the autoloaded path
* to the IoC container.
* Sets up resolver primary namespace and register paths to
* important directories.
*
* @method _setupResolver
*
* @param {String} namespace
*
* @return {void}
*
* @private
*/
_setupResolver () {
const autoload = this._packageFile.autoload || {}
let [ namespace ] = Object.keys(autoload)
this.appNamespace = namespace || 'App'
const autoloadDirectory = (path.join(this._appRoot, autoload[this.appNamespace] || './app'))
_setupResolver (namespace) {
this.appNamespace = namespace
debug('%s is the primary namespace', namespace)

/**
* Set app namespace with resolver. So that resolver
* knows how to make full namespaces.
*/
this._fold.resolver.appNamespace(this.appNamespace)

/**
* Setting up the autoloaded directory
*/
this._fold.ioc.autoload(autoloadDirectory, this.appNamespace)

/**
* Bind directories to resolver, so that we can
* resolve ioc container paths by passing
* incremental namespaces.
*/
this._fold.resolver.directories(DIRECTORIES)
debug('autoloading %s under %s namespace', autoloadDirectory, this.appNamespace)
}

/**
* Registers all directories from the package.json file
* to IoC container as autoloaded.
*
* First namespace/directory key/value pair will be used as
* primary autoloaded directory and doesn't require
* fullnamespaces at different places.
*
* @method _registerAutoloadedDirectories
*
* @return {void}
*
* @private
*/
_registerAutoloadedDirectories () {
let autoloads = this._packageFile.autoload || {}

/**
* Defining fallback autoload when nothing autoloads
* map is empty
*/
if (Object.keys(autoloads).length === 0) {
autoloads = { 'App': './app' }
}

Object.keys(autoloads).forEach((namespace, index) => {
const namespaceLocation = path.join(this._appRoot, autoloads[namespace])
if (index === 0) {
this._setupResolver(namespace)
}

this._fold.ioc.autoload(namespaceLocation, namespace)
debug('autoloading %s under %s namespace', namespaceLocation, namespace)
})
}

/**
Expand Down Expand Up @@ -325,7 +356,8 @@ class Ignitor {

this._preLoadFiles.forEach((file) => {
try {
require(path.join(this._appRoot, file))
const filePath = path.isAbsolute(file) ? file : path.join(this._appRoot, file)
require(filePath)
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND' || !this._isOptional(file)) {
throw error
Expand Down Expand Up @@ -537,21 +569,22 @@ class Ignitor {
}

this._setPackageFile()
this._setupResolver()
this._registerAutoloadedDirectories()
this._registerHelpers()
this._loadHooksFileIfAny()
this._registerProviders()
await this._bootProviders()
this._defineAliases()
this._setupExceptionsHandler()
this._loadPreLoadFiles()

/**
* Register commands when loadCommands is set to true.
*/
if (this._loadCommands) {
this._registerCommands()
}

this._loadPreLoadFiles()
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/ignitor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ test.group('Ignitor', (group) => {
})

ignitor._setPackageFile()
ignitor._setupResolver()
ignitor._registerAutoloadedDirectories()
ignitor._setupExceptionsHandler()
await fs.remove(path.join(__dirname, './app'))
})
Expand Down

0 comments on commit 65a41dc

Please sign in to comment.