cleaner.ts 949 B

12345678910111213141516171819202122232425262728293031323334
  1. import { registerTSPaths } from '../../../server/helpers/register-ts-paths'
  2. registerTSPaths()
  3. import * as Promise from 'bluebird'
  4. import * as rimraf from 'rimraf'
  5. import { initDatabaseModels, sequelizeTypescript } from '../../../server/initializers/database'
  6. import { CONFIG } from '../../../server/initializers/config'
  7. initDatabaseModels(true)
  8. .then(() => {
  9. return sequelizeTypescript.drop()
  10. })
  11. .then(() => {
  12. console.info('Tables of %s deleted.', CONFIG.DATABASE.DBNAME)
  13. const STORAGE = CONFIG.STORAGE
  14. return Promise.mapSeries(Object.keys(STORAGE), storage => {
  15. const storageDir = STORAGE[storage]
  16. return new Promise((res, rej) => {
  17. rimraf(storageDir, err => {
  18. if (err) return rej(err)
  19. console.info('%s deleted.', storageDir)
  20. return res()
  21. })
  22. })
  23. })
  24. .then(() => process.exit(0))
  25. })
  26. .catch(err => {
  27. console.error(err)
  28. process.exit(-1)
  29. })