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: 'maintainerName',
name: 'maintainer', message: 'Your name:'
message: 'Maintainer name(and email address):' }, {
}, type: 'input',
{ name: 'maintainerUrl',
type: 'input', message: 'Your home page URL or your mailto URL:'
name: 'url', }, {
message: 'PRIMARY URL:' type: 'input',
}, name: 'url',
{ message: 'URL you want to run Misskey:'
type: 'input', }, {
name: 'secondary_url', type: 'input',
message: 'SECONDARY URL:' name: 'port',
}, message: 'Listen port (e.g. 443):'
{ }, {
type: 'input', type: 'confirm',
name: 'port', name: 'https',
message: 'Listen port:' message: 'Use TLS?',
}, default: false
{ }, {
type: 'confirm', type: 'input',
name: 'https', name: 'https_key',
message: 'Use TLS?', message: 'Path of tls key:',
default: false when: ctx => ctx.https
}, }, {
{ type: 'input',
type: 'input', name: 'https_cert',
name: 'https_key', message: 'Path of tls cert:',
message: 'Path of tls key:', when: ctx => ctx.https
when: ctx => ctx.https }, {
}, type: 'input',
{ name: 'https_ca',
type: 'input', message: 'Path of tls ca:',
name: 'https_cert', when: ctx => ctx.https
message: 'Path of tls cert:', }, {
when: ctx => ctx.https type: 'input',
}, name: 'mongo_host',
{ message: 'MongoDB\'s host:',
type: 'input', default: 'localhost'
name: 'https_ca', }, {
message: 'Path of tls ca:', type: 'input',
when: ctx => ctx.https name: 'mongo_port',
}, message: 'MongoDB\'s port:',
{ default: '27017'
type: 'input', }, {
name: 'mongo_host', type: 'input',
message: 'MongoDB\'s host:', name: 'mongo_db',
default: 'localhost' message: 'MongoDB\'s db:',
}, default: 'misskey'
{ }, {
type: 'input', type: 'input',
name: 'mongo_port', name: 'mongo_user',
message: 'MongoDB\'s port:', message: 'MongoDB\'s user:'
default: '27017' }, {
}, type: 'password',
{ name: 'mongo_pass',
type: 'input', message: 'MongoDB\'s password:'
name: 'mongo_db', }, {
message: 'MongoDB\'s db:', type: 'input',
default: 'misskey' name: 'redis_host',
}, message: 'Redis\'s host:',
{ default: 'localhost'
type: 'input', }, {
name: 'mongo_user', type: 'input',
message: 'MongoDB\'s user:' name: 'redis_port',
}, message: 'Redis\'s port:',
{ default: '6379'
type: 'password', }, {
name: 'mongo_pass', type: 'password',
message: 'MongoDB\'s password:' name: 'redis_pass',
}, message: 'Redis\'s password:'
{ }, {
type: 'input', type: 'confirm',
name: 'redis_host', name: 'elasticsearch',
message: 'Redis\'s host:', message: 'Use Elasticsearch?',
default: 'localhost' default: false
}, }, {
{ type: 'input',
type: 'input', name: 'es_host',
name: 'redis_port', message: 'Elasticsearch\'s host:',
message: 'Redis\'s port:', default: 'localhost',
default: '6379' when: ctx => ctx.elasticsearch
}, }, {
{ type: 'input',
type: 'password', name: 'es_port',
name: 'redis_pass', message: 'Elasticsearch\'s port:',
message: 'Redis\'s password:' default: '9200',
}, when: ctx => ctx.elasticsearch
{ }, {
type: 'confirm', type: 'password',
name: 'elasticsearch', name: 'es_pass',
message: 'Use Elasticsearch?', message: 'Elasticsearch\'s password:',
default: false when: ctx => ctx.elasticsearch
}, }, {
{ type: 'input',
type: 'input', name: 'recaptcha_site',
name: 'es_host', message: 'reCAPTCHA\'s site key:'
message: 'Elasticsearch\'s host:', }, {
default: 'localhost', type: 'input',
when: ctx => ctx.elasticsearch name: 'recaptcha_secret',
}, message: 'reCAPTCHA\'s secret key:'
{ }];
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 => { 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) {