aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/danger/clean/cleaner.js
blob: a63c478e035f4b017b78c8cc1f7b30648c8c69c0 (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
const rimraf = require('rimraf')
const mongoose = require('mongoose')

const constants = require('../../../server/initializers/constants')

const mongodbUrl = 'mongodb://' + constants.CONFIG.DATABASE.HOST + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME
mongoose.connect(mongodbUrl, function () {
  console.info('Deleting MongoDB %s database.', constants.CONFIG.DATABASE.DBNAME)
  mongoose.connection.db.dropDatabase(function () {
    mongoose.connection.close()
  })
})

const STORAGE = constants.CONFIG.STORAGE
Object.keys(STORAGE).forEach(function (storage) {
  const storageDir = STORAGE[storage]

  rimraf(storageDir, function (err) {
    if (err) throw err

    console.info('Deleting %s.', storageDir)
  })
})