PeerTube/scripts/danger/clean/cleaner.ts

35 lines
949 B
TypeScript
Raw Normal View History

import { registerTSPaths } from '../../../server/helpers/register-ts-paths'
registerTSPaths()
import * as Promise from 'bluebird'
2017-12-12 10:53:50 -06:00
import * as rimraf from 'rimraf'
2020-05-07 07:58:24 -05:00
import { initDatabaseModels, sequelizeTypescript } from '../../../server/initializers/database'
import { CONFIG } from '../../../server/initializers/config'
2016-10-13 14:45:23 -05:00
2017-12-13 10:46:23 -06:00
initDatabaseModels(true)
.then(() => {
2017-12-12 10:53:50 -06:00
return sequelizeTypescript.drop()
})
.then(() => {
2017-06-11 08:19:43 -05:00
console.info('Tables of %s deleted.', CONFIG.DATABASE.DBNAME)
2016-10-13 14:45:23 -05:00
2017-06-11 08:19:43 -05:00
const STORAGE = CONFIG.STORAGE
2020-07-30 07:54:31 -05:00
return Promise.mapSeries(Object.keys(STORAGE), storage => {
2016-12-25 02:44:13 -06:00
const storageDir = STORAGE[storage]
return new Promise((res, rej) => {
2017-09-07 08:27:35 -05:00
rimraf(storageDir, err => {
if (err) return rej(err)
console.info('%s deleted.', storageDir)
return res()
})
2016-12-25 02:44:13 -06:00
})
})
.then(() => process.exit(0))
2016-10-13 14:45:23 -05:00
})
2020-07-30 07:54:31 -05:00
.catch(err => {
console.error(err)
process.exit(-1)
})