Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a779a7d
Initial plan
Copilot Nov 29, 2025
8c6c5ef
Add sync-examples script and CI workflow for playground-example sync
Copilot Nov 29, 2025
70b9c6a
Update examples README to document sync workflow
Copilot Nov 29, 2025
c666461
Merge branch 'main' into copilot/consolidate-playgrounds-examples
yamcodes Nov 29, 2025
82cbce5
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 29, 2025
005cdc2
Merge branch 'main' into copilot/consolidate-playgrounds-examples
yamcodes Nov 29, 2025
de71494
Sync all examples from playgrounds, including basic and basic-js
Copilot Dec 1, 2025
7950845
Merge branch 'main' into copilot/consolidate-playgrounds-examples
yamcodes Dec 9, 2025
185eed9
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 9, 2025
e9d3436
feat: Update example dependencies, refine package manager version syn…
yamcodes Dec 9, 2025
3071c40
Merge branch 'copilot/consolidate-playgrounds-examples' of https://gi…
yamcodes Dec 9, 2025
1ae9adb
chore: reorder devDependencies in basic example package.json files
yamcodes Dec 9, 2025
6bc2301
feat: Add example synchronization utility including file system helpe…
yamcodes Dec 9, 2025
36f0151
fix: Pin rolldown-vite dependency to 7.2.10 and unify file exclusion …
yamcodes Dec 9, 2025
79a8830
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 9, 2025
88a8f16
feat: Add `skipSync` option to bypass example synchronization.
yamcodes Dec 9, 2025
43fe889
feat: Introduce a new standard schema playground app, update existing…
yamcodes Dec 9, 2025
e5a8414
chore: Add type annotation to transform function and update pnpm lock…
yamcodes Dec 9, 2025
a721a0e
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 9, 2025
cbc9ce7
style: add explicit string type to Zod transformation parameter
yamcodes Dec 9, 2025
c2158c1
chore: reorder devDependencies in package.json
yamcodes Dec 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/sync-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: sync-examples

on:
pull_request:
paths:
- "apps/playgrounds/**"
- "examples/**"
- "bin/sync-examples.js"
push:
branches: ["main"]
paths:
- "apps/playgrounds/**"
- "examples/**"
- "bin/sync-examples.js"

permissions:
contents: read

jobs:
check-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Install pnpm
uses: pnpm/action-setup@v4

- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: "pnpm"
Comment thread
yamcodes marked this conversation as resolved.

- name: Install dependencies
run: pnpm install

- name: Build packages
run: pnpm build:packages

- name: Check examples sync
run: pnpm sync:examples:check
8 changes: 7 additions & 1 deletion apps/playgrounds/bun-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"rimraf": "catalog:"
}
},
"arkenvExamples": [
{
"name": "with-bun-react",
"packageManager": "bun"
}
]
}
15 changes: 10 additions & 5 deletions apps/playgrounds/bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"type": "module",
"private": true,
"scripts": {
"dev": "bun --watch .",
"start": "bun .",
"build": "bun build . --outdir=dist",
"preview": "bun dist",
"dev": "bun --watch run index.ts",
"start": "bun run index.ts",
"build": "bun build index.ts --outdir ./dist",
"fix": "pnpm -w run fix",
"clean": "rimraf dist node_modules"
},
Expand All @@ -19,5 +18,11 @@
"@types/bun": "catalog:",
"rimraf": "catalog:",
"typescript": "catalog:"
}
},
"arkenvExamples": [
{
"name": "with-bun",
"packageManager": "bun"
}
]
}
File renamed without changes.
77 changes: 77 additions & 0 deletions apps/playgrounds/js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# ArkEnv basic example (plain JavaScript)

This example shows how to use ArkEnv in a basic Node.js application.


## What's inside?

The example demonstrates:
- Setting up environment variables with ArkEnv
- Using default values
- Runtime-validated environment configuration

## Getting started

### Prerequisites

