Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getIncidentsFromProject = async contentDir => {
const files = await fse.readdir(contentDir);
const incidentsList = [];
for (let i = 0; i < files.length; i++) {
const f = path.resolve(contentDir, files[i]);
const ext = path.extname(f);
const fileName = path.basename(f);
if (ext === ".md") {
const fileContent = await fse.readFile(f);
const { data } = grayMatter.parse(fileContent);
incidentsList.push({
value: {
name: fileName,
path: f
},
name: `${fileName} > ${chalk.yellow(data.title)} (${chalk.green(
new Date(data.date).toUTCString()
)})`
});
}
}
return incidentsList;
};
const getIncidentData = async filePath => {
const key = `data:${filePath}`;
let data = cache.get(key);
if (!data) {
const fileContent = await fse.readFile(filePath);
data = grayMatter.parse(fileContent);
cache.set(key, data);
}
return data;
};