processDir = function(stack, dir, dirlist) { return dfs.readdir(dir.path).then(function(files) { return Deferred.all(files.map(function(filename) { var fullpath = path.join(dir.path, filename); return dfs.stat(fullpath).then(function(stat) { if (stat.isDirectory()) { stack.push({path: fullpath, dir: true}); } else { dirlist.push({path: fullpath, dir: false}); } return new Deferred().resolve(); }); })); }); };
processDir = function(stack, dir) { return dfs.readdir(dir).then(function(files) { return Deferred.all(files.map(function(filename) { var fullpath = path.join(dir, filename); return dfs.stat(fullpath).then(function(stat) { if (stat.isDirectory()) { stack.push(fullpath); return new Deferred().resolve(); } else { // console.log('unlink ' + fullpath); return dfs.unlink(fullpath); } }); })); }); };
}).then(function() { // Copy all required files into the .temp directory for doing the build if (steps.copy === false) { return new Deferred().resolve(); } section('Copying client code to ' + pathToTempDir); // Get the list of bundles from the orion.client lib: var bundles = []; return dfs.readdir(pathToOrionClientBundlesFolder).then(function(contents) { return Deferred.all(contents.map(function(item) { return dfs.stat(path.join(pathToOrionClientBundlesFolder, item)).then(function(stats) { if (stats.isDirectory()) { bundles.push(item); } }); })); }).then(function() { console.log('Copying orion.client'); /* So. Because the file structure of the Orion source bundles doesn't match the URL/RequireJS module * structure, we need to copy all the bundles' "./web/" folders into the temp dir, so that modules * will resolve in later optimization steps. */ return async.sequence(bundles.map(function(bundle) { return function() { var bundleWebFolder = path.resolve(pathToOrionClientBundlesFolder, bundle, BUNDLE_WEB_FOLDER); return dfs.exists(bundleWebFolder).then(function(exists) { if (exists) { return execCommand(getCopyDirCmd(bundleWebFolder, pathToTempDir)); } else { console.log('Bundle has no web/ folder, skip: ' + bundle); return; } }); }; }).concat([ function() { console.log('Copying orionode.client'); return execCommand(getCopyDirCmd(pathToOrionodeClient, pathToTempDir)); } ])); }); }).then(function() {
exports.getChildren = function(directory, parentLocation, excludes, callback) { // If 'excludes' is omitted, the callback can be given as the 3rd argument callback = excludes || callback; dfs.readdir(directory).then(function(files) { // stat each file to find if it's a Directory -- ugh var childStatPromises = files.map(function(file) { if (Array.isArray(excludes) && excludes.indexOf(file) !== -1) { return null; // omit } var filepath = path.join(directory, file); return dfs.stat(filepath).then(function(stat) { return [filepath, stat]; }); }).filter(function(f) { return f; }); // skip omitted stuff Deferred.all(childStatPromises).then(function(childStats) { var children = childStats.map(function(cs) { var childname = path.basename(cs[0]); var isDirectory = cs[1].isDirectory(); var timeStamp = cs[1].mtime.getTime(); var size = cs[1].size; var location = api.join(parentLocation, encodeURIComponent(childname)); if(isDirectory && location[location.length-1] !== "/"){ location = location +"/"; } return { Name: childname, Id: childname, Length: size, LocalTimeStamp: timeStamp, Directory: isDirectory, Location: location, ChildrenLocation: isDirectory ? api.join(parentLocation, childname) + '?depth=1' : null }; }); callback(children); //yay }); }); };