Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 48a0960

Browse files
author
Ray Arayilakath
committed
Patch other breaking instances, prettify config file
1 parent 23aa46d commit 48a0960

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import fs from 'fs';
22
import path from 'path';
33
import replapi from './src/source.js';
44

5+
import stringify from 'json-stable-stringify-without-jsonify';
6+
57
const defaultInitVariables = {
68
username: undefined,
79
captcha: {
@@ -22,6 +24,10 @@ const defaultInitVariables = {
2224
experimentalFeatures: undefined,
2325
};
2426

27+
function sortByKey(a, b) {
28+
return a.key > b.key ? 1 : -1;
29+
}
30+
2531
export default function ReplAPI(initVariables) {
2632
if (initVariables) {
2733
for (const [key, value] of Object.entries(initVariables)) {
@@ -39,9 +45,9 @@ export default function ReplAPI(initVariables) {
3945
defaultInitVariables[key] = value;
4046
}
4147
}
42-
fs.writeFileSync(path.join(process.cwd(), '.replapirc.json'), JSON.stringify(defaultInitVariables), { encoding: 'utf8' });
48+
fs.writeFileSync(path.join(process.cwd(), '.replapirc.json'), `${stringify(defaultInitVariables, { cmp: sortByKey, space: 4 })}\n`, { encoding: 'utf8' });
4349
} else {
44-
fs.writeFileSync(path.join(process.cwd(), '.replapirc.json'), JSON.stringify(defaultInitVariables), { encoding: 'utf8' });
50+
fs.writeFileSync(path.join(process.cwd(), '.replapirc.json'), `${stringify(defaultInitVariables, { cmp: sortByKey, space: 4 })}\n`, { encoding: 'utf8' });
4551
}
4652

4753
return {

src/classes/Database.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ function compare(value, hashData) {
2424
}
2525

2626
let exportable;
27-
const isExperimentalFeaturesEnabled = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.replapirc.json'))).experimentalFeatures;
27+
let isExperimentalFeaturesEnabled;
28+
if (fs.existsSync(path.join(process.cwd(), '.replapirc.json'))) {
29+
isExperimentalFeaturesEnabled = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.replapirc.json'))).experimentalFeatures;
30+
}
2831

2932
if (isExperimentalFeaturesEnabled) {
3033
exportable = class Database {

src/classes/Notifications.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import headers from '../utils/headers.js';
66
import constants from '../utils/constants.js';
77

88
let exportable;
9-
const isExperimentalFeaturesEnabled = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.replapirc.json'))).experimentalFeatures;
9+
let isExperimentalFeaturesEnabled;
10+
if (fs.existsSync(path.join(process.cwd(), '.replapirc.json'))) {
11+
isExperimentalFeaturesEnabled = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.replapirc.json'))).experimentalFeatures;
12+
}
1013

1114
if (isExperimentalFeaturesEnabled) {
1215
exportable = class Notifications {

0 commit comments

Comments
 (0)