Make sure you have [Node.js](https://nodejs.org) installed. We recommend using [nvm](https://github.com/nvm-sh/nvm) to install it.

### Quickstart

1. #### Install dependencies
```bash
npm install
```

2. #### Start the development server with hot reloading enabled
```bash
npm run dev
```
:white_check_mark: You will see the environment variables printed in the console.

### Adding environment variables

With the development server running (if it isn't - just run `npm run dev`), let's see how to add a new environment variable. For this example, we'll add a new environment variable called `MY_ENV_VAR`.

1. #### Define the new environment variable in the schema as a _required_ string
```javascript
// index.js
const env = arkenv({
// other definitions...
MY_ENV_VAR: "string"
});
```

2. #### Notice the development server will show an error
```bash
ArkEnvError: Errors found while validating environment variables
MY_ENV_VAR must be a string (was missing)
```
This is **good**! It means the environment variable is required and the type is enforced. Let's see how to fix it. For this example, we will define the environment variable [with a `.env` file](https://arkenv.js.org/docs/arkenv/how-to/load-environment-variables#using-env-files).

3. #### Copy the `.env.example` file to `.env`

To keep the development server running, run this command in a new terminal window:
```bash
cp .env.example .env
```

4. #### Add a new environment variable to the `.env` file
```bash
echo "MY_ENV_VAR=new_value" >> .env
```

Notice the development server will once again print the existing environment variables.

5. #### Add the following line to the `index.js` file
```javascript
console.log(env.MY_ENV_VAR);
```
You will see the new environment variable printed in the console.

**Congratulations!** :tada: You've just added a new environment variable and printed its value.

### Next steps

- [ArkEnv docs](https://arkenv.js.org/docs/arkenv)
- [ArkType docs](https://arktype.io/)
17 changes: 17 additions & 0 deletions apps/playgrounds/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import arkenv from "arkenv";

const env = arkenv({
HOST: "string.host",
PORT: "number.port",
NODE_ENV: "'development' | 'production' | 'test' = 'development'",
});

// Automatically validate and parse process.env
// TypeScript knows the ✨exact✨ types!
const host = env.HOST;
const port = env.PORT;
const nodeEnv = env.NODE_ENV;

console.log({ host, port, nodeEnv });

export default env;
28 changes: 28 additions & 0 deletions apps/playgrounds/js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "js-playground",
"private": true,
"type": "module",
"scripts": {
"start": "node --env-file .env index.js",
"dev": "node --watch --env-file .env index.js",
"dev:example": "node --watch --env-file .env.example index.js",
"fix": "pnpm -w run fix",
"clean": "rimraf dist node_modules"
},
"dependencies": {
"arkenv": "workspace:*",
"arktype": "catalog:"
},
"engines": {
"node": "24"
},
"stackblitz": {
"startCommand": "npm install && npm run dev:example"
},
"arkenvExamples": [
{
"name": "basic-js",
"packageManager": "npm"
}
]
}
12 changes: 12 additions & 0 deletions apps/playgrounds/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist"
}
}
79 changes: 75 additions & 4 deletions apps/playgrounds/node/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,77 @@
# Playground
# ArkEnv basic example

A free TypeScript playground for testing ArkEnv.
This example shows how to use ArkEnv in a basic Node.js application.

> [!TIP]
> This app uses `workspace:*` for the package version, allowing you to test your local changes. You must build the package after making changes.

## What's inside?

The example demonstrates:
- Setting up environment variables with ArkEnv
- Using default values
- Typesafe environment configuration

## Getting started

### Prerequisites

Make sure you have [Node.js](https://nodejs.org) installed. We recommend using [nvm](https://github.com/nvm-sh/nvm) to install it.

### Quickstart

1. #### Install dependencies
```bash
npm install
```

2. #### Start the development server with hot reloading enabled
```bash
npm run dev
```
:white_check_mark: You will see the environment variables printed in the console.

### Adding environment variables

With the development server running (if it isn't - just run `npm run dev`), let's see how to add a new environment variable. For this example, we'll add a new environment variable called `MY_ENV_VAR`.

1. #### Define the new environment variable in the schema as a _required_ string
```typescript
// index.ts
const env = arkenv({
// other definitions...
MY_ENV_VAR: "string"
});
```

2. #### Notice the development server will show an error
```bash
ArkEnvError: Errors found while validating environment variables
MY_ENV_VAR must be a string (was missing)
```
This is **good**! It means the environment variable is required and the type is enforced. Let's see how to fix it. For this example, we will define the environment variable [with a `.env` file](https://arkenv.js.org/docs/arkenv/how-to/load-environment-variables#using-env-files).

3. #### Copy the `.env.example` file to `.env`

To keep the development server running, run this command in a new terminal window:
```bash
cp .env.example .env
```

4. #### Add a new environment variable to the `.env` file
```bash
echo "MY_ENV_VAR=new_value" >> .env
```

Notice the development server will once again print the existing environment variables.

5. #### Add the following line to the `index.ts` file
```typescript
console.log(env.MY_ENV_VAR);
```
You will see the new environment variable printed in the console.

**Congratulations!** :tada: You've just added a new environment variable and printed its value.

### Next steps

- [ArkEnv docs](https://arkenv.js.org/docs/arkenv)
- [ArkType docs](https://arktype.io/)
21 changes: 18 additions & 3 deletions apps/playgrounds/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"private": true,
"type": "module",
"scripts": {
"dev": "tsx watch --env-file .env index.ts",
"start": "tsx --env-file .env index.ts",
"dev": "tsx watch --env-file .env index.ts",
"dev:example": "tsx watch --env-file .env.example index.ts",
"build": "tsc",
"fix": "pnpm -w run fix",
"clean": "rimraf dist node_modules"
},
Expand All @@ -16,6 +18,19 @@
"devDependencies": {
"@types/node": "catalog:",
"rimraf": "catalog:",
"tsx": "catalog:"
}
"tsx": "catalog:",
"typescript": "catalog:"
},
"engines": {
"node": "24"
},
"stackblitz": {
"startCommand": "npm install && npm run dev:example"
},
"arkenvExamples": [
{
"name": "basic",
"packageManager": "npm"
}
]
}
Loading
Loading