Skip to content

Commit

Permalink
chore: enhance Husky hooks and pre-commit script
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabb-c authored Dec 21, 2023
1 parent 9bc9076 commit 067095f
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 54 deletions.
16 changes: 15 additions & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/bin/sh
# Husky pre-commit hook to check commit messages using commitlint.

# Load Husky
. "$(dirname "$0")/_/husky.sh"

echo "Checking commit message 📝"
# Display a message indicating that commit message check is in progress
echo "Checking commit message..."

# Run commitlint with the provided commit message
pnpm commitlint --edit $1 -v

# Check the exit status of the previous command
if [ $? -ne 0 ]; then
echo "❌ Commit message check failed. Please follow the commit message conventions."
exit 1
else
echo "✅ Commit message check passed. Proceeding with the commit."
fi
15 changes: 15 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/usr/bin/env sh
# Husky pre-commit hook to run lint-staged using pnpm.

# Load Husky
. "$(dirname -- "$0")/_/husky.sh"

# Display a message indicating that lint-staged is running
echo "Running lint-staged..."

# Run lint-staged with pnpm
pnpm lint-staged

# Check the exit status of the previous command
if [ $? -ne 0 ]; then
echo "❌ lint-staged check failed. Please fix the issues before committing."
exit 1
else
echo "✅ lint-staged check passed. Proceeding with the commit."
fi
4 changes: 0 additions & 4 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
{
"path": "lib/index.d.ts",
"label": "Typings"
},
{
"path": "lib/index.global.js",
"Label": "Web"
}
]
}
Expand Down
47 changes: 26 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
# pokenode-ts

A lightweight Node.js wrapper for the PokéAPI with built-in types. An easy way to integrate your app with the PokéAPI.
**A lightweight Node.js wrapper for the PokéAPI with built-in types. An easy way to integrate your app with the PokéAPI.**

## Features

- 🛠️ Built-in typings
- 📦 Axios with auto-cache requests
- 🌲 Logging
- 🛠️ **Built-in typings**: TypeScript support with pre-defined types.
- 📦 **Axios with auto-cache requests**: Efficiently manage API requests with automatic caching.
- 🌲 **Logging**: Easily log and track your API interactions.

## Installation

```bash
# NPM
npm i axios axios-cache-interceptor pokenode-ts
npm install axios axios-cache-interceptor pokenode-ts

# Yarn
yarn add axios axios-cache-interceptor pokenode-ts

# Pnpm
pnpm i axios axios-cache-interceptor pokenode-ts
pnpm install axios axios-cache-interceptor pokenode-ts
```

## Basic Example

Using a client, like PokemonClient:

```js
```ts
import { PokemonClient } from 'pokenode-ts';

(async () => {
const api = new PokemonClient();

await api
.getPokemonByName('luxray')
.then((data) => console.log(data.name)) // will output "Luxray"
.catch((error) => console.error(error));
try {
const pokemonData = await api.getPokemonByName('luxray');
console.log(pokemonData.name); // Outputs "Luxray"
} catch (error) {
console.error(error);
}
})();

```

Or, using the MainClient:
Expand All @@ -46,10 +49,12 @@ import { MainClient } from 'pokenode-ts';
(async () => {
const api = new MainClient();

await api.pokemon
.getPokemonByName('luxray')
.then((data) => console.log(data.name)) // will output "Luxray"
.catch((error) => console.error(error));
try {
const pokemonData = await api.pokemon.getPokemonByName('luxray');
console.log(pokemonData.name); // Outputs "Luxray"
} catch (error) {
console.error(error);
}
})();
```

