aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/danger/clean/cleaner.ts
blob: d1dba46509ef3826930be076df224ec0c8f921d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import * as eachSeries from 'async/eachSeries'
import * as rimraf from 'rimraf'

import { CONFIG } from '../../../server/initializers/constants'
import { database as db } from '../../../server/initializers/database'

db.init(true, function () {
  db.sequelize.drop().asCallback(function (err) {
    if (err) throw err

    console.info('Tables of %s deleted.', CONFIG.DATABASE.DBNAME)

    const STORAGE = CONFIG.STORAGE
    eachSeries(Object.keys(STORAGE), function (storage, callbackEach) {
      const storageDir = STORAGE[storage]

      rimraf(storageDir, function (err) {
        console.info('%s deleted.', storageDir)
        return callbackEach(err)
      })
    }, function () {
      process.exit(0)
    })
  })
})