Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
];
// Avoid overwrite user files
const checkFiles = ["package.json", "config.js", "config.yml", "config.toml"];
checkFiles.forEach(file => {
if (fs.existsSync(path.join(outDir, file))) {
logger.error(`Make sure your destination directory is empty.\n${outDir}`);
process.exit(0);
}
});
// Prompt questions
if (fs.existsSync(outDir) && fs.readdirSync(outDir).length > 0) {
logger.warn("Remember to make sure your destination directory is empty.");
}
logger.info("Please answer the following questions:");
inquirer.prompt(questions).then(answers => {
const languageInfo = localeCode.getLanguages([answers.lang])[0];
const config = JSON.parse(
configTemplate({
options: {
title: answers.title,
name: slugify(answers.title),
description: answers.description,
language: {
code: languageInfo.code.split("-")[0],
iso: languageInfo.code,
name: languageInfo.nativeName
),
{ spaces: " " }
);
// .gitignore
fse.copySync(
path.join(__dirname, "init", "_gitignore"),
path.join(outDir, ".gitignore")
);
logger.success(
`A new project of Statusfy was successfully created at ${chalk.cyan(
outDir
)}`
);
logger.warn(
`Remember to run ${chalk.cyan(`${answers.packageManager} install`)}`
);
});
};
};
const content = generateIncident(
newMatter,
data.content,
config.content.frontMatterFormat
);
await fse.writeFile(localeIncidentPath, content);
updatedFiles.push(localeIncidentPath);
} catch (error) {
logger.error(error);
}
} else {
logger.warn(`This file couldn't be found:\n${localeIncidentPath}`);
}
}
if (updatedFiles.length > 0) {
const prefix =
updatedFiles.length === 1
? "This file was successfully updated"
: "These files were successfully updated";
logger.success(`${prefix}: \n${updatedFiles.join("\n")}`);
}
}
} catch (error) {
logger.fatal(error);
}
});
);
createdFiles.push(path.relative(contentPath, filePath));
if (answers.open) {
opener(filePath);
}
}
});
if (!error) {
logger.success(
`The Incident was successfully created.\n${createdFiles.join("\n")}`
);
} else {
logger.warn("There was an issue in creating the Incident.");
}
} catch (error) {
logger.fatal(error);
}
});
};
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
? "This file was successfully deleted"
: "These files were successfully deleted";
logger.success(`${prefix}: \n${deletedFiles.join("\n")}`);
}
}
} catch (error) {
logger.fatal(error);
}
});
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 fileName = path.relative(dirPath, filePath);
const fileContent = (await readFileP(filePath)).toString("utf8");
const incident = new Incident(fileContent, fileName).getData();