forked from quizlet/ts-migration
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollectFiles.js
47 lines (47 loc) · 2.33 KB
/
collectFiles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const util_1 = require("util");
const path_1 = require("path");
const readdir = (0, util_1.promisify)(fs_1.default.readdir);
const stat = (0, util_1.promisify)(fs_1.default.stat);
function getFiles(dir) {
return __awaiter(this, void 0, void 0, function* () {
const subdirs = yield readdir(dir);
const files = yield Promise.all(subdirs.map((subdir) => __awaiter(this, void 0, void 0, function* () {
const res = (0, path_1.resolve)(dir, subdir);
return (yield stat(res)).isDirectory() ? getFiles(res) : res;
})));
return files.reduce((a, f) => a.concat(f), []);
});
}
function collectFiles(paths) {
return __awaiter(this, void 0, void 0, function* () {
const filesArr = yield Promise.all(paths.include.map((include) => __awaiter(this, void 0, void 0, function* () {
const isFile = (yield stat(include)).isFile();
return isFile ? [include] : yield getFiles(include);
})));
const files = filesArr.reduce((a, f) => a.concat(f), []);
const filesWithExtensions = files.filter(f => {
return paths.extensions.some(e => f.endsWith(e));
});
const filesWithoutExclusions = filesWithExtensions.filter(f => {
return !paths.exclude.some(e => f.includes(e));
});
return filesWithoutExclusions;
});
}
exports.default = collectFiles;
//# sourceMappingURL=collectFiles.js.map