Skip to content

Commit

Permalink
style: fix code style with xo lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kabeep committed Sep 17, 2024
1 parent 5d384fb commit 23ad11c
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 68 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,7 @@ on:
- '!v*alpha*'

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16.14.0

- name: Install dependencies
run: npm install

- name: Run test
run: npm run test

publish-npm:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm test
npm lint
7 changes: 5 additions & 2 deletions .xo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
],
"rules": {
"import/extensions": "off",
"unicorn/prefer-module": "off",
"@typescript-eslint/await-thenable": "off",
"no-await-in-loop": "off",
"import/no-anonymous-default-export": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/consistent-type-definitions": [
"error",
"interface"
Expand Down
3 changes: 1 addition & 2 deletions src/helper/expection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ export default function expection(
}

const providedMessage: string | undefined = typeof message === 'function' ? message() : message;
throw new NodeError(providedMessage || 'Unknown error', code);
throw new NodeError(providedMessage ?? 'Unknown error', code);
}

12 changes: 6 additions & 6 deletions src/helper/partial-right.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/**
* Creates a function that invokes `fn` with partially applied arguments from the right.
*
* @param {Function} fn - The function to partially apply arguments to.
* @param {...any[]} args - The arguments to be partially applied from the right.
* @param {Function} function_ - The function to partially apply arguments to.
* @param {...any[]} arguments_ - The arguments to be partially applied from the right.
* @returns {Function} - A new function with the partial arguments applied from the right.
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}`;
* const greetJohn = partialRight(greet, 'John');
* console.log(greetJohn('Hello')); // Output: "Hello, John"
*/
export default function partialRight<T extends (...args: any[]) => any>(
fn: T,
...args: Parameters<T>
export default function partialRight<T extends (...arguments_: any[]) => any>(
function_: T,
...arguments_: Parameters<T>
): (...rest: any[]) => ReturnType<T> {
return (...rest: any[]) => fn(...rest, ...args);
return (...rest: any[]) => function_(...rest, ...arguments_);
}
9 changes: 4 additions & 5 deletions src/helper/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
*
* pipeline(5).then(result => console.log(result)); // Output: 10.5
*/
export default function pipe<T, R>(
...fns: Array<(input: any) => any | Promise<any>>
): (input: T) => Promise<R> {
export default function pipe<T, R>(...fns: Array<(input: any) => any | Promise<any>>): (input: T) => Promise<R> {
return async (input: T): Promise<R> => {
let result: any = input;
for (const fn of fns) {
result = await fn(result); // Awaiting each function in case it returns a promise
for (const function_ of fns) {
result = await function_(result); // Awaiting each function in case it returns a promise
}

return result as R;
};
}
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import steamLibrary, { type SteamLibraryOption } from './steam-library';
import steamRoot from './steam-root';
import { pipe } from './helper/index.js';

export type { SteamAppOption, SteamLibraryOption };

/**
* A function that retrieves the root path of the Steam installation.
*
Expand Down Expand Up @@ -32,14 +30,15 @@ export const getLibrary = pipe<void, SteamLibraryOption[]>(steamRoot, steamLibra
* @type {Function}
* @returns {Promise<SteamAppOption[]>} A promise that resolves to an array of `SteamAppOption` objects.
*/
export const getApps = pipe<void, SteamAppOption[]>(
steamRoot,
steamLibrary,
(apps: SteamLibraryOption[]) => apps.map(steamApp),
export const getApps = pipe<void, SteamAppOption[]>(steamRoot, steamLibrary, (apps: SteamLibraryOption[]) =>
apps.map((app) => steamApp(app)),
);

export default {
getLibrary,
getApps,
getRootPath,
}
};

export { type SteamAppOption } from './steam-app';
export { type SteamLibraryOption } from './steam-library';
27 changes: 12 additions & 15 deletions src/steam-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as VDF from '@node-steam/vdf';
import { readFileSync } from 'fs';
import { existsSync } from 'node:fs';
import { readFileSync, existsSync } from 'node:fs';
import { resolve } from 'node:path';
import * as VDF from '@node-steam/vdf';
import { expection, partialRight } from './helper';
import type { SteamLibraryOption } from './steam-library';

Expand Down Expand Up @@ -48,15 +47,13 @@ interface SteamAppManifest {
AppState: AppState;
}

const remappingManifest = (appState: AppState, { id, library }: SteamLibraryOption) => (
{
id: appState.appid,
name: appState.name,
installPath: appState.installdir ? resolve(library, 'steamapps/common', appState.installdir) : undefined,
modPath: resolve(library, 'steamapps/workshop/content', id),
language: appState.UserConfig?.language,
}
);
const remappingManifest = (appState: AppState, { id, library }: SteamLibraryOption) => ({
id: appState.appid,
name: appState.name,
installPath: appState.installdir ? resolve(library, 'steamapps/common', appState.installdir) : undefined,
modPath: resolve(library, 'steamapps/workshop/content', id),
language: appState.UserConfig?.language,
});

export type SteamAppOption = ReturnType<typeof remappingManifest>;

Expand All @@ -66,10 +63,10 @@ export default function steamApp({ id, library }: SteamLibraryOption): SteamAppO

customExpection(existsSync(manifestFile), `App ${id} not found in library ${library}`);

const content = readFileSync(manifestFile, 'utf-8');
const content = readFileSync(manifestFile, 'utf8');

const record: SteamAppManifest = VDF.parse(content);
const record = VDF.parse(content) as SteamAppManifest;
customExpection(record.AppState, 'Invalid manifest file');

return remappingManifest(record.AppState, { id, library });
}
}
16 changes: 10 additions & 6 deletions src/steam-library.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as VDF from '@node-steam/vdf';
import { existsSync, readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import * as VDF from '@node-steam/vdf';
import { expection, partialRight } from './helper';

interface SteamLibrary {
Expand Down Expand Up @@ -37,10 +37,10 @@ export default function steamLibrary(rootPath: string): SteamLibraryOption[] {
customExpection(existsSync(libraryFile), 'Steam library file not found');

// Read the file content
const content = readFileSync(libraryFile, 'utf-8');
const content = readFileSync(libraryFile, 'utf8');

// Parse the VDF content into a structured object
const record: SteamLibrary = VDF.parse(content);
const record = VDF.parse(content) as SteamLibrary;

// Ensure the parsed content contains valid library folders
customExpection(record.libraryfolders, 'Invalid library file');
Expand All @@ -49,10 +49,14 @@ export default function steamLibrary(rootPath: string): SteamLibraryOption[] {

// Loop through the library folders and extract game IDs and paths
for (const index in record.libraryfolders) {
const item = record.libraryfolders[index];
if (Object.hasOwn(record.libraryfolders, index)) {
const item = record.libraryfolders[index];

for (const gameId in item.apps) {
apps.push({ library: item.path, id: gameId });
for (const gameId in item.apps) {
if (Object.hasOwn(item.apps, gameId)) {
apps.push({ library: item.path, id: gameId });
}
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/steam-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ export default async function steamRoot(): Promise<string> {
return new Promise((resolve, reject) => {
// Define the registry path and key name
const regKey = new Registry({
hive: Registry.HKCU, // HKEY_CURRENT_USER
key: registryKey, // Steam registry key
hive: Registry.HKCU, // HKEY_CURRENT_USER
key: registryKey, // Steam registry key
});

// Read the "SteamPath" key from the registry
regKey.get('SteamPath', function (error, item) {
if (error) {
reject(new NodeError(`${error}`, 'EREGISTRY'));
} else if (!item.value) {
reject(new NodeError('Steam path is empty', 'EREGISTRY'));
} else {
reject(new NodeError(error.toString(), 'EREGISTRY'));
} else if (item.value) {
resolve(item.value);
} else {
reject(new NodeError('Steam path is empty', 'EREGISTRY'));
}
});
});
Expand Down

0 comments on commit 23ad11c

Please sign in to comment.