1 | 'use strict';
|
2 |
|
3 | var _stringify = require('babel-runtime/core-js/json/stringify');
|
4 |
|
5 | var _stringify2 = _interopRequireDefault(_stringify);
|
6 |
|
7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | var glob = require('glob');
|
26 | var path = require('path');
|
27 |
|
28 | var errors = require('./errors');
|
29 | var getFileSize = require('./get-file-size');
|
30 | var getFileHash = require('./get-file-hash');
|
31 |
|
32 | module.exports = function (globOptions) {
|
33 | var globDirectory = globOptions.globDirectory,
|
34 | globFollow = globOptions.globFollow,
|
35 | globIgnores = globOptions.globIgnores,
|
36 | globPattern = globOptions.globPattern,
|
37 | globStrict = globOptions.globStrict;
|
38 |
|
39 | var globbedFiles = void 0;
|
40 | try {
|
41 | globbedFiles = glob.sync(globPattern, {
|
42 | cwd: globDirectory,
|
43 | follow: globFollow,
|
44 | ignore: globIgnores,
|
45 | strict: globStrict
|
46 | });
|
47 | } catch (err) {
|
48 | throw new Error(errors['unable-to-glob-files'] + ` '${err.message}'`);
|
49 | }
|
50 |
|
51 | if (globbedFiles.length === 0) {
|
52 | throw new Error(errors['useless-glob-pattern'] + ' ' + (0, _stringify2.default)({ globDirectory, globPattern, globIgnores }, null, 2));
|
53 | }
|
54 |
|
55 | var fileDetails = globbedFiles.map(function (file) {
|
56 | var fullPath = path.join(globDirectory, file);
|
57 | var fileSize = getFileSize(fullPath);
|
58 | if (fileSize === null) {
|
59 | return null;
|
60 | }
|
61 |
|
62 | var fileHash = getFileHash(fullPath);
|
63 | return {
|
64 | file: `${path.relative(globDirectory, fullPath)}`,
|
65 | hash: fileHash,
|
66 | size: fileSize
|
67 | };
|
68 | });
|
69 |
|
70 |
|
71 | return fileDetails.filter(function (details) {
|
72 | return details !== null;
|
73 | });
|
74 | }; |
\ | No newline at end of file |