diff --git a/CHANGELOG.md b/CHANGELOG.md index e81fd43..be69657 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ #### Package * Node.js 16.20 is now required (from 14). * Made the library a `module`. -* Removed `GameResolver`. +* Removed `GameResolver`, moved the `GameDig` class in a separate file. +* Modified exports, now the library exports `games` and `protocols` alongside the `GameDig` class. #### Games * Renamed `Counter Strike: 2D` to `CS2D` in [games.txt](games.txt) (why? see [this](https://cs2d.com/faq.php?show=misc_name#misc_name)). diff --git a/examples/simple.js b/examples/simple.js index 3f4a23b..a0c52c1 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -1,4 +1,4 @@ -import GameDig from '../lib/index.js' +import { GameDig } from '../lib/index.js' // Instead of '../lib/index.js' you would have here 'gamedig'. GameDig.query({ diff --git a/lib/ProtocolResolver.js b/lib/ProtocolResolver.js index a1f38a9..f5fb774 100644 --- a/lib/ProtocolResolver.js +++ b/lib/ProtocolResolver.js @@ -1,7 +1,7 @@ -import * as Protocols from '../protocols/index.js' +import * as protocols from '../protocols/index.js' export const getProtocol = (protocolId) => { - if (!(protocolId in Protocols)) { throw Error('Protocol definition file missing: ' + protocolId) } + if (!(protocolId in protocols)) { throw Error('Protocol definition file missing: ' + protocolId) } - return new Protocols[protocolId]() + return new protocols[protocolId]() } diff --git a/lib/gamedig.js b/lib/gamedig.js new file mode 100644 index 0000000..a3d1e27 --- /dev/null +++ b/lib/gamedig.js @@ -0,0 +1,23 @@ +import QueryRunner from './QueryRunner.js' + +let singleton = null + +export class GameDig { + constructor (runnerOpts) { + this.queryRunner = new QueryRunner(runnerOpts) + } + + async query (userOptions) { + return await this.queryRunner.run(userOptions) + } + + static getInstance () { + if (!singleton) { singleton = new GameDig() } + + return singleton + } + + static async query (...args) { + return await GameDig.getInstance().query(...args) + } +} diff --git a/lib/index.js b/lib/index.js index 396e7aa..14bb795 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,23 +1,5 @@ -import QueryRunner from './QueryRunner.js' +import { GameDig } from './gamedig.js' +import { games } from './games.js' +import * as protocols from '../protocols/index.js' -let singleton = null - -export default class Gamedig { - constructor (runnerOpts) { - this.queryRunner = new QueryRunner(runnerOpts) - } - - async query (userOptions) { - return await this.queryRunner.run(userOptions) - } - - static getInstance () { - if (!singleton) { singleton = new Gamedig() } - - return singleton - } - - static async query (...args) { - return await Gamedig.getInstance().query(...args) - } -} +export { GameDig, games, protocols } diff --git a/tools/attempt_protocols.js b/tools/attempt_protocols.js index 757daa8..15960ad 100644 --- a/tools/attempt_protocols.js +++ b/tools/attempt_protocols.js @@ -1,5 +1,5 @@ import Minimist from 'minimist' -import GameDig from './../lib/index.js' +import { GameDig } from './../lib/index.js' const argv = Minimist(process.argv.slice(2), {})