@openveo/api
Advanced tools
Comparing version 4.0.0-RC2 to 4.0.0
@@ -1,2 +0,2 @@ | ||
# 4.0.0 / | ||
# 4.0.0 / 2017-05-04 | ||
@@ -33,2 +33,3 @@ ## BREAKING CHANGES | ||
- util.shallowValidateObject is now capable to validate a timestamp as a string for a date | ||
- Add require('@openveo/api').fileSystem.readdir function to get resources of a directory and all its sub directories | ||
@@ -113,2 +114,2 @@ ## BUG FIXES | ||
First stable version of OpenVeo API for [OpenVeo core](https://github.com/veo-labs/openveo-core) and plugins development. | ||
First stable version of OpenVeo API for [OpenVeo core](https://github.com/veo-labs/openveo-core) and plugins development. |
@@ -157,2 +157,77 @@ 'use strict'; | ||
/** | ||
* Reads a directory content recursively and asynchronously. | ||
* | ||
* It is assumed that the directory exists. | ||
* | ||
* @method readdirRecursive | ||
* @private | ||
* @static | ||
* @async | ||
* @param {String} directoryPath Path of the directory | ||
* @param {Function} callback The function to call when done | ||
* - **Error** The error if an error occurred, null otherwise | ||
* - **Array** The list of fs.Stats corresponding to resources inside the directory (files and directories) | ||
*/ | ||
function readdirRecursive(directoryPath, callback) { | ||
var resources = []; | ||
// Read directory | ||
fs.readdir(directoryPath, function(error, resourcesNames) { | ||
// Failed reading directory | ||
if (error) return callback(error); | ||
var pendingResourceNumber = resourcesNames.length; | ||
// No more pending resources, done for this directory | ||
if (!pendingResourceNumber) | ||
callback(null, resources); | ||
// Iterate through the list of resources in the directory | ||
resourcesNames.forEach(function(resourceName) { | ||
var resourcePath = path.join(directoryPath, resourceName); | ||
// Get resource stats | ||
fs.stat(resourcePath, function(error, stats) { | ||
if (error) | ||
return callback(error); | ||
stats.path = resourcePath; | ||
resources.push(stats); | ||
// Resource correspond to a directory | ||
if (stats.isDirectory()) { | ||
readdirRecursive(resourcePath, function(error, paths) { | ||
if (error) | ||
return callback(error); | ||
resources = resources.concat(paths); | ||
pendingResourceNumber--; | ||
if (!pendingResourceNumber) | ||
callback(null, resources); | ||
}); | ||
} else { | ||
// Resource does not correspond to a directory | ||
// Mark resource as treated | ||
pendingResourceNumber--; | ||
if (!pendingResourceNumber) | ||
callback(null, resources); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Copies a file. | ||
@@ -480,1 +555,25 @@ * | ||
}; | ||
/** | ||
* Gets the content of a directory recursively and asynchronously. | ||
* | ||
* @method readdir | ||
* @static | ||
* @async | ||
* @param {String} directoryPath Path of the directory | ||
* @param {Function} callback The function to call when done | ||
* - **Error** The error if an error occurred, null otherwise | ||
* - **Array** The list of resources insides the directory | ||
*/ | ||
module.exports.readdir = function(directoryPath, callback) { | ||
if (!directoryPath || Object.prototype.toString.call(directoryPath) !== '[object String]') | ||
return callback(new TypeError('Invalid directory path, expected a string')); | ||
fs.stat(directoryPath, function(error, stat) { | ||
if (error) callback(error); | ||
else if (!stat.isDirectory()) | ||
callback(new Error(directoryPath + ' is not a directory')); | ||
else | ||
readdirRecursive(directoryPath, callback); | ||
}); | ||
}; |
{ | ||
"name": "@openveo/api", | ||
"version": "4.0.0-RC2", | ||
"version": "4.0.0", | ||
"description": "API for OpenVeo plugins", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -19,10 +19,10 @@ # OpenVeo API | ||
Documentation is available on [Github pages](http://veo-labs.github.io/openveo-api/3.1.0). | ||
Documentation is available on [Github pages](http://veo-labs.github.io/openveo-api/4.0.0). | ||
# Contributors | ||
Maintainer : [Veo-Labs](http://www.veo-labs.com/) | ||
Maintainer: [Veo-Labs](http://www.veo-labs.com/) | ||
# License | ||
[AGPL](http://www.gnu.org/licenses/agpl-3.0.en.html) | ||
[AGPL](http://www.gnu.org/licenses/agpl-3.0.en.html) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
173985
3932
0
28