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

                                    
                                 


                                                                   
                                                                                                                                                    

                                                                                 
                                                













                                                 
const rimraf = require('rimraf')
const mongoose = require('mongoose')
mongoose.Promise = global.Promise

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

const mongodbUrl = 'mongodb://' + constants.CONFIG.DATABASE.HOSTNAME + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME
mongoose.connect(mongodbUrl, function () {
  console.info('Deleting MongoDB %s database.', constants.CONFIG.DATABASE.DBNAME)
  mongoose.connection.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)
  })
})