Skip to content

Commit f5ab47c

Browse files
committed
Packaging
1 parent b85d96c commit f5ab47c

File tree

5 files changed

+143
-4
lines changed

5 files changed

+143
-4
lines changed

.github/workflows/publish.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish Package to NPM
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Use Node.js
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: '18.x'
18+
registry-url: 'https://registry.npmjs.org'
19+
cache: 'npm'
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Verify package version matches release tag
25+
run: |
26+
PKG_VERSION=$(node -p "require('./package.json').version")
27+
GITHUB_REF_NAME=${GITHUB_REF#refs/tags/}
28+
GITHUB_TAG=${GITHUB_REF_NAME#v}
29+
echo "Package version: $PKG_VERSION"
30+
echo "GitHub tag (without v): $GITHUB_TAG"
31+
if [ "$PKG_VERSION" != "$GITHUB_TAG" ] && [ "$PKG_VERSION" != "${GITHUB_TAG#v}" ]; then
32+
echo "⚠️ WARNING: GitHub release tag ($GITHUB_REF_NAME) doesn't match package.json version ($PKG_VERSION)"
33+
echo "The package will be published with the version from package.json: $PKG_VERSION"
34+
fi
35+
36+
- name: Build
37+
run: npm run build
38+
39+
- name: Test
40+
run: npm test
41+
42+
- name: Verify dual module compatibility
43+
run: |
44+
node -e "require('./dist/index.js')" # Test CJS
45+
node --input-type=module -e "import * as mod from './dist/index.mjs'; console.log(typeof mod.convertJsonSchemaToZod === 'function')" # Test ESM
46+
47+
- name: Publish to NPM
48+
run: npm publish
49+
env:
50+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- Initial implementation of JSON Schema to Zod conversion
12+
- Support for basic types (string, number, integer, boolean, null, object, array)
13+
- String validations (minLength, maxLength, pattern)
14+
- Number validations (minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf)
15+
- Array validations (minItems, maxItems, uniqueItems)
16+
- Object validations (required properties, additionalProperties)
17+
- Schema composition (const, enum, anyOf, allOf, oneOf)
18+
- Dual module support (CommonJS and ESM)
19+
- GitHub Actions CI workflow
20+
- GitHub Actions publish workflow

CLAUDE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# zod-from-json-schema Development Guidelines
2+
3+
## Commands
4+
- **Build:** `npm run build` (generates CJS and ESM outputs)
5+
- **Test all:** `npm test`
6+
- **Test single file:** `npx vitest run src/path/to/file.test.ts`
7+
- **Test with pattern:** `npx vitest run -t "test pattern"`
8+
- **Clean:** `npm run clean` (removes dist directory)
9+
10+
## Code Style
11+
- **TypeScript:** Use strict types, avoid `any` except in JSON Schema interfaces
12+
- **Imports:** Use named imports from zod (`import { z } from "zod"`)
13+
- **Formatting:** 4-space indentation, avoid lines > 80 chars
14+
- **Naming:** Use camelCase for functions/variables, PascalCase for types/interfaces
15+
- **Error handling:** Use Zod's built-in validation or custom refinements
16+
- **Comments:** Document functions with JSDoc comments including params, return types
17+
- **Compatibility:** Keep dual-module support (CJS/ESM) for all exported functions
18+
19+
## Architecture
20+
- Functions should be pure with no side effects
21+
- Keep JSON Schema to Zod conversion logic separate from utility functions
22+
- Write tests for each supported feature and edge case

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ const jsonSchema = {
7676
const zodSchema = convertJsonSchemaToZod(jsonSchema);
7777

7878
// Use the Zod schema to validate data
79-
const validData = zodSchema.parse({
80-
name: "John Doe",
81-
age: 30
82-
});
79+
try {
80+
const validData = zodSchema.parse({
81+
name: "John Doe",
82+
age: 30
83+
});
84+
console.log("Valid data:", validData);
85+
} catch (error) {
86+
console.error("Validation error:", error);
87+
}
8388
```
8489

8590
## Supported JSON Schema Features

RELEASE.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Release Process for zod-from-json-schema
2+
3+
This document outlines the steps to create a new release of the package.
4+
5+
## Release Steps
6+
7+
1. **Update package version in package.json**:
8+
```bash
9+
# From the project root directory
10+
npm version patch # For a bug fix (0.0.x)
11+
npm version minor # For new features (0.x.0)
12+
npm version major # For breaking changes (x.0.0)
13+
```
14+
This will automatically:
15+
- Update the version in package.json
16+
- Create a git commit with that change
17+
- Create a git tag for the version
18+
19+
2. **Push the changes and tag**:
20+
```bash
21+
git push origin main --tags
22+
```
23+
24+
3. **Create a GitHub Release**:
25+
- Go to the "Releases" section of your GitHub repository
26+
- Click "Draft a new release"
27+
- Select the tag you just pushed (should match the version in package.json)
28+
- Add a title and description for the release
29+
- Click "Publish release"
30+
31+
4. **Monitor the GitHub Actions workflow**:
32+
- The publish workflow will trigger automatically when the release is created
33+
- It will verify that the package version matches the release tag
34+
- It will build, test, and publish the package to npm
35+
- You can monitor progress in the "Actions" tab of your GitHub repository
36+
37+
## Important Notes
38+
39+
- The version in package.json determines what version is published to npm
40+
- The GitHub release tag should match the version in package.json (with or without a leading 'v')
41+
- If there is a mismatch, the workflow will warn you but will still publish using the version in package.json
42+
- Make sure to update the CHANGELOG.md file before creating a release

0 commit comments

Comments
 (0)