diff --git a/src/Ignitor/index.js b/src/Ignitor/index.js index ab1c1f0..b04ab3c 100644 --- a/src/Ignitor/index.js +++ b/src/Ignitor/index.js @@ -47,6 +47,7 @@ class Ignitor { constructor (fold) { this._fold = fold this._appRoot = null + this._modulesRoot = null this._loadCommands = false /** @@ -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') @@ -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() /** @@ -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 diff --git a/test/ignitor.spec.js b/test/ignitor.spec.js index 4aca969..15b2c54 100644 --- a/test/ignitor.spec.js +++ b/test/ignitor.spec.js @@ -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') @@ -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, './'))