Skip to content

Commit

Permalink
Update: cli task installation: search folders
Browse files Browse the repository at this point in the history
  • Loading branch information
martonsagi committed Nov 1, 2016
1 parent 9aceff3 commit d090713
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
22 changes: 14 additions & 8 deletions lib/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -75,7 +81,7 @@ module.exports = class {
if (instance === null) {
return null;
}

return new instance();
}

Expand Down Expand Up @@ -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 {
Expand All @@ -158,7 +164,7 @@ module.exports = class {
}
}
})
.catch(function (e) {
.catch((e) => {
reject(e);
});
}).bind(this));
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 16 additions & 5 deletions lib/import-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 {
Expand Down

0 comments on commit d090713

Please sign in to comment.