Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const readFileIncidents = async dirPath => {
const allIncidents = [];
const exists = await fse.pathExists(dirPath);
if (!exists) {
logger.warn(`Content Directory not found: ${dirPath}`);
} else {
try {
const files = (await readdirP(dirPath)).map(f => path.join(dirPath, f));
for (let i = 0; i < files.length; i++) {
const filePath = files[i];
const isFile = (await statP(filePath)).isFile();
if (
isFile &&
path.extname(filePath) === ".md" &&
path.basename(filePath).toLowerCase() !== "readme.md"
) {
const { incident, resolved, severity, affectedsystems, confirm } = answers;
try {
if (confirm) {
const modified = dates.parse().toISOString();
const locales = config.locales.map(l => l.code);
const updatedFiles = [];
for (let j = 0; j < locales.length; j++) {
const locale = locales[j];
const localeIncidentPath = path.join(
contentDir,
config.defaultLocale !== locale ? locale : "",
incident.name
);
const exists = await fse.pathExists(localeIncidentPath);
if (exists) {
try {
const data = await getIncidentData(localeIncidentPath);
const newMatter = {
...data.data,
modified,
severity,
affectedsystems,
resolved
};
const content = generateIncident(
newMatter,
data.content,
config.content.frontMatterFormat
inquirer.prompt(questions).then(async answers => {
const { incident, confirm } = answers;
try {
if (confirm) {
const locales = config.locales.map(l => l.code);
const deletedFiles = [];
for (let j = 0; j < locales.length; j++) {
const locale = locales[j];
const localeIncidentPath = path.join(
contentDir,
config.defaultLocale !== locale ? locale : "",
incident.name
);
const exists = await fse.pathExists(localeIncidentPath);
if (exists) {
try {
await fse.remove(localeIncidentPath);
deletedFiles.push(localeIncidentPath);
} catch (error) {
logger.error(error);
}
} else {
logger.warn(`This file couldn't be found:\n${localeIncidentPath}`);
}
}
if (deletedFiles.length > 0) {
const prefix =
deletedFiles.length === 1