/**
 * @file Check service availability
 * @author xuexb <fe.xiaowu@gmail.com>
 */

const path = require('path');
const fs = require('fs');
const jsonPath = path.resolve(__dirname, '../public/content.json');

let isError = false;

const exit = str => {
  isError = true;
  console.error(str);
};

if (!fs.existsSync(jsonPath)) {
  exit(`\`${jsonPath}\` is not a file!`);
}

let data;

try {
  data = require(jsonPath);
}
catch (e) {
  exit(e);
}

// check common config
if (!data.meta) {
  exit('`config.meta` can not be empty!');
}
[
  'title',
  'subtitle',
  'description',
  'author',
  'url'
].forEach(key => {
  if (!data.meta[key]) {
    exit(`\`config.${key}\` can not be empty!`);
  }
});


[
  'title',
  'desc',
  'author',
  {
    key: 'excerpt',
    tip: '<!--more-->'
  }
].forEach(val => {
  if ('string' === typeof val) {
    val = {
      key: val
    };
  }

  data.posts.forEach(post => {
    if (!post[val.key]) {
      let tip = val.tip || `\`post.${val.key}\``;
      exit(`${tip} in the \`${post.path}\` must be set!`);
    }
  });
});


if (isError) {
  process.exit(1);
}

@@ -237,19 +237,29 @@
  exit = 
+(
 str
+, isExit)
  =%3E %7B%0A  
@@ -295,16 +295,58 @@
 or(str);
+%0A%0A  if (isExit) %7B%0A    process.exit(1);%0A  %7D
 %0A%7D;%0A%0Aif 
@@ -413,16 +413,22 @@
 a file!%60
+, true
 );%0A%7D%0A%0Ale
@@ -584,18 +584,29 @@
 y!');%0A%7D%0A
-%5B%0A
+else %7B%0A  %5B%0A  
   'title
@@ -610,16 +610,18 @@
 tle',%0A  
+ 
+ 
 'subtitl
@@ -620,24 +620,26 @@
 'subtitle',%0A
+  
   'descripti
@@ -641,24 +641,26 @@
 ription',%0A  
+ 
+ 
 'author',%0A  
@@ -661,16 +661,18 @@
 r',%0A
+  
   'url'%0A
 %5D.fo
@@ -667,16 +667,18 @@
   'url'%0A
+  
 %5D.forEac
@@ -684,24 +684,26 @@
 ch(key =%3E %7B%0A
+  
   if (!data.
@@ -715,24 +715,26 @@
 key%5D) %7B%0A    
+ 
+ 
 exit(%60%5C%60conf
@@ -772,14 +772,20 @@
 ;%0A  
-%7D%0A
+  %7D%0A  
 %7D);%0A
+%7D%0A
 %0A%0A%5B%0A

Fix config.meta bug