/**
 * Created by axetroy on 17-2-15.
 */

const _ = require('lodash');
const Promise = require('bluebird');
const co = require('co');
const fs = Promise.promisifyAll(require('fs-extra'));
const config = require('./config');
const storage = require('node-persist');
const globalConfig = require('./global-config');

/**
 1. make sure root directory has exist
 2. make sure [temp, config] has exist
 3. make sure [config] must be a json file even it's empty
 */
module.exports = function (options) {
  return co(function *() {
    yield fs.ensureDirAsync(config.paths.root);

    yield [
      fs.ensureDirAsync(config.paths.temp),
      yield globalConfig.init()
    ];

    yield storage.init({
      dir: config.paths.storage,
      stringify: JSON.stringify,
      parse: JSON.parse,
      encoding: 'utf8',
      logging: false,  // can also be custom logging function
      continuous: true, // continously persist to disk
      interval: false, // milliseconds, persist to disk on an interval
      ttl: false, // ttl* [NEW], can be true for 24h default or a number in MILLISECONDS
      expiredInterval: 7 * 24 * 3600 * 1000,     // clear cache in 7 days
      // in some cases, you (or some other service) might add non-valid storage files to your
      // storage dir, i.e. Google Drive, make this true if you'd like to ignore these files and not throw an error
      forgiveParseErrors: false // [NEW]
    });

  });
};

@@ -40,37 +40,8 @@
 */%0A%0A
-const _ = require('lodash');%0A
 cons
@@ -69,24 +69,24 @@
 bluebird');%0A
+
 const co = r
@@ -538,17 +538,16 @@
 .root);%0A
-%0A
     yiel
@@ -629,26 +629,15 @@
 it()
+,
 %0A    
-%5D;%0A%0A    yield
+ 
  sto
@@ -648,16 +648,18 @@
 .init(%7B%0A
+  
       di
@@ -689,16 +689,18 @@
 ,%0A      
+  
 stringif
@@ -724,16 +724,18 @@
 ,%0A      
+ 
+ 
 parse: J
@@ -751,16 +751,18 @@
 ,%0A      
+  
 encoding
@@ -771,16 +771,18 @@
 'utf8',%0A
+  
       lo
@@ -841,16 +841,18 @@
 n%0A      
+  
 continuo
@@ -892,16 +892,18 @@
 to disk%0A
+  
       in
@@ -965,16 +965,18 @@
 nterval%0A
+  
       tt
@@ -1062,16 +1062,18 @@
 S%0A      
+  
 expiredI
@@ -1132,16 +1132,18 @@
  7 days%0A
+  
       //
@@ -1228,16 +1228,18 @@
 to your%0A
+  
       //
@@ -1351,16 +1351,18 @@
 r%0A      
+  
 forgiveP
@@ -1392,20 +1392,27 @@
 EW%5D%0A    
-%7D);%0A
+  %7D)%0A    %5D;
 %0A  %7D);%0A%7D

refactor prepare working