Skip to content

Commit

Permalink
Merge pull request #13 from frytg/dev/storage-s3
Browse files Browse the repository at this point in the history
feat: prepare `storage-s3` module
  • Loading branch information
frytg authored Dec 18, 2024
2 parents e9519f1 + 2729d91 commit 3564c34
Show file tree
Hide file tree
Showing 14 changed files with 603 additions and 7 deletions.
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

0 comments on commit 3564c34

Please sign in to comment.