From 4f438416993a07f6c44703bb3d072b3291b3b5c5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 9 Apr 2016 21:12:18 -0700 Subject: [PATCH] Add doc comments to the common file util. [ci skip] --- lib/common/file.js | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/common/file.js b/lib/common/file.js index 783a194ba..9f9016fbe 100644 --- a/lib/common/file.js +++ b/lib/common/file.js @@ -9,10 +9,26 @@ var minify = require('../common/minify.js'); /*----------------------------------------------------------------------------*/ +/** + * Creates a [fs.copy](https://github.com/jprichardson/node-fs-extra#copy) + * function with `srcPath` and `destPath` partially applied. + * + * @memberOf file + * @param {string} srcPath The path of the file to copy. + * @param {string} destPath The path to copy the file to. + * @returns {Function} Returns the partially applied function. + */ function copy(srcPath, destPath) { return _.partial(fs.copy, srcPath, destPath); } +/** + * Creates an object of compiled template and base name pairs that match `pattern`. + * + * @memberOf file + * @param {string} pattern The glob pattern to be match. + * @returns {Object} Returns the object of compiled templates. + */ function globTemplate(pattern) { return _.transform(glob.sync(pattern), function(result, filePath) { var key = path.basename(filePath, path.extname(filePath)); @@ -20,14 +36,33 @@ function globTemplate(pattern) { }, {}); } +/** + * Creates a `minify` function with `srcPath` and `destPath` partially applied. + * + * @memberOf file + * @param {string} srcPath The path of the file to minify. + * @param {string} destPath The path to write the file to. + * @returns {Function} Returns the partially applied function. + */ function min(srcPath, destPath) { return _.partial(minify, srcPath, destPath); } -function write(filePath, data) { - return _.partial(fs.writeFile, filePath, data); +/** + * Creates a [fs.writeFile](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) + * function with `filePath` and `data` partially applied. + * + * @memberOf file + * @param {string} destPath The path to write the file to. + * @param {string} data The data to write to the file. + * @returns {Function} Returns the partially applied function. + */ +function write(destPath, data) { + return _.partial(fs.writeFile, destPath, data); } +/*----------------------------------------------------------------------------*/ + module.exports = { 'copy': copy, 'globTemplate': globTemplate,