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

Commit

Permalink
feat(Ignitor): allow to set modulesRoot (#11)
Browse files Browse the repository at this point in the history
Sometimes, appRoot is not necessarily the directory which contains
node_modules (for example when the AdonisJs app is in a subdirectory
of a bigger application.
`ignitor.modulesRoot(location)` allows to specify a different directory to
look for dependencies such as `@adonisjs/ace`.
  • Loading branch information
targos authored and thetutlage committed Aug 23, 2018
1 parent 8d4417b commit e1dda89
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Ignitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Ignitor {
constructor (fold) {
this._fold = fold
this._appRoot = null
this._modulesRoot = null
this._loadCommands = false

/**
Expand Down Expand Up @@ -408,7 +409,8 @@ class Ignitor {
this._callHooks('before', 'registerCommands')

const { commands } = this._getAppAttributes()
const ace = require(path.join(this._appRoot, '/node_modules/@adonisjs/ace'))
const root = this._modulesRoot || this._appRoot
const ace = require(path.join(root, '/node_modules/@adonisjs/ace'))
commands.forEach((command) => ace.addCommand(command))

this._callHooks('after', 'registerCommands')
Expand Down Expand Up @@ -513,7 +515,8 @@ class Ignitor {
_invokeAce () {
this._callHooks('before', 'aceCommand')

const ace = require(path.join(this._appRoot, '/node_modules/@adonisjs/ace'))
const root = this._modulesRoot || this._appRoot
const ace = require(path.join(root, '/node_modules/@adonisjs/ace'))
ace.wireUpWithCommander()

/**
Expand Down Expand Up @@ -659,6 +662,22 @@ class Ignitor {
return this
}

/**
* Set application modules root. This path
* contains the node_modules directory with
* the application's dependencies.
*
* @method modulesRoot
*
* @param {String} location
*
* @chainable
*/
modulesRoot (location) {
this._modulesRoot = location
return this
}

/**
* Set the application file. This file exports
* an array of providers, aceProviders, aliases
Expand Down
13 changes: 13 additions & 0 deletions test/ignitor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ test.group('Ignitor', (group) => {
assert.equal(ignitor._appRoot, 'foo')
})

test('register modules root', (assert) => {
const ignitor = new Ignitor()
ignitor.modulesRoot('foo')
assert.equal(ignitor._modulesRoot, 'foo')
})

test('default app file to start/app.js', (assert) => {
const ignitor = new Ignitor()
assert.equal(ignitor._appFile, 'start/app.js')
Expand Down Expand Up @@ -269,6 +275,13 @@ test.group('Ignitor', (group) => {
}
})

test('fire ace when app and modules roots are different', async () => {
const ignitor = new Ignitor(fold)
ignitor.appRoot(__dirname)
ignitor.modulesRoot(path.join(__dirname, '..'))
await ignitor.fireAce()
})

test('setup resolver', async (assert) => {
const ignitor = new Ignitor(fold)
ignitor.appRoot(path.join(__dirname, './'))
Expand Down

0 comments on commit e1dda89

Please sign in to comment.