Skip to content

Commit 70cc3d2

Browse files
committed
refactor(grabber): extract config helpers
1 parent 19814dc commit 70cc3d2

File tree

11 files changed

+7924
-1421
lines changed

11 files changed

+7924
-1421
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
node_modules
33
dist
44
test
5-
config.yml
5+
/config.yml
66

77
# local env files
88
.env.local

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript',
5+
],
6+
}

index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs-extra'
22
import path from 'path'
33

4-
import Utils from './utils'
4+
import Utils, {loadConfig} from './utils'
55
import {confirm, writeJSON} from './helper'
66
import * as logger from './logger'
77
import ProgressBar from './progressbar'
@@ -13,14 +13,14 @@ process.on('SIGINT', () => {
1313
process.stdout.write('\x1Bc')
1414

1515
const utils = new Utils()
16-
const config = utils.getConfig()
16+
const config = loadConfig()
1717

1818
void async function main () {
19-
const bannedUuidList = config.render['banned-players'] ? utils.getBannedPlayers() : []
19+
const bannedUuidList = config.get('render.banned-players') ? utils.getBannedPlayers() : []
2020

2121
const uuidList = (() => {
2222
let list = config.render.whitelist ? utils.getWhitelistedPlayers() : utils.getAllPlayers()
23-
if (!config.render['render-banned'] && bannedUuidList.length) {
23+
if (!config.get('render.render-banned') && bannedUuidList.length) {
2424
list = list.filter(uuid => !bannedUuidList.some(ban => ban === uuid))
2525
}
2626
return list
@@ -33,10 +33,10 @@ void async function main () {
3333
logger.Default.info('Advancements not set: Render mode set to 1.11')
3434
}
3535

36-
const outputDir = path.join(config.BASEPATH, config.render.output)
36+
const outputDir = config.resolve(config.render.output)
3737
logger.Default.info('CREATE OUTPUT DIR', outputDir)
3838

39-
if (config.render['confirm-clear-data'] !== false) {
39+
if (config.get('render.confirm-clear-data') !== false) {
4040
const prompt = await confirm('Do you want to clean the output folder?')
4141
if (prompt) {
4242
try {
@@ -54,7 +54,7 @@ void async function main () {
5454

5555
for (const uuid of uuidList) {
5656
try {
57-
const banned = config.render['render-banned'] ? bannedUuidList.some(ban => ban === uuid) : false
57+
const banned = config.get('render.render-banned') ? bannedUuidList.some(ban => ban === uuid) : false
5858
let data
5959
try {
6060
data = await utils.createPlayerData(uuid, banned)
@@ -81,7 +81,7 @@ void async function main () {
8181
const worldTime = await utils.getWorldTime()
8282
writeJSON(path.join(outputDir, 'info.json'), {
8383
worldTime,
84-
timeFormat: config.render['time-format'],
84+
timeFormat: config.get('render.time-format'),
8585
lastUpdate: Date.now(),
8686
...config.web,
8787
} as never)

jest.config.js

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// All imported modules in your tests should be mocked automatically
6+
// automock: false,
7+
8+
// Stop running tests after `n` failures
9+
// bail: 0,
10+
11+
// The directory where Jest should store its cached dependency information
12+
// cacheDirectory: "/private/var/folders/0h/1bsnxdrn0db9f6wcnmt49lvm0000gp/T/jest_dy",
13+
14+
// Automatically clear mock calls and instances between every test
15+
clearMocks: true,
16+
17+
// Indicates whether the coverage information should be collected while executing the test
18+
collectCoverage: true,
19+
20+
// An array of glob patterns indicating a set of files for which coverage information should be collected
21+
// collectCoverageFrom: undefined,
22+
23+
// The directory where Jest should output its coverage files
24+
coverageDirectory: '__coverage__',
25+
26+
// An array of regexp pattern strings used to skip coverage collection
27+
coveragePathIgnorePatterns: [
28+
'/node_modules/',
29+
'/mocks/',
30+
],
31+
32+
// Indicates which provider should be used to instrument code for coverage
33+
// coverageProvider: "babel",
34+
35+
// A list of reporter names that Jest uses when writing coverage reports
36+
// coverageReporters: [
37+
// "json",
38+
// "text",
39+
// "lcov",
40+
// "clover"
41+
// ],
42+
43+
// An object that configures minimum threshold enforcement for coverage results
44+
// coverageThreshold: undefined,
45+
46+
// A path to a custom dependency extractor
47+
// dependencyExtractor: undefined,
48+
49+
// Make calling deprecated APIs throw helpful error messages
50+
// errorOnDeprecated: false,
51+
52+
// Force coverage collection from ignored files using an array of glob patterns
53+
// forceCoverageMatch: [],
54+
55+
// A path to a module which exports an async function that is triggered once before all test suites
56+
// globalSetup: undefined,
57+
58+
// A path to a module which exports an async function that is triggered once after all test suites
59+
// globalTeardown: undefined,
60+
61+
// A set of global variables that need to be available in all test environments
62+
// globals: {},
63+
64+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
65+
// maxWorkers: "50%",
66+
67+
// An array of directory names to be searched recursively up from the requiring module's location
68+
// moduleDirectories: [
69+
// "node_modules"
70+
// ],
71+
72+
// An array of file extensions your modules use
73+
// moduleFileExtensions: [
74+
// "js",
75+
// "json",
76+
// "jsx",
77+
// "ts",
78+
// "tsx",
79+
// "node"
80+
// ],
81+
82+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
83+
// moduleNameMapper: {},
84+
85+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
86+
// modulePathIgnorePatterns: [],
87+
88+
// Activates notifications for test results
89+
// notify: false,
90+
91+
// An enum that specifies notification mode. Requires { notify: true }
92+
// notifyMode: "failure-change",
93+
94+
// A preset that is used as a base for Jest's configuration
95+
// preset: undefined,
96+
97+
// Run tests from one or more projects
98+
// projects: undefined,
99+
100+
// Use this configuration option to add custom reporters to Jest
101+
// reporters: undefined,
102+
103+
// Automatically reset mock state between every test
104+
// resetMocks: false,
105+
106+
// Reset the module registry before running each individual test
107+
// resetModules: false,
108+
109+
// A path to a custom resolver
110+
// resolver: undefined,
111+
112+
// Automatically restore mock state between every test
113+
// restoreMocks: false,
114+
115+
// The root directory that Jest should scan for tests and modules within
116+
// rootDir: undefined,
117+
118+
// A list of paths to directories that Jest should use to search for files in
119+
// roots: [
120+
// "<rootDir>"
121+
// ],
122+
123+
// Allows you to use a custom runner instead of Jest's default test runner
124+
// runner: "jest-runner",
125+
126+
// The paths to modules that run some code to configure or set up the testing environment before each test
127+
// setupFiles: [],
128+
129+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
130+
// setupFilesAfterEnv: [],
131+
132+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
133+
// snapshotSerializers: [],
134+
135+
// The test environment that will be used for testing
136+
testEnvironment: 'node',
137+
138+
// Options that will be passed to the testEnvironment
139+
// testEnvironmentOptions: {},
140+
141+
// Adds a location field to test results
142+
// testLocationInResults: false,
143+
144+
// The glob patterns Jest uses to detect test files
145+
// testMatch: [
146+
// "**/__tests__/**/*.[jt]s?(x)",
147+
// "**/?(*.)+(spec|test).[tj]s?(x)"
148+
// ],
149+
150+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
151+
// testPathIgnorePatterns: [
152+
// "/node_modules/"
153+
// ],
154+
155+
// The regexp pattern or array of patterns that Jest uses to detect test files
156+
// testRegex: [],
157+
158+
// This option allows the use of a custom results processor
159+
// testResultsProcessor: undefined,
160+
161+
// This option allows use of a custom test runner
162+
// testRunner: "jasmine2",
163+
164+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
165+
// testURL: "http://localhost",
166+
167+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
168+
// timers: "real",
169+
170+
// A map from regular expressions to paths to transformers
171+
// transform: undefined,
172+
173+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
174+
// transformIgnorePatterns: [
175+
// "/node_modules/"
176+
// ],
177+
178+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
179+
// unmockedModulePathPatterns: undefined,
180+
181+
// Indicates whether each individual test should be reported during the run
182+
// verbose: undefined,
183+
184+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
185+
// watchPathIgnorePatterns: [],
186+
187+
// Whether to use watchman for file crawling
188+
// watchman: true,
189+
}

0 commit comments

Comments
 (0)