diff options
Diffstat (limited to 'server/initializers/installer.ts')
-rw-r--r-- | server/initializers/installer.ts | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 1ec24c4ad..3c5a77df9 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts | |||
@@ -4,12 +4,13 @@ import * as passwordGenerator from 'password-generator' | |||
4 | import * as Promise from 'bluebird' | 4 | import * as Promise from 'bluebird' |
5 | 5 | ||
6 | import { database as db } from './database' | 6 | import { database as db } from './database' |
7 | import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION } from './constants' | 7 | import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION, CACHE } from './constants' |
8 | import { clientsExist, usersExist } from './checker' | 8 | import { clientsExist, usersExist } from './checker' |
9 | import { logger, createCertsIfNotExist, root, mkdirpPromise } from '../helpers' | 9 | import { logger, createCertsIfNotExist, root, mkdirpPromise, rimrafPromise } from '../helpers' |
10 | 10 | ||
11 | function installApplication () { | 11 | function installApplication () { |
12 | return db.sequelize.sync() | 12 | return db.sequelize.sync() |
13 | .then(() => removeCacheDirectories()) | ||
13 | .then(() => createDirectoriesIfNotExist()) | 14 | .then(() => createDirectoriesIfNotExist()) |
14 | .then(() => createCertsIfNotExist()) | 15 | .then(() => createCertsIfNotExist()) |
15 | .then(() => createOAuthClientIfNotExist()) | 16 | .then(() => createOAuthClientIfNotExist()) |
@@ -24,13 +25,34 @@ export { | |||
24 | 25 | ||
25 | // --------------------------------------------------------------------------- | 26 | // --------------------------------------------------------------------------- |
26 | 27 | ||
28 | function removeCacheDirectories () { | ||
29 | const cacheDirectories = CACHE.DIRECTORIES | ||
30 | |||
31 | const tasks = [] | ||
32 | |||
33 | // Cache directories | ||
34 | Object.keys(cacheDirectories).forEach(key => { | ||
35 | const dir = cacheDirectories[key] | ||
36 | tasks.push(rimrafPromise(dir)) | ||
37 | }) | ||
38 | |||
39 | return Promise.all(tasks) | ||
40 | } | ||
41 | |||
27 | function createDirectoriesIfNotExist () { | 42 | function createDirectoriesIfNotExist () { |
28 | const storages = config.get('storage') | 43 | const storages = CONFIG.STORAGE |
44 | const cacheDirectories = CACHE.DIRECTORIES | ||
29 | 45 | ||
30 | const tasks = [] | 46 | const tasks = [] |
31 | Object.keys(storages).forEach(key => { | 47 | Object.keys(storages).forEach(key => { |
32 | const dir = storages[key] | 48 | const dir = storages[key] |
33 | tasks.push(mkdirpPromise(join(root(), dir))) | 49 | tasks.push(mkdirpPromise(dir)) |
50 | }) | ||
51 | |||
52 | // Cache directories | ||
53 | Object.keys(cacheDirectories).forEach(key => { | ||
54 | const dir = cacheDirectories[key] | ||
55 | tasks.push(mkdirpPromise(dir)) | ||
34 | }) | 56 | }) |
35 | 57 | ||
36 | return Promise.all(tasks) | 58 | return Promise.all(tasks) |