Other example scripts
Test and Storybook coverage
const { promises: fs, constants: fsConstants } = require("fs");
const path = require("path");
const fileLookupCache = new Map();
async function exists(filePath) {
const absPath = path.resolve(__dirname, filePath);
if (fileLookupCache.has(absPath)) {
return fileLookupCache.get(absPath);
}
try {
await fs.access(absPath, fsConstants.F_OK);
fileLookupCache.set(absPath, true);
return true;
} catch {
fileLookupCache.set(absPath, false);
return false;
}
}
function hasTests(filePath) {
const testFilePath = filePath.replace(/(.)(\.[jt]sx?)$/, "$1.test$2");
return exists(testFilePath);
}
function hasStories(filePath) {
const testFilePath = filePath.replace(/(.)(\.[jt]sx?)$/, "$1.stories$2");
return exists(testFilePath);
}
/**
* @type {import('@omlet/cli').CliHookModule}
*/
module.exports = {
async afterScan(components) {
for (const component of components) {
component.setMetadata("hasStories", await hasStories(component.filePath));
component.setMetadata("hasTests", await hasTests(component.filePath));
}
}
}Visual components
Deprecated components
Last updated