From 82221ac920ad2e6bafc742a09fa1636899d4173e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 13 Oct 2016 21:45:23 +0200 Subject: Update clean script --- scripts/danger/clean/cleaner.js | 23 +++++++++++++++++++++++ scripts/danger/clean/dev.sh | 7 +++++++ scripts/danger/clean/modules.sh | 2 +- scripts/danger/clean/prod.sh | 7 +++++++ scripts/danger/clean/server.sh | 8 -------- 5 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 scripts/danger/clean/cleaner.js create mode 100755 scripts/danger/clean/dev.sh create mode 100755 scripts/danger/clean/prod.sh delete mode 100755 scripts/danger/clean/server.sh (limited to 'scripts/danger/clean') diff --git a/scripts/danger/clean/cleaner.js b/scripts/danger/clean/cleaner.js new file mode 100644 index 000000000..a63c478e0 --- /dev/null +++ b/scripts/danger/clean/cleaner.js @@ -0,0 +1,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) + }) +}) diff --git a/scripts/danger/clean/dev.sh b/scripts/danger/clean/dev.sh new file mode 100755 index 000000000..5f09565cf --- /dev/null +++ b/scripts/danger/clean/dev.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +read -p "This will remove all directories and Mongo database. Are you sure? " -n 1 -r + +if [[ "$REPLY" =~ ^[Yy]$ ]]; then + NODE_ENV=test node "./scripts/danger/clean/cleaner" +fi diff --git a/scripts/danger/clean/modules.sh b/scripts/danger/clean/modules.sh index 429044b3f..99555a693 100755 --- a/scripts/danger/clean/modules.sh +++ b/scripts/danger/clean/modules.sh @@ -1,6 +1,6 @@ #!/bin/bash -read -p "This will remove all node and typescript modules. Are you sure? " -n 1 -r +read -p "This will remove all node server and client modules. Are you sure? " -n 1 -r if [[ "$REPLY" =~ ^[Yy]$ ]]; then rm -rf node_modules client/node_modules diff --git a/scripts/danger/clean/prod.sh b/scripts/danger/clean/prod.sh new file mode 100755 index 000000000..e6c92671d --- /dev/null +++ b/scripts/danger/clean/prod.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +read -p "This will remove all directories and Mongo database. Are you sure? " -n 1 -r + +if [[ "$REPLY" =~ ^[Yy]$ ]]; then + NODE_ENV=production node "./scripts/danger/clean/cleaner" +fi diff --git a/scripts/danger/clean/server.sh b/scripts/danger/clean/server.sh deleted file mode 100755 index 1a0576112..000000000 --- a/scripts/danger/clean/server.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -read -p "This will remove certs, uploads, database (dev) and logs. Are you sure? " -n 1 -r - -if [[ "$REPLY" =~ ^[Yy]$ ]]; then - rm -rf ./certs ./logs ./uploads - printf "use peertube-dev;\ndb.dropDatabase();" | mongo -fi -- cgit v1.2.3