This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
95 lines (90 loc) 路 2.04 KB
/
Copy pathindex.js
File metadata and controls
95 lines (90 loc) 路 2.04 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import fs from 'fs';
import path from 'path';
import { assign } from 'lodash-es';
// import stringify from 'json-stable-stringify-without-jsonify';
import classes from './src/loader.js';
Object.prototype.sortKeys = function () {
return Object.fromEntries(Object.entries(this).sort());
};
const defaultInitVariables = {
username: '',
captcha: {
token: '',
},
endpoints: {
gql: '',
restful: '',
login: '',
},
markdown: {
length: '',
removeMarkdown: '',
},
previewCount: {
comments: '',
},
experimentalFeatures: '',
createDatabaseFlag: '',
statsForNerds: '',
};
export default function ReplAPI(initVariables, filetype = '.json') {
if (initVariables) assign(defaultInitVariables, initVariables);
switch (filetype) {
case '.json':
fs.writeFileSync(
path.join(process.cwd(), '.replapirc.json'),
`${JSON.stringify(defaultInitVariables.sortKeys(), null, '\t')}\n`,
{ encoding: 'utf8' },
);
break;
case '.mjs':
fs.writeFileSync(
path.join(process.cwd(), 'replapi.config.mjs'),
`export default ${JSON.stringify(
defaultInitVariables.sortKeys(),
null,
'\t',
)}\n`,
{ encoding: 'utf8' },
);
break;
case '.cjs':
fs.writeFileSync(
path.join(process.cwd(), 'replapi.config.cjs'),
`module.exports = ${JSON.stringify(
defaultInitVariables.sortKeys(),
null,
'\t',
)}\n`,
{ encoding: 'utf8' },
);
break;
case '.js':
fs.writeFileSync(
path.join(process.cwd(), 'replapi.config.js'),
`module.exports = ${JSON.stringify(
defaultInitVariables.sortKeys(),
null,
'\t',
)}\n`,
{ encoding: 'utf8' },
);
break;
default:
console.warn(`Invalid file type '${filetype}'`);
fs.writeFileSync(
path.join(process.cwd(), '.replapirc.json'),
`${JSON.stringify(defaultInitVariables.sortKeys(), null, '\t')}\n`,
{ encoding: 'utf8' },
);
break;
}
return {
defaults: defaultInitVariables,
Blog: classes.Blog,
Board: classes.Board,
Explore: classes.Explore,
User: classes.User,
Languages: classes.Languages,
};
}