aboutsummaryrefslogblamecommitdiffhomepage
path: root/scripts/danger/clean/cleaner.ts
blob: 69e8a63a0de7c3d5cdaf6a639fc478d72d8a992c (plain) (tree)
1
2
3
4
5
6
7
8
9

                                                                           
                                   
                                
                                                                                               
                                                            
 
                        
               
                                     
               
                                                                 
 
                                  
                                                               
                                         
                                        
                                   



                                                 
        
                                
    


                      
import { registerTSPaths } from '../../../server/helpers/register-ts-paths'
registerTSPaths()

import * as Promise from 'bluebird'
import * as rimraf from 'rimraf'
import { initDatabaseModels, sequelizeTypescript } from '../../../server/initializers/database'
import { CONFIG } from '../../../server/initializers/config'

initDatabaseModels(true)
  .then(() => {
    return sequelizeTypescript.drop()
  })
  .then(() => {
    console.info('Tables of %s deleted.', CONFIG.DATABASE.DBNAME)

    const STORAGE = CONFIG.STORAGE
    return Promise.mapSeries(Object.keys(STORAGE), storage => {
      const storageDir = STORAGE[storage]

      return new Promise((res, rej) => {
        rimraf(storageDir, err => {
          if (err) return rej(err)

          console.info('%s deleted.', storageDir)
          return res()
        })
      })
    })
    .then(() => process.exit(0))
  })
  .catch(err => {
    console.error(err)
    process.exit(-1)
  })