-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathgulp-console.js
49 lines (42 loc) · 1.45 KB
/
gulp-console.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import mongoose from 'mongoose';
import nconf from 'nconf';
import repl from 'repl';
import gulp from 'gulp';
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,
);
};
gulp.task('console', done => {
improveRepl(repl.start({
prompt: 'Habitica > ',
}).context);
done();
});