forked from colmena/colmena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-load-settings.js
More file actions
63 lines (54 loc) · 1.26 KB
/
01-load-settings.js
File metadata and controls
63 lines (54 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict'
import { default as debug } from 'debug'
// to enable these logs set `DEBUG=boot:01-load-settings` or `DEBUG=boot:*`
const log = debug('boot:01-load-settings')
module.exports = function (app) {
// Do not run if we are in codegen mode.
if (process.env.ENV === 'codegen') return
const Setting = app.models.Setting
function loadDefaultSettings () {
console.error('Creating default settings')
const settings = [ {
type: 'string',
key: 'appName',
value: 'LoopBack Admin',
}, {
type: 'select',
key: 'appTheme',
value: 'skin-blue',
options: [
'skin-blue',
'skin-black',
],
}, {
type: 'select',
key: 'appLayout',
value: 'fixed',
options: [
'skin-blue',
'not-fixed',
],
} ]
settings.forEach((setting) => {
Setting.create(setting, (err) => {
if (err) {
console.error(err)
}
})
})
}
function loadExistingSettings () {
console.error('Loading existing settings')
Setting.find((data) => log(data))
}
Setting.count((err, result) => {
if (err) {
console.error(err)
}
if (result < 1) {
loadDefaultSettings()
} else {
loadExistingSettings()
}
})
}