Skip to content

Commit

Permalink
feat(create): Make distinction between MySQL & MariaDB
Browse files Browse the repository at this point in the history
They are handled slightly differently by TypeORM so need to be correctly configured.
  • Loading branch information
michaelbromley committed Aug 31, 2020
1 parent 682966f commit a31bbf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions packages/create/src/gather-user-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export async function gatherUserResponses(root: string): Promise<UserResponses>
name: 'dbType',
message: 'Which database are you using?',
choices: [
{ title: 'MySQL / MariaDB', value: 'mysql' },
{ title: 'MySQL', value: 'mysql' },
{ title: 'MariaDB', value: 'mariadb' },
{ title: 'Postgres', value: 'postgres' },
{ title: 'SQLite', value: 'sqlite' },
{ title: 'SQL.js', value: 'sqljs' },
Expand All @@ -41,7 +42,7 @@ export async function gatherUserResponses(root: string): Promise<UserResponses>
type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
name: 'dbHost',
message: `What's the database host address?`,
initial: '192.168.99.100',
initial: 'localhost',
},
{
type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
Expand Down Expand Up @@ -207,6 +208,7 @@ async function generateSources(
function defaultDBPort(dbType: DbType): number {
switch (dbType) {
case 'mysql':
case 'mariadb':
return 3306;
case 'postgres':
return 5432;
Expand Down
20 changes: 10 additions & 10 deletions packages/create/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export function isSafeToCreateProjectIn(root: string, name: string) {

const conflicts = fs
.readdirSync(root)
.filter((file) => !validFiles.includes(file))
.filter(file => !validFiles.includes(file))
// IntelliJ IDEA creates module files before CRA is launched
.filter((file) => !/\.iml$/.test(file))
.filter(file => !/\.iml$/.test(file))
// Don't treat log files from previous installation as conflicts
.filter((file) => !errorLogFilePatterns.some((pattern) => file.indexOf(pattern) === 0));
.filter(file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0));

if (conflicts.length > 0) {
console.log(`The directory ${chalk.green(name)} contains files that could conflict:`);
Expand All @@ -62,8 +62,8 @@ export function isSafeToCreateProjectIn(root: string, name: string) {

// Remove any remnant files from a previous installation
const currentFiles = fs.readdirSync(path.join(root));
currentFiles.forEach((file) => {
errorLogFilePatterns.forEach((errorLogFilePattern) => {
currentFiles.forEach(file => {
errorLogFilePatterns.forEach(errorLogFilePattern => {
// This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
if (file.indexOf(errorLogFilePattern) === 0) {
fs.removeSync(path.join(root, file));
Expand Down Expand Up @@ -121,7 +121,7 @@ export function checkThatNpmCanReadCwd() {
// "; cwd = C:\path\to\current\dir" (unquoted)
// I couldn't find an easier way to get it.
const prefix = '; cwd = ';
const line = lines.find((l) => l.indexOf(prefix) === 0);
const line = lines.find(l => l.indexOf(prefix) === 0);
if (typeof line !== 'string') {
// Fail gracefully. They could remove it.
return true;
Expand Down Expand Up @@ -207,7 +207,7 @@ export function installPackages(
}

const child = spawn(command, args, { stdio: logLevel === 'silent' ? 'ignore' : 'inherit' });
child.on('close', (code) => {
child.on('close', code => {
if (code !== 0) {
let message = 'An error occurred when installing dependencies.';
if (logLevel === 'silent') {
Expand Down Expand Up @@ -252,6 +252,7 @@ export function getDependencies(
function dbDriverPackage(dbType: DbType): string {
switch (dbType) {
case 'mysql':
case 'mariadb':
return 'mysql';
case 'postgres':
return 'pg';
Expand Down Expand Up @@ -343,9 +344,8 @@ async function checkPostgresDbExists(options: any, root: string): Promise<true>
function throwConnectionError(err: any) {
throw new Error(
`Could not connect to the database. ` +
`Please check the connection settings in your Vendure config.\n[${
err.message || err.toString()
}]`,
`Please check the connection settings in your Vendure config.\n[${err.message ||
err.toString()}]`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/create/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type DbType = 'mysql' | 'postgres' | 'sqlite' | 'sqljs' | 'mssql' | 'oracle';
export type DbType = 'mysql' | 'mariadb' | 'postgres' | 'sqlite' | 'sqljs' | 'mssql' | 'oracle';

export interface UserResponses {
usingTs: boolean;
Expand Down

0 comments on commit a31bbf8

Please sign in to comment.