diff options
Diffstat (limited to 'scripts/danger')
-rw-r--r-- | scripts/danger/clean/cleaner.js | 31 | ||||
-rwxr-xr-x | scripts/danger/clean/dev.sh | 3 | ||||
-rwxr-xr-x | scripts/danger/clean/prod.sh | 3 |
3 files changed, 20 insertions, 17 deletions
diff --git a/scripts/danger/clean/cleaner.js b/scripts/danger/clean/cleaner.js index 10e91e700..1a1e3dee7 100644 --- a/scripts/danger/clean/cleaner.js +++ b/scripts/danger/clean/cleaner.js | |||
@@ -1,24 +1,25 @@ | |||
1 | const eachSeries = require('async/eachSeries') | ||
1 | const rimraf = require('rimraf') | 2 | const rimraf = require('rimraf') |
2 | const mongoose = require('mongoose') | ||
3 | mongoose.Promise = global.Promise | ||
4 | 3 | ||
5 | const constants = require('../../../server/initializers/constants') | 4 | const constants = require('../../../server/initializers/constants') |
5 | const db = require('../../../server/initializers/database') | ||
6 | 6 | ||
7 | const mongodbUrl = 'mongodb://' + constants.CONFIG.DATABASE.HOSTNAME + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME | 7 | db.init(true, function () { |
8 | mongoose.connect(mongodbUrl, function () { | 8 | db.sequelize.drop().asCallback(function (err) { |
9 | console.info('Deleting MongoDB %s database.', constants.CONFIG.DATABASE.DBNAME) | 9 | if (err) throw err |
10 | mongoose.connection.dropDatabase(function () { | ||
11 | mongoose.connection.close() | ||
12 | }) | ||
13 | }) | ||
14 | 10 | ||
15 | const STORAGE = constants.CONFIG.STORAGE | 11 | console.info('Tables of %s deleted.', db.sequelize.config.database) |
16 | Object.keys(STORAGE).forEach(function (storage) { | ||
17 | const storageDir = STORAGE[storage] | ||
18 | 12 | ||
19 | rimraf(storageDir, function (err) { | 13 | const STORAGE = constants.CONFIG.STORAGE |
20 | if (err) throw err | 14 | eachSeries(Object.keys(STORAGE), function (storage, callbackEach) { |
15 | const storageDir = STORAGE[storage] | ||
21 | 16 | ||
22 | console.info('Deleting %s.', storageDir) | 17 | rimraf(storageDir, function (err) { |
18 | console.info('%s deleted.', storageDir) | ||
19 | return callbackEach(err) | ||
20 | }) | ||
21 | }, function () { | ||
22 | process.exit(0) | ||
23 | }) | ||
23 | }) | 24 | }) |
24 | }) | 25 | }) |
diff --git a/scripts/danger/clean/dev.sh b/scripts/danger/clean/dev.sh index 5f09565cf..f4a5d1e8a 100755 --- a/scripts/danger/clean/dev.sh +++ b/scripts/danger/clean/dev.sh | |||
@@ -1,6 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | read -p "This will remove all directories and Mongo database. Are you sure? " -n 1 -r | 3 | read -p "This will remove all directories and SQL tables. Are you sure? (y/*) " -n 1 -r |
4 | echo | ||
4 | 5 | ||
5 | if [[ "$REPLY" =~ ^[Yy]$ ]]; then | 6 | if [[ "$REPLY" =~ ^[Yy]$ ]]; then |
6 | NODE_ENV=test node "./scripts/danger/clean/cleaner" | 7 | NODE_ENV=test node "./scripts/danger/clean/cleaner" |
diff --git a/scripts/danger/clean/prod.sh b/scripts/danger/clean/prod.sh index e6c92671d..7ee13ba83 100755 --- a/scripts/danger/clean/prod.sh +++ b/scripts/danger/clean/prod.sh | |||
@@ -1,6 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | read -p "This will remove all directories and Mongo database. Are you sure? " -n 1 -r | 3 | read -p "This will remove all directories and SQL tables. Are you sure? (y/*) " -n 1 -r |
4 | echo | ||
4 | 5 | ||
5 | if [[ "$REPLY" =~ ^[Yy]$ ]]; then | 6 | if [[ "$REPLY" =~ ^[Yy]$ ]]; then |
6 | NODE_ENV=production node "./scripts/danger/clean/cleaner" | 7 | NODE_ENV=production node "./scripts/danger/clean/cleaner" |