aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/danger/clean/cleaner.ts
blob: a22e2ed6aff475ccb8d54f735d2066a4edd052cb (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
26
import * as Promise from 'bluebird'
import * as rimraf from 'rimraf'
import { CONFIG, initDatabase, sequelizeTypescript } from '../../../server/initializers'

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

    const STORAGE = CONFIG.STORAGE
    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))
  })