lasso
Version:
Lasso.js is a build tool and runtime library for building and bundling all of the resources needed by a web application
39 lines (28 loc) • 1.08 kB
JavaScript
const nodePath = require('path');
const glob = require('util').promisify(require('glob'));
const globRegExp = /[*?+{}]/;
async function globNormalizer (dependency, context) {
if (typeof dependency === 'string' && globRegExp.test(dependency)) {
const typeSeparator = dependency.indexOf(':');
const basedir = context.dirname;
let pattern = dependency;
let type = null;
let matches = [];
if (typeSeparator) {
type = dependency.substring(0, typeSeparator).trim();
pattern = dependency.substring(typeSeparator + 1);
}
pattern = pattern.trim();
const patterns = pattern.split(/\s+/);
for (const pattern of patterns) {
const files = await glob(pattern, { cwd: basedir });
matches = matches.concat(files);
}
matches = matches.map((match) => {
match = nodePath.join(basedir, match);
return type ? type + ':' + match : match;
});
return matches;
}
}
exports.normalizer = globNormalizer;