}).then(function () { //search for all ui plugins return Q.when(qfs.list(ABS_NODE_MODULES), function(files){ var isDocularPlugin = /^docular-ui-plugin-([^\/\\]+)$/; //look for any api.js files within subdirectories of the doc_apis directory files.forEach(function(file) { var matches = isDocularPlugin.exec(doc_utils.normalizeFile(file)); if(matches){ try{ ui_plugins[matches[1]] = require(file + '/index.js'); } catch(e) { console.log("Failed to load docular plugin:", e); } } }); }); //Next we need to process all the groups and normalize their api values }).then(function() {
return Q.when(qfs.list(ABS_NODE_MODULES), function(files){ return Q.when(qfs.list(ABS_GLOBAL_NODE_MODULES), function (globalModules) { var nodeModulePromises = [], allFiles = globalModules.concat(files); nodeModulePromises.push(loadDocAPIPlugins(allFiles)); nodeModulePromises.push(loadUIPlugins(allFiles)); return Q.all(nodeModulePromises); }); });
exports.getDirsFiles = function(path, dirs, files) { return QFS.list(path).then(function(list) { return Q.all(list .map(function(i) { return QFS.isDirectory(PATH.join(path, i)) .then(function(isDir) { (isDir ? dirs : files).push(i); }); })); }); };
.then(function (packages) { return FS.list(packages).then(function (names) { // discover installed packages return Q.all(names.map(function (name) { return FS.isFile(FS.join(packages, name, "package.json")) .then(function (isFile) { if (isFile) { found[name] = FS.join(packages, name); } }); })); }); }, function (reason) {
}).then(function(){ //search for all doc_apis within the node_modules folder with prefix docular-doc-api- return Q.when(qfs.list(ABS_NODE_MODULES), function(files){ var rawDocAPIS = {}; var pattern_apiFile = new RegExp(docularAPIPrefix + "([^\/]+)$",'i'); //look for any api.js files within subdirectories of the doc_apis directory files.forEach(function(file) { var matches = pattern_apiFile.exec(doc_utils.normalizeFile(file)); if(matches){ try{ rawDocAPIS[matches[1]] = require(file + '/index.js'); } catch(e) { console.log("Failed to load document api:", e); } } }); //let's also nest the doc_api value inside the object for(var docAPI in rawDocAPIS){ rawDocAPIS[docAPI].apiName = docAPI; } //throw an error if the default doc api was not loaded if(!rawDocAPIS['doc']){ console.log("FATAL ERROR: ".red + " Error loading default doc api 'doc'.".yellow, e); } else { //first set the default doc api var defaultDocAPI = doc_apis['doc'] = rawDocAPIS['doc']; //now we use the default doc api "doc" to start as a base class for(var docName in rawDocAPIS) { if(rawDocAPIS.hasOwnProperty(docName) && docName != 'doc') { doc_apis[docName] = nodeExtend(true, {}, defaultDocAPI, rawDocAPIS[docName]); } } } }); //now gather all ui plugins and store them }).then(function () {
/** * Optimize all *.svg files in a specific folder. * * @param {String} folder folder path * @param {Object} opts COA options */ function optimizeFolder(folder, opts) { var svgo = new SVGO({ coa: opts }); folder = PATH.resolve(process.cwd(), folder); UTIL.puts('\n' + folder + ':\n'); // list directory QFS.list(folder).then(function(list) { list.forEach(function(item) { var filename = item; item = folder + '/' + item; // checkif item is a file QFS.isFile(item) .then(function(isFile) { // and file name matches *.svg if (isFile && regSVGFile.test(item)) { // then optimize it and output profit information return svgo.fromFile(item) .then(function(result) { UTIL.puts(filename + ':'); saveFileAndPrintInfo(result, item, opts.pretty); }); } }) .fail(function(e) { UTIL.puts(filename + ':\n' + String('Error! "' + e.message + '"').red + '\n'); }); }); }) .done(); }
}).then(function(){ //search for all node_modules that could be plugins and process them return Q.when(qfs.list(ABS_NODE_MODULES), function(files){ var nodeModulePromises = []; nodeModulePromises.push(loadDocAPIPlugins(files)); nodeModulePromises.push(loadUIPlugins(files)); return Q.deep(nodeModulePromises); }); //Next we need to process all the groups and normalize their api values }).then(function() {
return function() { return QFS.list(path).then(function(list) { response.status = 200; response.charset = 'utf8'; response.headers = { 'content-type': 'text/json' }; root = PATH.join(root, '/'); var body = response.body = [], files = [], dirs = []; body.push(U.getDirsFiles(path, dirs, files).then(function() { return JSON.stringify(files); })); return response; }); }
exports.getFilesAsync = function(path) { return QFS.list(path).then(function(items) { return Q.all(items.map(function(i) { return QFS.isFile(PATH.join(path, i)) .then(function(isFile){ return { name: i, file: isFile }; } ); })) .then(function(items) { return items .filter(function(item) { return item.file; }) .map(function(item) { return item.name; }); } ); }); };
exports.getDirsAsync = function(path) { return QFS.list(path).then(function(items) { return Q.all(items.map(function(i) { return QFS.isDirectory(PATH.join(path, i)) .then(function(isDir){ return { name: i, dir: isDir }; } ); })) .then(function(items) { return items .filter(function(item) { return item.dir; }) .map(function(item) { return item.name; }); } ); }); };
var Q = require("q/util"); var FS = require("q-fs"); Q.when(FS.list(__dirname)) .then(function (fileNames) { return Q.deep(fileNames.map(function (fileName) { return { "name": fileName, "text": FS.read(FS.join(__dirname, fileName)) }; })); }).then(function (files) { files.forEach(function (file) { console.log(file.name, file.text.length); }); });
listEntries = function() { return fs.list(entryDirectory); },