-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
562 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
name: Continuous Integration - Config | ||
|
||
on: | ||
push: | ||
paths: | ||
- ".github/workflows/ci-config.yml" | ||
- "packages/config/**" | ||
pull_request: | ||
paths: | ||
- ".github/workflows/ci-config.yml" | ||
- "packages/config/**" | ||
|
||
jobs: | ||
linter: | ||
name: Lint Code | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
run_install: false | ||
|
||
- name: Get pnpm store directory | ||
shell: bash | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | ||
- uses: actions/cache@v3 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ env.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Lint code | ||
run: pnpm --filter "./packages/config" run lint | ||
|
||
test: | ||
name: Test | ||
runs-on: ${{ matrix.os }} | ||
permissions: | ||
contents: read | ||
strategy: | ||
matrix: | ||
node-version: [18, 20] | ||
os: [macos-latest, ubuntu-latest, windows-latest] | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Setup Node ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
run_install: false | ||
|
||
- name: Get pnpm store directory | ||
shell: bash | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | ||
- uses: actions/cache@v3 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ env.STORE_PATH }} | ||
key: ${{ runner.os }}-${{ matrix.node-version }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.node-version }}-pnpm-store- | ||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Run tests | ||
run: pnpm --filter "./packages/config" run test | ||
|
||
automerge: | ||
name: Automerge Dependabot PRs | ||
if: > | ||
github.event_name == 'pull_request' && | ||
github.event.pull_request.user.login == 'dependabot[bot]' | ||
needs: test | ||
permissions: | ||
pull-requests: write | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: fastify/github-action-merge-dependabot@v3 | ||
with: | ||
exclude: ${{ inputs.auto-merge-exclude }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
target: major |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"extends": "standard-with-typescript", | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"rules": { | ||
// conflict between standard and standard-typescript | ||
"no-void": ["error", { "allowAsStatement": true }] | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["**/*.test.ts"], | ||
"rules": { | ||
"@typescript-eslint/no-floating-promises": "off" | ||
} | ||
}, | ||
{ | ||
"files": ["scripts/*.mjs"], | ||
"rules": { | ||
"@typescript-eslint/explicit-function-return-type": "off" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# Project Source Files | ||
.yarn | ||
test/ | ||
bin/ | ||
.vscode/ | ||
.github/ | ||
|
||
.eslint* | ||
.git* | ||
.prettier* | ||
jest* | ||
|
||
lib/**/*.ts | ||
!lib/**/*.d.ts | ||
scripts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# @kakang/fastify-config | ||
|
||
[![Continuous Integration](https://github.com/kaka-repo/fastify-plugins/actions/workflows/ci-config.yml/badge.svg)](https://github.com/kaka-repo/fastify-plugins/actions/workflows/ci-config.yml) | ||
[![NPM version](https://img.shields.io/npm/v/@kakang/fastify-config.svg?style=flat)](https://www.npmjs.com/package/@kakang/fastify-config) | ||
|
||
This plugin use `env-schema` to read the .env file and provides | ||
the value through variables and fastify plugin. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @kakang/fastify-config --save | ||
|
||
yarn add @kakang/fastify-config | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { build } from '@kakang/fastify-config' | ||
|
||
const { env, plugin } = build({ | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
FOO: { type: 'string' } | ||
} | ||
}, | ||
data: process.env | ||
dotenv: true | ||
}) | ||
|
||
fastify.register(plugin) | ||
|
||
fastify.config // here is the env value | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import envSchema, { type EnvSchemaData, type EnvSchemaOpt } from 'env-schema' | ||
import { type FastifyPluginCallback } from 'fastify' | ||
import FastifyPlugin from 'fastify-plugin' | ||
|
||
export function build <T = EnvSchemaData> (options: EnvSchemaOpt<T>): { env: T, plugin: FastifyPluginCallback } { | ||
const env = envSchema<T>(options) | ||
|
||
const plugin: FastifyPluginCallback = function (fastify, _, done) { | ||
fastify.decorate('config', env as unknown) | ||
done() | ||
} | ||
FastifyPlugin(plugin, { | ||
fastify: '4.x', | ||
name: '@kakang/fastify-config', | ||
decorators: { | ||
fastify: [], | ||
request: [], | ||
reply: [] | ||
}, | ||
dependencies: [], | ||
encapsulate: false | ||
}) | ||
|
||
return { | ||
env, | ||
plugin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
Oops, something went wrong.