import { join } from 'path';
import { replaceCode, appendFile, addNpmPackage } from '../utils';

async function generateMongodbDatabase(params) {
  switch (params.framework) {
    case 'express':
      const app = join(__base, 'build', params.uuid, 'app.js');
      const mongooseRequire = join(__base, 'modules', 'database', 'mongodb', 'mongoose-require.js');
      const mongooseConnect = join(__base, 'modules', 'database', 'mongodb', 'mongoose-connect.js');

      await replaceCode(app, 'DATABASE_REQUIRE', mongooseRequire);
      await replaceCode(app, 'DATABASE_CONNECTION', mongooseConnect, { leadingBlankLine: true });

      await appendFile(join(__base, 'build', params.uuid, '.env'), 'MONGODB=mongodb://localhost/test');

      await addNpmPackage('mongoose', params);
      break;
    case 'hapi':
      break;
    case 'meteor':
      break;
    default:
  }
}

export default generateMongodbDatabase;

@@ -43,16 +43,30 @@
 aceCode,
+ mkdirs, copy,
  appendF
@@ -153,16 +153,69 @@
 rams) %7B%0A
+  const build = join(__base, 'build', params.uuid);%0A%0A
   switch
@@ -283,35 +283,12 @@
 oin(
-__base, 'build', params.uui
+buil
 d, '
@@ -498,16 +498,117 @@
 ct.js');
+%0A      const mongooseUserModel = join(__base, 'modules', 'database', 'mongodb', 'mongoose-model.js');
 %0A%0A      
@@ -799,35 +799,12 @@
 oin(
-__base, 'build', params.uui
+buil
 d, '
@@ -896,16 +896,182 @@
 arams);%0A
+%0A      // Create models dir%0A      await mkdirs(join(__base, 'build', params.uuid, 'models'));%0A      await copy(mongooseUserModel, join(build, 'models', 'user.js'));%0A%0A
       br

Create models dir and copy user model for mongodb generator