mirror of
				https://github.com/HabitRPG/habitica.git
				synced 2025-10-28 03:32:29 +01:00 
			
		
		
		
	* add run-rs to dependencies
* wip: add replica set to api unit github action
* wip: add replica set to api unit github action
* wip: fix gh actions mongodb replica set setting
* usa replica set for integration tests
* add correct mongodb version matrix for integration tests
* use different db connection on gh actions
* Revert "use different db connection on gh actions"
This reverts commit aa8db759d3.
* add example transaction
* add mongo script to package.json
* abstract mongodb utils, connect using hostname on windows
* npm scripts: mongo -> mongo:dev
* add setup script for run-rs on windows
* gh actions: run in test environment
* remove test files
* better error handling, use cross-spawn to avoid issues on windows
* fix lint
		
	
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import mongoose from 'mongoose';
 | |
| import nconf from 'nconf';
 | |
| import repl from 'repl';
 | |
| import gulp from 'gulp';
 | |
| import logger from '../website/server/libs/logger';
 | |
| import {
 | |
|   getDevelopmentConnectionUrl,
 | |
|   getDefaultConnectionOptions,
 | |
| } from '../website/server/libs/mongodb';
 | |
| 
 | |
| // Add additional properties to the repl's context
 | |
| const improveRepl = context => {
 | |
|   // Let "exit" and "quit" terminate the console
 | |
|   ['exit', 'quit'].forEach(term => {
 | |
|     Object.defineProperty(context, term, {
 | |
|       get () { // eslint-disable-line getter-return
 | |
|         process.exit();
 | |
|       },
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   // "clear" clears the screen
 | |
|   Object.defineProperty(context, 'clear', {
 | |
|     get () { // eslint-disable-line getter-return
 | |
|       process.stdout.write('\u001B[2J\u001B[0;0f');
 | |
|     },
 | |
|   });
 | |
| 
 | |
|   context.Challenge = require('../website/server/models/challenge').model; // eslint-disable-line global-require
 | |
|   context.Group = require('../website/server/models/group').model; // eslint-disable-line global-require
 | |
|   context.User = require('../website/server/models/user').model; // eslint-disable-line global-require
 | |
| 
 | |
|   const IS_PROD = nconf.get('NODE_ENV') === 'production';
 | |
|   const NODE_DB_URI = nconf.get('NODE_DB_URI');
 | |
| 
 | |
|   const mongooseOptions = getDefaultConnectionOptions();
 | |
|   const connectionUrl = IS_PROD ? NODE_DB_URI : getDevelopmentConnectionUrl(NODE_DB_URI);
 | |
| 
 | |
|   mongoose.connect(
 | |
|     connectionUrl,
 | |
|     mongooseOptions,
 | |
|     err => {
 | |
|       if (err) throw err;
 | |
|       logger.info('Connected with Mongoose');
 | |
|     },
 | |
|   );
 | |
| };
 | |
| 
 | |
| gulp.task('console', done => {
 | |
|   improveRepl(repl.start({
 | |
|     prompt: 'Habitica > ',
 | |
|   }).context);
 | |
|   done();
 | |
| });
 |