-
Notifications
You must be signed in to change notification settings - Fork 6
Add playground-to-example sync infrastructure #468
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a779a7d
Initial plan
Copilot 8c6c5ef
Add sync-examples script and CI workflow for playground-example sync
Copilot 70b9c6a
Update examples README to document sync workflow
Copilot c666461
Merge branch 'main' into copilot/consolidate-playgrounds-examples
yamcodes 82cbce5
[autofix.ci] apply automated fixes
autofix-ci[bot] 005cdc2
Merge branch 'main' into copilot/consolidate-playgrounds-examples
yamcodes de71494
Sync all examples from playgrounds, including basic and basic-js
Copilot 7950845
Merge branch 'main' into copilot/consolidate-playgrounds-examples
yamcodes 185eed9
[autofix.ci] apply automated fixes
autofix-ci[bot] e9d3436
feat: Update example dependencies, refine package manager version syn…
yamcodes 3071c40
Merge branch 'copilot/consolidate-playgrounds-examples' of https://gi…
yamcodes 1ae9adb
chore: reorder devDependencies in basic example package.json files
yamcodes 6bc2301
feat: Add example synchronization utility including file system helpe…
yamcodes 36f0151
fix: Pin rolldown-vite dependency to 7.2.10 and unify file exclusion …
yamcodes 79a8830
[autofix.ci] apply automated fixes
autofix-ci[bot] 88a8f16
feat: Add `skipSync` option to bypass example synchronization.
yamcodes 43fe889
feat: Introduce a new standard schema playground app, update existing…
yamcodes e5a8414
chore: Add type annotation to transform function and update pnpm lock…
yamcodes a721a0e
[autofix.ci] apply automated fixes
autofix-ci[bot] cbc9ce7
style: add explicit string type to Zod transformation parameter
yamcodes c2158c1
chore: reorder devDependencies in package.json
yamcodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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" | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install | ||
|
|
||
| - name: Build packages | ||
| run: pnpm build:packages | ||
|
|
||
| - name: Check examples sync | ||
| run: pnpm sync:examples:check | ||
This file contains hidden or 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
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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,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/) |
This file contains hidden or 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,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; |
This file contains hidden or 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 @@ | ||
| { | ||
| "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" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,12 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "module": "ESNext", | ||
| "moduleResolution": "Bundler", | ||
| "esModuleInterop": true, | ||
| "strict": true, | ||
| "skipLibCheck": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "outDir": "./dist" | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -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/) |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.