summaryrefslogtreecommitdiff
path: root/cli/init.js
blob: 5a36509574cdfe7f216d79958a5fe5d5ac16a332 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const inquirer = require('inquirer');
const chalk = require('chalk');

const configDirPath = `${__dirname}/../.config`;
const configPath = `${configDirPath}/default.yml`;

const form = [{
	type: 'input',
	name: 'maintainerName',
	message: 'Your name:'
}, {
	type: 'input',
	name: 'maintainerUrl',
	message: 'Your home page URL or your mailto URL:'
}, {
	type: 'input',
	name: 'url',
	message: 'URL you want to run Misskey:',
	validate: function(wannabeurl) {
		return wannabeurl.match('^http\(s?\)://') ? true :
		       'URL needs to start with http:// or https://';
	}
}, {
	type: 'input',
	name: 'port',
	message: 'Listen port (e.g. 443):'
}, {
	type: 'confirm',
	name: 'https',
	message: 'Use TLS?',
	default: false
}, {
	type: 'input',
	name: 'https_key',
	message: 'Path of tls key:',
	when: ctx => ctx.https
}, {
	type: 'input',
	name: 'https_cert',
	message: 'Path of tls cert:',
	when: ctx => ctx.https
}, {
	type: 'input',
	name: 'https_ca',
	message: 'Path of tls ca:',
	when: ctx => ctx.https
}, {
	type: 'input',
	name: 'mongo_host',
	message: 'MongoDB\'s host:',
	default: 'localhost'
}, {
	type: 'input',
	name: 'mongo_port',
	message: 'MongoDB\'s port:',
	default: '27017'
}, {
	type: 'input',
	name: 'mongo_db',
	message: 'MongoDB\'s db:',
	default: 'misskey'
}, {
	type: 'input',
	name: 'mongo_user',
	message: 'MongoDB\'s user:'
}, {
	type: 'password',
	name: 'mongo_pass',
	message: 'MongoDB\'s password:'
}, {
	type: 'input',
	name: 'redis_host',
	message: 'Redis\'s host:',
	default: 'localhost'
}, {
	type: 'input',
	name: 'redis_port',
	message: 'Redis\'s port:',
	default: '6379'
}, {
	type: 'password',
	name: 'redis_pass',
	message: 'Redis\'s password:'
}, {
	type: 'confirm',
	name: 'elasticsearch',
	message: 'Use Elasticsearch?',
	default: false
}, {
	type: 'input',
	name: 'es_host',
	message: 'Elasticsearch\'s host:',
	default: 'localhost',
	when: ctx => ctx.elasticsearch
}, {
	type: 'input',
	name: 'es_port',
	message: 'Elasticsearch\'s port:',
	default: '9200',
	when: ctx => ctx.elasticsearch
}, {
	type: 'password',
	name: 'es_pass',
	message: 'Elasticsearch\'s password:',
	when: ctx => ctx.elasticsearch
}, {
	type: 'input',
	name: 'recaptcha_site',
	message: 'reCAPTCHA\'s site key:'
}, {
	type: 'input',
	name: 'recaptcha_secret',
	message: 'reCAPTCHA\'s secret key:'
}];

inquirer.prompt(form).then(as => {
	// Mapping answers
	const conf = {
		maintainer: {
			name: as['maintainerName'],
			url: as['maintainerUrl']
		},
		url: as['url'],
		port: parseInt(as['port'], 10),
		mongodb: {
			host: as['mongo_host'],
			port: parseInt(as['mongo_port'], 10),
			db: as['mongo_db'],
			user: as['mongo_user'],
			pass: as['mongo_pass']
		},
		redis: {
			host: as['redis_host'],
			port: parseInt(as['redis_port'], 10),
			pass: as['redis_pass']
		},
		elasticsearch: {
			enable: as['elasticsearch'],
			host: as['es_host'] || null,
			port: parseInt(as['es_port'], 10) || null,
			pass: as['es_pass'] || null
		},
		recaptcha: {
			site_key: as['recaptcha_site'],
			secret_key: as['recaptcha_secret']
		}
	};

	if (as['https']) {
		conf.https = {
			key: as['https_key'] || null,
			cert: as['https_cert'] || null,
			ca: as['https_ca'] || null
		};
	}

	console.log(`Thanks. Writing the configuration to ${chalk.bold(path.resolve(configPath))}`);

	try {
		fs.writeFileSync(configPath, yaml.dump(conf));
		console.log(chalk.green('Well done.'));
	} catch (e) {
		console.error(e);
	}
});