Expand All @@ -61,11 +66,11 @@ Check out our [Documentation page](https://pokenode-ts.vercel.app/)!

Every change in this project is analyzed by [SonarCloud](https://sonarcloud.io/)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Gabb-c_pokenode-ts&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Gabb-c_pokenode-ts)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Gabb-c_pokenode-ts&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Gabb-c_pokenode-ts)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=Gabb-c_pokenode-ts&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=Gabb-c_pokenode-ts)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Gabb-c_pokenode-ts&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Gabb-c_pokenode-ts)
[![codecov](https://codecov.io/gh/Gabb-c/pokenode-ts/branch/master/graph/badge.svg?token=whfY8GNSpS)](https://codecov.io/gh/Gabb-c/pokenode-ts)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Gabb-c_pokenode-ts&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Gabb-c_pokenode-ts 'Sonar Quality Gate Status')
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Gabb-c_pokenode-ts&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Gabb-c_pokenode-ts 'Sonar Bugs')
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=Gabb-c_pokenode-ts&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=Gabb-c_pokenode-ts 'Sonar Code Smells')
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Gabb-c_pokenode-ts&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Gabb-c_pokenode-ts 'Sonar Quality Gate Status')
[![codecov](https://codecov.io/gh/Gabb-c/pokenode-ts/branch/master/graph/badge.svg?token=whfY8GNSpS)](https://codecov.io/gh/Gabb-c/pokenode-ts 'Codecov Coverage Reports')

## Leave your feedback

Expand All @@ -75,6 +80,6 @@ Every change in this project is analyzed by [SonarCloud](https://sonarcloud.io/)

## Donate

Please consider donating if you think pokenode-ts is helpful to you or that my work is valuable. I am happy if you can [buy me a coffee](https://github.com/sponsors/Gabb-c) ❤️
If pokenode-ts is valuable to you, please consider [buying me a coffee](https://github.com/sponsors/Gabb-c) ❤️

![Analytics](https://repobeats.axiom.co/api/embed/f71a113e3161e1d054170c94e4ac3fcfc960cdd4.svg 'Repobeats analytics image')
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"formatWithErrors": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 100,
Expand Down
50 changes: 27 additions & 23 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
{
"compilerOptions": {
// Specifies the ECMAScript target version (latest features).
"target": "ESNext",
"lib": [
"ESNext"
],
// An array of library files to include in the compilation.
"lib": ["ESNext"],
// Allows JavaScript files to be included in the project.
"allowJs": true,
// Skips type checking of declaration files.
"skipLibCheck": true,
// Enables all strict type-checking options.
"strict": true,
// Prevents TypeScript from emitting output files (e.g., JavaScript files).
"noEmit": true,
// Adds `undefined` to the type of an indexing operation for possibly undefined objects.
"noUncheckedIndexedAccess": true,
// Ensures that the casing of referenced file names matches the casing of the actual file.
"forceConsistentCasingInFileNames": true,
// Generates corresponding `.d.ts` files for TypeScript files.
"declaration": false,
// Allows default imports from modules with no default export.
"esModuleInterop": true,
// Specifies the module code generation.
"module": "ESNext",
// Specifies how modules are resolved.
"moduleResolution": "Bundler",
// Enables experimental support for decorators.
"experimentalDecorators": true,
// Enables the metadata reflection for decorators.
"emitDecoratorMetadata": true,
// Allows importing JSON files as modules.
"resolveJsonModule": true,
// Transforms each file as a separate module, which can help catch more errors.
"isolatedModules": true,
// Specifies the base directory for resolving non-relative module names.
"baseUrl": ".",
// Defines path mappings for module names.
"paths": {
"@clients": [
"src/clients/index.ts"
],
"@config": [
"src/config/index.ts"
],
"@constants": [
"src/constants/index.ts"
],
"@models": [
"src/models/index.ts"
],
"@clients": ["src/clients/index.ts"],
"@config": ["src/config/index.ts"],
"@constants": ["src/constants/index.ts"],
"@models": ["src/models/index.ts"],
}
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts",
"**/*.test.ts"
]
// Specifies the files to include in the compilation.
"include": ["src/**/*"],
// Specifies files to be excluded from the compilation.
"exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"]
}
21 changes: 17 additions & 4 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,44 @@ import isCI from "is-ci";
import { defineConfig } from "tsup";
import { peerDependencies, author, version, license, description } from "./package.json";

// Extract peerDependencies from package.json
const EXTERNAL_DEPS = Object.keys(peerDependencies as Record<string, string>);

// Custom banner with improved formatting
const myBanner = `
/**
* Version ${version} | ${new Date().toLocaleDateString("en-us")}
* Build with Node ${process.version}
* Licensed under the ${license} license
* ${description}
* Version: ${version} | Build Date: ${new Date().toLocaleDateString("en-us")}
* Build Environment: Node ${process.version}
* License: ${license}
*
* _
* |_) _ | _ _ _ _| _ __ _|_ _
* | (_) |< (/_ | | (_) (_| (/_ |_ _>
*
* ${description}
* ${author.name} <${author.url}>
*/
`;

export default defineConfig({
// Entry file(s) for the bundling process
entry: ["src/index.ts"],
// Output directory for the bundled code
outDir: "lib",
// Enable code splitting for better performance
splitting: true,
// Specify external dependencies to exclude from the bundle
external: EXTERNAL_DEPS,
// Generate source maps if not running in a continuous integration environment
sourcemap: !isCI,
// Clean the output directory before each build if not in a continuous integration environment
clean: !isCI,
// Generate declaration files (.d.ts)
dts: true,
// Output formats: CommonJS and ECMAScript modules
format: ["cjs", "esm"],
// Minify the code if in a continuous integration environment
minify: isCI,
// Add a custom banner to the top of each bundled file
banner: { js: myBanner },
});

0 comments on commit 067095f

Please sign in to comment.