nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / lodash / lib / common / file.js
1 'use strict';
2
3 var _ = require('lodash'),
4     fs = require('fs-extra'),
5     glob = require('glob'),
6     path = require('path');
7
8 var minify = require('../common/minify.js');
9
10 /*----------------------------------------------------------------------------*/
11
12 /**
13  * Creates a [fs.copy](https://github.com/jprichardson/node-fs-extra#copy)
14  * function with `srcPath` and `destPath` partially applied.
15  *
16  * @memberOf file
17  * @param {string} srcPath The path of the file to copy.
18  * @param {string} destPath The path to copy the file to.
19  * @returns {Function} Returns the partially applied function.
20  */
21 function copy(srcPath, destPath) {
22   return _.partial(fs.copy, srcPath, destPath);
23 }
24
25 /**
26  * Creates an object of compiled template and base name pairs that match `pattern`.
27  *
28  * @memberOf file
29  * @param {string} pattern The glob pattern to be match.
30  * @returns {Object} Returns the object of compiled templates.
31  */
32 function globTemplate(pattern) {
33   return _.transform(glob.sync(pattern), function(result, filePath) {
34     var key = path.basename(filePath, path.extname(filePath));
35     result[key] = _.template(fs.readFileSync(filePath, 'utf8'));
36   }, {});
37 }
38
39 /**
40  * Creates a `minify` function with `srcPath` and `destPath` partially applied.
41  *
42  * @memberOf file
43  * @param {string} srcPath The path of the file to minify.
44  * @param {string} destPath The path to write the file to.
45  * @returns {Function} Returns the partially applied function.
46  */
47 function min(srcPath, destPath) {
48   return _.partial(minify, srcPath, destPath);
49 }
50
51 /**
52  * Creates a [fs.writeFile](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)
53  * function with `filePath` and `data` partially applied.
54  *
55  * @memberOf file
56  * @param {string} destPath The path to write the file to.
57  * @param {string} data The data to write to the file.
58  * @returns {Function} Returns the partially applied function.
59  */
60 function write(destPath, data) {
61   return _.partial(fs.writeFile, destPath, data);
62 }
63
64 /*----------------------------------------------------------------------------*/
65
66 module.exports = {
67   'copy': copy,
68   'globTemplate': globTemplate,
69   'min': min,
70   'write': write
71 };