74 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-04-26 09:07:40 +02:00
import type { Question } from 'inquirer';
2024-05-02 14:38:49 +02:00
import type { DBClient } from './types';
2023-04-26 09:07:40 +02:00
interface QuestionFactory {
2024-05-02 14:38:49 +02:00
(options: { client: DBClient }): Question;
2023-04-26 09:07:40 +02:00
}
2021-06-29 16:27:35 +02:00
const DEFAULT_PORTS = {
postgres: 5432,
mysql: 3306,
2023-04-26 09:07:40 +02:00
sqlite: undefined,
2021-06-29 16:27:35 +02:00
};
2024-05-02 14:38:49 +02:00
const database: QuestionFactory = () => ({
type: 'input',
name: 'database',
message: 'Database name:',
2024-05-02 14:38:49 +02:00
default: 'strapi',
2023-04-26 09:07:40 +02:00
validate(value: string) {
if (value.includes('.')) {
2020-01-07 14:23:15 +01:00
return `The database name can't contain a "."`;
}
return true;
},
});
2023-04-26 09:07:40 +02:00
const host: QuestionFactory = () => ({
type: 'input',
name: 'host',
message: 'Host:',
default: '127.0.0.1',
});
2023-04-26 09:07:40 +02:00
const port: QuestionFactory = ({ client }) => ({
type: 'input',
name: 'port',
2023-04-26 09:07:40 +02:00
message: 'Port:',
2021-06-29 16:27:35 +02:00
default: DEFAULT_PORTS[client],
});
2023-04-26 09:07:40 +02:00
const username: QuestionFactory = () => ({
type: 'input',
name: 'username',
message: 'Username:',
});
2023-04-26 09:07:40 +02:00
const password: QuestionFactory = () => ({
type: 'password',
name: 'password',
message: 'Password:',
mask: '*',
});
2023-04-26 09:07:40 +02:00
const ssl: QuestionFactory = () => ({
type: 'confirm',
name: 'ssl',
message: 'Enable SSL connection:',
default: false,
});
2023-04-26 09:07:40 +02:00
const filename: QuestionFactory = () => ({
type: 'input',
name: 'filename',
message: 'Filename:',
default: '.tmp/data.db',
});
2023-04-26 09:07:40 +02:00
export default {
sqlite: [filename],
postgres: [database, host, port, username, password, ssl],
mysql: [database, host, port, username, password, ssl],
};