UNPKG

ts-api-core

Version:

Nodejs api framework core

41 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const pm = require("picomatch"); const run = (pattern, options = { cwd: process.cwd(), ignore: [] }) => { const startTime = Date.now(); const entryDir = options.cwd; const isMatch = pm(pattern, { ignore: options.ignore || [] }); const ignoreMatch = pm('**', { ignore: options.ignore || [] }); function globDirectory(dirname, isMatch, ignoreDirMatch, options) { if (!(0, fs_1.existsSync)(dirname)) { return []; } const list = (0, fs_1.readdirSync)(dirname); const result = []; for (let file of list) { const resolvePath = (0, path_1.resolve)(dirname, file); // log(`resolvePath = ${resolvePath}`) const fileStat = (0, fs_1.statSync)(resolvePath); if (fileStat.isDirectory() && ignoreDirMatch(resolvePath.replace(entryDir, ''))) { const childs = globDirectory(resolvePath, isMatch, ignoreDirMatch, options); result.push(...childs); } else if (fileStat.isFile() && isMatch(resolvePath.replace(entryDir, ''))) { result.push(resolvePath); } } return result; } const result = globDirectory(entryDir, isMatch, ignoreMatch, options); // log(`timing ${Date.now() - startTime}ms`) return result; }; exports.run = run; //# sourceMappingURL=index.js.map