-
-
Notifications
You must be signed in to change notification settings - Fork 314
/
config.ts
36 lines (30 loc) · 937 Bytes
/
config.ts
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
import path from 'path';
import fs from 'fs';
export const PORT = process.env.PORT || 3000;
export const MONGODB_URI =
process.env.MONGODB_URI || 'mongodb://localhost:27017/graphql-compose-mongoose';
export const examplesPath = './examples';
export function getDirectories(srcPath: string): string[] {
return fs
.readdirSync(srcPath)
.filter((file) => fs.statSync(path.join(srcPath, file)).isDirectory());
}
export function resolveExamplePath(...args: any) {
return path.resolve(examplesPath, ...args);
}
export function getExampleNames() {
const preferableOrder = ['user', 'northwind', 'mongooseDiscriminators'];
const dirs = getDirectories(examplesPath);
const result = [];
preferableOrder.forEach((name) => {
const idx = dirs.indexOf(name);
if (idx !== -1) {
result.push(name);
dirs.splice(idx, 1);
}
});
dirs.forEach((name) => {
result.push(name);
});
return result;
}