forked from pubpub/pubpub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.replrc.js
64 lines (56 loc) · 1.62 KB
/
.replrc.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import chalk from 'chalk';
import { isProd } from 'utils/environment';
import { addWorkerTask } from 'server/utils/workers';
import { sendEmail } from 'server/utils/email';
import { createPubPubS3Client, assetsClient } from 'server/utils/s3';
import { getPubDraftDoc, getPubDraftRef, editFirebaseDraftByRef } from 'server/utils/firebaseAdmin';
import * as facets from 'server/facets';
import * as featureFlags from 'server/featureFlag/interface';
import * as tasks from 'workers/tasks';
import * as models from 'server/models';
const pilcrow = '¶';
const prompt = isProd() ? chalk.redBright(`[PROD] ${pilcrow} `) : chalk.greenBright(`${pilcrow} `);
const banner = () => {
const color = isProd() ? chalk.redBright : chalk.greenBright;
console.log(
color(isProd() ? 'PubPub PROD devshell. Use caution.' : 'Welcome to the PubPub devshell.'),
);
console.log(color("Call scope() to see what's in scope."));
};
const generateFindFunctions = () => {
return Object.fromEntries(
['Collection', 'Community', 'Pub', 'User'].map((modelName) => {
const Model = models[modelName];
const fn = (whereQuery) => Model.findOne({ where: whereQuery });
return [`find${modelName}`, fn];
}),
);
};
const clear = () => {
process.stdout.write('\u001B[2J\u001B[0;0f');
};
const scope = () => {
console.log(Object.keys(context).join(', '));
};
const context = {
...tasks,
...models,
...featureFlags,
...facets,
...generateFindFunctions(),
clear,
scope,
addWorkerTask,
sendEmail,
createPubPubS3Client,
assetsClient,
getPubDraftDoc,
getPubDraftRef,
editFirebaseDraftByRef,
};
module.exports = {
context,
prompt,
banner,
enableAwait: true,
};