Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const authorDirectory = path.join(__dirname, 'authors')
const postsDirectory = path.join(__dirname, 'posts')
const dateFormatRegex = /[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])-/g
// Example shape of author data
const authorData = {
"name": "David Wells",
"github": "davidwells",
"avatar": "https://avatars2.githubusercontent.com/u/532272?v=3&s=60",
"bio": {
"short": "David Wells is a developer at Serverless, Inc.",
"long": "David is a Full Stack JavaScript Developer, entrepreneur, past life marketer. Developer @ http://serverless.com "
}
}
const authorArray = fs.readdirSync(authorDirectory).map((author) =>{
return author.replace('.json', '')
})
// test author directory
globby(['*', '!node_modules'], {
cwd: authorDirectory
}).then(paths => {
paths.forEach((file) => {
const fp = path.join(authorDirectory, file)
if (file.match(/\.json/)) {
const author = fs.readFileSync(fp, 'utf8')
const valid = hasSameProps(authorData, JSON.parse(author))
if (!valid) {
const msg = `${file} has missing value in author profile.
Author data must match (if no value applies use false):