Преглед изворни кода

feat(create): Make distinction between MySQL & MariaDB

They are handled slightly differently by TypeORM so need to be correctly configured.
Michael Bromley пре 5 година
родитељ
комит
a31bbf8432
3 измењених фајлова са 15 додато и 13 уклоњено
  1. 4 2
      packages/create/src/gather-user-responses.ts
  2. 10 10
      packages/create/src/helpers.ts
  3. 1 1
      packages/create/src/types.ts

+ 4 - 2
packages/create/src/gather-user-responses.ts

@@ -27,7 +27,8 @@ export async function gatherUserResponses(root: string): Promise<UserResponses>
                 name: 'dbType',
                 name: 'dbType',
                 message: 'Which database are you using?',
                 message: 'Which database are you using?',
                 choices: [
                 choices: [
-                    { title: 'MySQL / MariaDB', value: 'mysql' },
+                    { title: 'MySQL', value: 'mysql' },
+                    { title: 'MariaDB', value: 'mariadb' },
                     { title: 'Postgres', value: 'postgres' },
                     { title: 'Postgres', value: 'postgres' },
                     { title: 'SQLite', value: 'sqlite' },
                     { title: 'SQLite', value: 'sqlite' },
                     { title: 'SQL.js', value: 'sqljs' },
                     { title: 'SQL.js', value: 'sqljs' },
@@ -41,7 +42,7 @@ export async function gatherUserResponses(root: string): Promise<UserResponses>
                 type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
                 type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
                 name: 'dbHost',
                 name: 'dbHost',
                 message: `What's the database host address?`,
                 message: `What's the database host address?`,
-                initial: '192.168.99.100',
+                initial: 'localhost',
             },
             },
             {
             {
                 type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
                 type: (() => (dbType === 'sqlite' || dbType === 'sqljs' ? null : 'text')) as any,
@@ -207,6 +208,7 @@ async function generateSources(
 function defaultDBPort(dbType: DbType): number {
 function defaultDBPort(dbType: DbType): number {
     switch (dbType) {
     switch (dbType) {
         case 'mysql':
         case 'mysql':
+        case 'mariadb':
             return 3306;
             return 3306;
         case 'postgres':
         case 'postgres':
             return 5432;
             return 5432;

+ 10 - 10
packages/create/src/helpers.ts

@@ -42,11 +42,11 @@ export function isSafeToCreateProjectIn(root: string, name: string) {
 
 
     const conflicts = fs
     const conflicts = fs
         .readdirSync(root)
         .readdirSync(root)
-        .filter((file) => !validFiles.includes(file))
+        .filter(file => !validFiles.includes(file))
         // IntelliJ IDEA creates module files before CRA is launched
         // 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
         // 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) {
     if (conflicts.length > 0) {
         console.log(`The directory ${chalk.green(name)} contains files that could conflict:`);
         console.log(`The directory ${chalk.green(name)} contains files that could conflict:`);
@@ -62,8 +62,8 @@ export function isSafeToCreateProjectIn(root: string, name: string) {
 
 
     // Remove any remnant files from a previous installation
     // Remove any remnant files from a previous installation
     const currentFiles = fs.readdirSync(path.join(root));
     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
             // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
             if (file.indexOf(errorLogFilePattern) === 0) {
             if (file.indexOf(errorLogFilePattern) === 0) {
                 fs.removeSync(path.join(root, file));
                 fs.removeSync(path.join(root, file));
@@ -121,7 +121,7 @@ export function checkThatNpmCanReadCwd() {
     // "; cwd = C:\path\to\current\dir" (unquoted)
     // "; cwd = C:\path\to\current\dir" (unquoted)
     // I couldn't find an easier way to get it.
     // I couldn't find an easier way to get it.
     const prefix = '; cwd = ';
     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') {
     if (typeof line !== 'string') {
         // Fail gracefully. They could remove it.
         // Fail gracefully. They could remove it.
         return true;
         return true;
@@ -207,7 +207,7 @@ export function installPackages(
         }
         }
 
 
         const child = spawn(command, args, { stdio: logLevel === 'silent' ? 'ignore' : 'inherit' });
         const child = spawn(command, args, { stdio: logLevel === 'silent' ? 'ignore' : 'inherit' });
-        child.on('close', (code) => {
+        child.on('close', code => {
             if (code !== 0) {
             if (code !== 0) {
                 let message = 'An error occurred when installing dependencies.';
                 let message = 'An error occurred when installing dependencies.';
                 if (logLevel === 'silent') {
                 if (logLevel === 'silent') {
@@ -252,6 +252,7 @@ export function getDependencies(
 function dbDriverPackage(dbType: DbType): string {
 function dbDriverPackage(dbType: DbType): string {
     switch (dbType) {
     switch (dbType) {
         case 'mysql':
         case 'mysql':
+        case 'mariadb':
             return 'mysql';
             return 'mysql';
         case 'postgres':
         case 'postgres':
             return 'pg';
             return 'pg';
@@ -343,9 +344,8 @@ async function checkPostgresDbExists(options: any, root: string): Promise<true>
 function throwConnectionError(err: any) {
 function throwConnectionError(err: any) {
     throw new Error(
     throw new Error(
         `Could not connect to the database. ` +
         `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()}]`,
     );
     );
 }
 }
 
 

+ 1 - 1
packages/create/src/types.ts

@@ -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 {
 export interface UserResponses {
     usingTs: boolean;
     usingTs: boolean;