Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prepare storage-s3 module #13

Merged
merged 15 commits into from
Dec 18, 2024
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ permissions:
contents: read

env:
NODE_ENV: production
JSR_DEPENDENCIES: "@cross/test @std/assert @std/fmt @frytg/logger"
NPM_DEPENDENCIES: "luxon sinon"
NPM_DEPENDENCIES: "luxon minio sinon"

jobs:
test-on-deno-and-lint:
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"files": {
"maxSize": 2097152,
"ignore": ["*.vue", "vendor"]
"ignore": ["*.vue", "coverage", "node_modules", "vendor"]
},
"formatter": {
"indentStyle": "tab",
Expand Down
13 changes: 13 additions & 0 deletions check-required-env/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Check Required Env Changelog

## 2024-12-17 - 0.1.0

- feat: add `getRequiredEnv`

## 2024-11-27 - 0.0.1

- feat: add test for required env

## 2024-11-22 - 0.0.1

- feat: add check required env
4 changes: 2 additions & 2 deletions check-required-env/check-required-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import logger from '@frytg/logger'
/**
* Check if an environment variable is required and log an alert and exit if it is not set.
*
* @param name - The name of the environment variable.
* @returns void
* @param {string} name - The name of the environment variable.
* @returns {void}
*
* @example
* ```ts
Expand Down
7 changes: 5 additions & 2 deletions check-required-env/deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"$schema": "https://jsr.io/schema/config-file.v1.json",
"name": "@frytg/check-required-env",
"version": "0.0.1",
"exports": "./check-required-env.ts",
"version": "0.1.0",
"exports": {
".": "./check-required-env.ts",
"./get": "./get-required-env.ts"
},
"imports": {
"@frytg/logger": "jsr:@frytg/[email protected]"
}
Expand Down
34 changes: 34 additions & 0 deletions check-required-env/get-required-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// load packages
import process from 'node:process'
import logger from '@frytg/logger'

/**
* Access an environment variable and log an alert and exit if it is not set.
*
* @param {string} name - The name of the environment variable.
* @param {boolean} preferThrowError - Whether to throw an error if the environment variable is not set.
* @returns {string} The value of the environment variable.
*
* @example
* ```ts
* import { getRequiredEnv } from '@frytg/check-required-env/get'
*
* getRequiredEnv('MY_IMPORTANT_ENV_VAR', false)
* ```
*/
export const getRequiredEnv = (name: string, preferThrowError = true): string => {
const value = process.env[name]

// return if the env variable is set
if (value !== undefined) return value

// log and exit if not set
logger.log({
level: 'alert',
message: `env ${name} is required`,
source: 'getRequiredEnv',
data: { name },
})
if (preferThrowError) throw new Error(`env ${name} is required`)
process.exit(1)
}
3 changes: 2 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"tasks": {
"check": "deno fmt --check && deno lint && biome lint",
"dry-run": "deno publish --dry-run",
"test": "deno test --allow-sys --allow-env --clean --coverage"
},
"lint": {
Expand All @@ -30,7 +31,7 @@
},
"exclude": ["**/*.md", "**/*.yml", "**/*.yaml"]
},
"workspace": ["./check-required-env", "./crypto", "./dates", "./logger"],
"workspace": ["./check-required-env", "./crypto", "./dates", "./logger", "./storage-s3"],
"imports": {
"@biomejs/biome": "npm:@biomejs/biome@^1.9.4",
"@types/node": "npm:@types/node@^22.10.2",
Expand Down
Loading
Loading