Repository URL to install this package:
|
Version:
5.0.0-rc.11 ▾
|
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var path = _interopDefault(require('path'));
var index = require('../path-type/index.js');
const getExtensions = extensions => extensions.length > 1 ? `{${extensions.join(',')}}` : extensions[0];
const getPath = (filepath, cwd) => {
const pth = filepath[0] === '!' ? filepath.slice(1) : filepath;
return path.isAbsolute(pth) ? pth : path.join(cwd, pth);
};
const addExtensions = (file, extensions) => {
if (path.extname(file)) {
return `**/${file}`;
}
return `**/${file}.${getExtensions(extensions)}`;
};
const getGlob = (dir, opts) => {
if (opts.files && !Array.isArray(opts.files)) {
throw new TypeError(`Expected \`files\` to be of type \`Array\` but received type \`${typeof opts.files}\``);
}
if (opts.extensions && !Array.isArray(opts.extensions)) {
throw new TypeError(`Expected \`extensions\` to be of type \`Array\` but received type \`${typeof opts.extensions}\``);
}
if (opts.files && opts.extensions) {
return opts.files.map(x => path.join(dir, addExtensions(x, opts.extensions)));
}
if (opts.files) {
return opts.files.map(x => path.join(dir, `**/${x}`));
}
if (opts.extensions) {
return [path.join(dir, `**/*.${getExtensions(opts.extensions)}`)];
}
return [path.join(dir, '**')];
};
var dirGlob = (input, opts) => {
opts = Object.assign({cwd: process.cwd()}, opts);
if (typeof opts.cwd !== 'string') {
return Promise.reject(new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof opts.cwd}\``));
}
return Promise.all([].concat(input).map(x => index.default.dir(getPath(x, opts.cwd))
.then(isDir => isDir ? getGlob(x, opts) : x)))
.then(globs => [].concat.apply([], globs));
};
var sync = (input, opts) => {
opts = Object.assign({cwd: process.cwd()}, opts);
if (typeof opts.cwd !== 'string') {
throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof opts.cwd}\``);
}
const globs = [].concat(input).map(x => index.default.dirSync(getPath(x, opts.cwd)) ? getGlob(x, opts) : x);
return [].concat.apply([], globs);
};
dirGlob.sync = sync;
exports.__moduleExports = dirGlob;
exports.default = dirGlob;
exports.sync = sync;
//# sourceMappingURL=index.js.map