react-cosmos
Version:
Sandbox for developing and testing UI components in isolation
21 lines (20 loc) • 973 B
JavaScript
import { glob } from 'glob';
import micromatch from 'micromatch';
import { getDecoratorPatterns, getFixturePatterns, } from './shared.js';
export async function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
const paths = await glob('**/*', {
cwd: rootDir,
absolute: true,
ignore,
});
const fixturePatterns = getFixturePatterns(fixturesDir, fixtureFileSuffix);
const fixturePaths = getMatchingPaths(paths, fixturePatterns);
const decoratorPaths = getMatchingPaths(paths, getDecoratorPatterns());
// Omit decorators from fixture paths, which happens when decorators are
// placed inside fixture dirs.
const nonDecoratorFixturePaths = fixturePaths.filter(fixturePath => decoratorPaths.indexOf(fixturePath) === -1);
return { fixturePaths: nonDecoratorFixturePaths, decoratorPaths };
}
function getMatchingPaths(paths, patterns) {
return micromatch(paths, patterns, { dot: true });
}