diff --git a/lib/analyzer.js b/lib/analyzer.js index 22a0bfa..47651dc 100644 --- a/lib/analyzer.js +++ b/lib/analyzer.js @@ -32,7 +32,13 @@ module.exports = class { let cliParams = this.getCliParams(); return Promise.all([this.getProject(), this.getConfig(cliParams.pkg)]) .then(result => { - this.result = { project: result[0], config: result[1], options: cliParams, importer: this.autoDiscoverHooks(cliParams.pkg)}; + this.result = { + project: result[0], + config: result[1], + options: cliParams, + importer: this.autoDiscoverHooks(cliParams.pkg) + }; + return this.result; }); } @@ -75,7 +81,7 @@ module.exports = class { if (instance === null) { return null; } - + return new instance(); } @@ -135,11 +141,11 @@ module.exports = class { * @return {Promise} */ getConfig(pkgName) { - return new Promise((function (resolve, reject) { + return new Promise(((resolve, reject) => { this.exists(pkgName) - .then(function (exists) { + .then((exists) => { if (exists === true) { - fs.readJson(this.getFilename(pkgName), function (err, data) { + fs.readJson(this.getFilename(pkgName), (err, data) => { if (err) { reject(err); } else { @@ -158,7 +164,7 @@ module.exports = class { } } }) - .catch(function (e) { + .catch((e) => { reject(e); }); }).bind(this)); @@ -198,8 +204,8 @@ module.exports = class { exists(pkgName) { let t = this; - return new Promise(function (resolve, reject) { - fs.stat(t.getFilename(pkgName), function (err, stat) { + return new Promise((resolve, reject) => { + fs.stat(t.getFilename(pkgName), (err, stat) => { if (err) { reject(err); } else { diff --git a/lib/import-base.js b/lib/import-base.js index 06ef91d..b62178e 100644 --- a/lib/import-base.js +++ b/lib/import-base.js @@ -166,8 +166,9 @@ module.exports = class { /** * Install custom aurelia-cli tasks to aurelia_project/tasks folder - * @TODO: provide mechanism to be able to install tasks provided by - * the npm package currently being configured (e.g. ./node_modules/plugin/..) + * + * Capable of installing tasks provided by the npm package + * currently being configured (e.g. ./node_modules/plugin/..) * * @return ImportStepState | void */ @@ -184,11 +185,21 @@ module.exports = class { for (let taskName of tasks) { // determinate transpiler to set correct file extension let filename = taskName + project.transpiler.fileExtension, - source = path.resolve(__dirname, `../tasks/${taskName}`), - destFile = destFolder + filename; + destFile = destFolder + filename, + source = null; // If file is missing, aborting importation process by throwing an Error - fs.copySync(`${source}.js`, destFile); + try { + // by default, search in installed package directory + let pkgName = this.engine.options.pkg; + pkgName = pkgName.indexOf('@') !== -1 ? pkgName.split('@')[0] : pkgName; + source = path.resolve(__dirname, `../../${pkgName}/install/${taskName}`); + fs.copySync(`${source}.js`, destFile); + } catch (e) { + // fallback to 'tasks' folder in aurelia-cli-pacman + source = path.resolve(__dirname, `../tasks/${taskName}`); + fs.copySync(`${source}.js`, destFile); + } // task metadata is optional try {