Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Fix issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
ofrogon committed Apr 30, 2016
1 parent 87ef5c6 commit 4c0bafc
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions lib/fileManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ function arrayOfGlob(globs, bowerFileFolder, libName, depth, localCache) {
depth = depth || 0;

if (depth < length) {
glob(path.join(bowerFileFolder, libName, globs[depth]), function(err, data) {
glob(path.join(bowerFileFolder, libName, globs[depth]), function (err, data) {
if (!err) {
depth++;

arrayOfGlob(globs, bowerFileFolder, libName, depth, data).then(
function(ans) {
function (ans) {
data = data.concat(ans.data);

deferred.resolve({data: data, localCache: localCache});
},
function(err) {
function (err) {
deferred.reject(err);
}
);
Expand Down Expand Up @@ -90,9 +90,9 @@ FileObj.prototype = {
* @param that {FileObj}
* @returns {Promise<Q>}
*/
getList: function(libs, libName, libFolder, uncleanList, that) {
getList: function (libs, libName, libFolder, uncleanList, that) {
return that.enumeratePackages(libs, libName, libFolder).then(
function(data) {
function (data) {
uncleanList.ignore = uncleanList.ignore.concat(data.ignore);
uncleanList.move = uncleanList.move.concat(data.move);
}
Expand All @@ -109,16 +109,16 @@ FileObj.prototype = {
* @param that {FileObj}
* @returns {Promise<Q>}
*/
enumeratePackages: function(fileNameAndExt, libName, libFolder, localCache, uncleanList, that) {
enumeratePackages: function (fileNameAndExt, libName, libFolder, localCache, uncleanList, that) {
return arrayOfGlob([fileNameAndExt], that.bowerFileFolder, libName, 0, localCache).then(
function(ans) {
function (ans) {
var lc = ans.localCache,
result = that.enumerateFile(ans.data, lc.fileName, libFolder, lc.fileFolder, lc.pkg === "!" ? "ignore" : "move");

uncleanList.ignore = uncleanList.ignore.concat(result.ignore);
uncleanList.move = uncleanList.move.concat(result.move);
},
function(err) {
function (err) {
console.warn(err);
}
);
Expand All @@ -130,7 +130,7 @@ FileObj.prototype = {
*
* @returns {Promise<Q>}
*/
getList: function() {
getList: function () {
var uncleanList = {
ignore: [],
move: []
Expand All @@ -152,10 +152,10 @@ FileObj.prototype = {
}

Q.all(promises).then(
function() {
function () {
defer.resolve(that.clean(uncleanList));
},
function(err) {
function (err) {
defer.reject(err);
}
);
Expand All @@ -171,7 +171,7 @@ FileObj.prototype = {
* @param libFolder {String}
* @returns {Promise<Q>}
*/
enumeratePackages: function(pkgs, libName, libFolder) {
enumeratePackages: function (pkgs, libName, libFolder) {
var uncleanList = {ignore: [], move: []},
defer = Q.defer(),
promises = [],
Expand All @@ -185,9 +185,8 @@ FileObj.prototype = {
}

for (var x = 0, y = pkgs[pkg].length; x < y; x++) {
var pkgPart = pkgs[pkg][x].split("#"),
fileNameAndExt = pkgPart[0] || "*",
fileFolder = pkgPart[1] || "",
var fileNameAndExt = pkgs[pkg][x] || "*",
fileFolder = pkg.split("#")[1] || "",
extName = path.extname(fileNameAndExt),
fileName = path.basename(fileNameAndExt, extName),
extension = extName.substr(1);
Expand Down Expand Up @@ -217,10 +216,10 @@ FileObj.prototype = {
}

Q.all(promises).then(
function() {
function () {
defer.resolve(uncleanList);
},
function(err) {
function (err) {
defer.reject(err);
}
);
Expand All @@ -237,7 +236,7 @@ FileObj.prototype = {
* @param action {String}
* @returns {{ignore: Array, move: Array}}
*/
enumerateFile: function(files, fileName, libFolder, fileFolder, action) {
enumerateFile: function (files, fileName, libFolder, fileFolder, action) {
var f,
unCleanList = {
ignore: [],
Expand Down Expand Up @@ -303,7 +302,7 @@ FileObj.prototype = {
* @param unCleanList {{ignore: Array, move: Array}}
* @returns {Array}
*/
clean: function(unCleanList) {
clean: function (unCleanList) {
var list = [];

if (Object.keys(unCleanList).length >= 0) {
Expand Down Expand Up @@ -331,16 +330,16 @@ FileObj.prototype = {
*
* @returns {Promise<Q>}
*/
deleteBowerComponents: function() {
deleteBowerComponents: function () {
var deferred = Q.defer();

fs.rmdirRQ(this.bowerFileFolder).then(
// Pass
function() {
function () {
deferred.resolve();
},
// Fail
function(err) {
function (err) {
// Make the error go up
deferred.reject(err);
}
Expand All @@ -354,12 +353,12 @@ FileObj.prototype = {
*
* @returns {Promise<Q>}
*/
run: function() {
run: function () {
var deferred = Q.defer(),
that = this;

this.getList().then(
function(list) {
function (list) {
var promises = [];

// Backup the list of files to return them is the option verbose is set
Expand All @@ -372,18 +371,18 @@ FileObj.prototype = {
}

Q.all(promises).then(
function() {
function () {
if (that.isVerbose) {
deferred.resolve(that.listBackup);
} else {
deferred.resolve(null);
}
},
function(err) {
function (err) {
deferred.reject(err);
}
);
}, function(err) {
}, function (err) {
deferred.reject(err);
}
);
Expand All @@ -396,24 +395,24 @@ FileObj.prototype = {
*
* @returns {Promise<Q>}
*/
runAndRemove: function() {
runAndRemove: function () {
var deferred = Q.defer(),
pointer = this;

this.run().then(
function(data) {
function (data) {
pointer.deleteBowerComponents().then(
function() {
function () {
deferred.resolve(data);
},
function(err) {
function (err) {
deferred.reject(err);
}
);
},
function(err) {
function (err) {
pointer.deleteBowerComponents().finally(
function() {
function () {
deferred.reject(err);
}
);
Expand All @@ -435,10 +434,10 @@ function moveFiles(config) {
list = new FileObj(config);

list.run().then(
function(message) {
function (message) {
deferred.resolve(message);
},
function(err) {
function (err) {
deferred.reject(err);
}
);
Expand All @@ -458,10 +457,10 @@ function moveFilesAndRemove(config) {
list = new FileObj(config);

list.runAndRemove().then(
function(data) {
function (data) {
deferred.resolve(data);
},
function(err) {
function (err) {
deferred.reject(err);
}
);
Expand Down

0 comments on commit 4c0bafc

Please sign in to comment.