Fix config init script

This commit is contained in:
syuilo 2018-04-02 11:25:31 +09:00
parent 21ebd9a367
commit 85134b513d
1 changed files with 108 additions and 130 deletions

View File

@ -7,140 +7,119 @@ const chalk = require('chalk');
const configDirPath = `${__dirname}/../.config`; const configDirPath = `${__dirname}/../.config`;
const configPath = `${configDirPath}/default.yml`; const configPath = `${configDirPath}/default.yml`;
const form = [ const form = [{
{
type: 'input', type: 'input',
name: 'maintainer', name: 'maintainerName',
message: 'Maintainer name(and email address):' message: 'Your name:'
}, }, {
{ type: 'input',
name: 'maintainerUrl',
message: 'Your home page URL or your mailto URL:'
}, {
type: 'input', type: 'input',
name: 'url', name: 'url',
message: 'PRIMARY URL:' message: 'URL you want to run Misskey:'
}, }, {
{
type: 'input',
name: 'secondary_url',
message: 'SECONDARY URL:'
},
{
type: 'input', type: 'input',
name: 'port', name: 'port',
message: 'Listen port:' message: 'Listen port (e.g. 443):'
}, }, {
{
type: 'confirm', type: 'confirm',
name: 'https', name: 'https',
message: 'Use TLS?', message: 'Use TLS?',
default: false default: false
}, }, {
{
type: 'input', type: 'input',
name: 'https_key', name: 'https_key',
message: 'Path of tls key:', message: 'Path of tls key:',
when: ctx => ctx.https when: ctx => ctx.https
}, }, {
{
type: 'input', type: 'input',
name: 'https_cert', name: 'https_cert',
message: 'Path of tls cert:', message: 'Path of tls cert:',
when: ctx => ctx.https when: ctx => ctx.https
}, }, {
{
type: 'input', type: 'input',
name: 'https_ca', name: 'https_ca',
message: 'Path of tls ca:', message: 'Path of tls ca:',
when: ctx => ctx.https when: ctx => ctx.https
}, }, {
{
type: 'input', type: 'input',
name: 'mongo_host', name: 'mongo_host',
message: 'MongoDB\'s host:', message: 'MongoDB\'s host:',
default: 'localhost' default: 'localhost'
}, }, {
{
type: 'input', type: 'input',
name: 'mongo_port', name: 'mongo_port',
message: 'MongoDB\'s port:', message: 'MongoDB\'s port:',
default: '27017' default: '27017'
}, }, {
{
type: 'input', type: 'input',
name: 'mongo_db', name: 'mongo_db',
message: 'MongoDB\'s db:', message: 'MongoDB\'s db:',
default: 'misskey' default: 'misskey'
}, }, {
{
type: 'input', type: 'input',
name: 'mongo_user', name: 'mongo_user',
message: 'MongoDB\'s user:' message: 'MongoDB\'s user:'
}, }, {
{
type: 'password', type: 'password',
name: 'mongo_pass', name: 'mongo_pass',
message: 'MongoDB\'s password:' message: 'MongoDB\'s password:'
}, }, {
{
type: 'input', type: 'input',
name: 'redis_host', name: 'redis_host',
message: 'Redis\'s host:', message: 'Redis\'s host:',
default: 'localhost' default: 'localhost'
}, }, {
{
type: 'input', type: 'input',
name: 'redis_port', name: 'redis_port',
message: 'Redis\'s port:', message: 'Redis\'s port:',
default: '6379' default: '6379'
}, }, {
{
type: 'password', type: 'password',
name: 'redis_pass', name: 'redis_pass',
message: 'Redis\'s password:' message: 'Redis\'s password:'
}, }, {
{
type: 'confirm', type: 'confirm',
name: 'elasticsearch', name: 'elasticsearch',
message: 'Use Elasticsearch?', message: 'Use Elasticsearch?',
default: false default: false
}, }, {
{
type: 'input', type: 'input',
name: 'es_host', name: 'es_host',
message: 'Elasticsearch\'s host:', message: 'Elasticsearch\'s host:',
default: 'localhost', default: 'localhost',
when: ctx => ctx.elasticsearch when: ctx => ctx.elasticsearch
}, }, {
{
type: 'input', type: 'input',
name: 'es_port', name: 'es_port',
message: 'Elasticsearch\'s port:', message: 'Elasticsearch\'s port:',
default: '9200', default: '9200',
when: ctx => ctx.elasticsearch when: ctx => ctx.elasticsearch
}, }, {
{
type: 'password', type: 'password',
name: 'es_pass', name: 'es_pass',
message: 'Elasticsearch\'s password:', message: 'Elasticsearch\'s password:',
when: ctx => ctx.elasticsearch when: ctx => ctx.elasticsearch
}, }, {
{
type: 'input', type: 'input',
name: 'recaptcha_site', name: 'recaptcha_site',
message: 'reCAPTCHA\'s site key:' message: 'reCAPTCHA\'s site key:'
}, }, {
{
type: 'input', type: 'input',
name: 'recaptcha_secret', name: 'recaptcha_secret',
message: 'reCAPTCHA\'s secret key:' message: 'reCAPTCHA\'s secret key:'
} }];
];
inquirer.prompt(form).then(as => { inquirer.prompt(form).then(as => {
// Mapping answers // Mapping answers
const conf = { const conf = {
maintainer: as['maintainer'], maintainer: {
name: as['maintainerName'],
url: as['maintainerUrl']
},
url: as['url'], url: as['url'],
secondary_url: as['secondary_url'],
port: parseInt(as['port'], 10), port: parseInt(as['port'], 10),
https: { https: {
enable: as['https'], enable: as['https'],
@ -175,7 +154,6 @@ inquirer.prompt(form).then(as => {
console.log(`Thanks. Writing the configuration to ${chalk.bold(path.resolve(configPath))}`); console.log(`Thanks. Writing the configuration to ${chalk.bold(path.resolve(configPath))}`);
try { try {
fs.mkdirSync(configDirPath);
fs.writeFileSync(configPath, yaml.dump(conf)); fs.writeFileSync(configPath, yaml.dump(conf));
console.log(chalk.green('Well done.')); console.log(chalk.green('Well done.'));
} catch (e) { } catch (e) {