-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
116 lines (96 loc) · 3.39 KB
/
install.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import Bcrypt from 'bcrypt';
import Prompt from 'prompt';
import DotEnv from 'dotenv';
import Post from './app/model/post';
import User from './app/model/user';
import Tag from './app/model/tag';
import Image from './app/model/image';
import Content from './app/model/content';
import Page from './app/model/page';
import Db from './app/database';
DotEnv.config();
console.log('\x1b[47m\x1b[35m', 'ribbon Setup', '\x1b[0m');
/*
* Check if a user exists in the database.
*/
const query = User.find({});
query.exec(async (find_err, find_results) => {
if (find_results.length > 0) {
console.log('\x1b[47m\x1b[31m', 'ribbon is already installed.', '\x1b[0m');
process.exit();
} else {
console.log('\x1b[47m\x1b[30m', 'Administration Details', '\x1b[0m');
Prompt.start();
const Schema = {
properties: {
username: {
description: 'Enter your username',
required: true,
default: 'admin',
},
email: {
description: 'Enter your email',
required: true,
default: '[email protected]',
},
password: {
description: 'Enter your password',
required: true,
hidden: true,
replace: '*',
default: 'password',
},
},
};
Prompt.get(Schema, async (prompt_err, prompt) => {
// Add admin authentication details.
const new_user = await new User({
username: prompt.username,
password: await Bcrypt.hash(prompt.password, parseInt(process.env.HASH_SALT_ROUNDS, 10)),
email: prompt.email,
group: 1,
}).save();
// Add first page.
const new_page = await new Page({
title: 'First Page',
url: 'First-Page',
description: 'This is the first page for the website!',
created_by: Db.Types.ObjectId(new_user.id),
image: null,
}).save();
// Add content boxes for the first page.
const content = await new Content({
title: 'First Box',
content: 'First box contents.',
page_id: Db.Types.ObjectId(new_page._id),
content_column: 3,
created_by: Db.Types.ObjectId(new_user.id),
}).save();
// Add default image into database.
const image = await new Image({
title: 'photo-1499336315816-097655dcfbda.jpg',
file_name: 'photo-1499336315816-097655dcfbda.jpg',
created_by: Db.Types.ObjectId(new_user.id),
}).save();
// Add first tag into database.
const new_tag = await new Tag({
title: 'Example Tag',
url: 'Example-Tag',
content: 'A tag for blog entries.',
}).save();
// Add first post into database.
const post = await new Post({
title: 'First Post',
url: 'First-Post',
content: 'This is the first post for the blog!',
image: Db.Types.ObjectId(image._id),
created_by: Db.Types.ObjectId(new_user._id),
tag: Db.Types.ObjectId(new_tag._id),
}).save();
console.log('\x1b[42m\x1b[30m', 'Installation successful.', '\x1b[0m');
console.log('\x1b[42m\x1b[30m', 'You need to get the arabesque administrator panel by visiting https://github.com/jtpox/arabesque', '\x1b[0m');
console.log('\x1b[42m\x1b[30m', `Access the administrators panel by visiting '<website_url>/ribbon' and logging in using the email '${prompt.email}'.`, '\x1b[0m');
process.exit();
});
}
});