2016-12-28 14:49:51 -08:00
|
|
|
const fs = require('fs');
|
2017-05-24 21:15:16 -07:00
|
|
|
const path = require('path');
|
2016-12-28 14:49:51 -08:00
|
|
|
const yaml = require('js-yaml');
|
|
|
|
const inquirer = require('inquirer');
|
2017-05-24 21:15:16 -07:00
|
|
|
const chalk = require('chalk');
|
2016-12-28 14:49:51 -08:00
|
|
|
|
2017-01-13 18:05:21 -08:00
|
|
|
const configDirPath = `${__dirname}/../.config`;
|
2017-01-16 15:37:24 -08:00
|
|
|
const configPath = `${configDirPath}/default.yml`;
|
2016-12-28 14:49:51 -08:00
|
|
|
|
2018-04-01 19:25:31 -07:00
|
|
|
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:'
|
|
|
|
}, {
|
|
|
|
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:'
|
|
|
|
}];
|
2016-12-28 14:49:51 -08:00
|
|
|
|
|
|
|
inquirer.prompt(form).then(as => {
|
|
|
|
// Mapping answers
|
|
|
|
const conf = {
|
2018-04-01 19:25:31 -07:00
|
|
|
maintainer: {
|
|
|
|
name: as['maintainerName'],
|
|
|
|
url: as['maintainerUrl']
|
|
|
|
},
|
2016-12-28 14:49:51 -08:00
|
|
|
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: {
|
2018-04-21 18:14:25 -07:00
|
|
|
site_key: as['recaptcha_site'],
|
|
|
|
secret_key: as['recaptcha_secret']
|
2016-12-28 14:49:51 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-15 01:29:32 -07:00
|
|
|
if (as['https']) {
|
|
|
|
conf.https = {
|
|
|
|
key: as['https_key'] || null,
|
|
|
|
cert: as['https_cert'] || null,
|
|
|
|
ca: as['https_ca'] || null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-05-24 21:15:16 -07:00
|
|
|
console.log(`Thanks. Writing the configuration to ${chalk.bold(path.resolve(configPath))}`);
|
2016-12-28 14:49:51 -08:00
|
|
|
|
|
|
|
try {
|
|
|
|
fs.writeFileSync(configPath, yaml.dump(conf));
|
2017-05-24 21:15:16 -07:00
|
|
|
console.log(chalk.green('Well done.'));
|
2016-12-28 14:49:51 -08:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
});
|