Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
86 changes: 86 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CI/CD Pipeline

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
release:
types: [published]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install --ignore-scripts

- name: Run tests
run: npm test

- name: Run examples
run: |
node examples/basic-usage.js
node examples/advanced-usage.js
node examples/user-management.js

publish:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm install --ignore-scripts

- name: Run tests
run: npm test

- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'

- name: Check package.json
run: |
echo "Checking package.json validity..."
node -e "console.log('package.json is valid JSON')"

- name: Check for required files
run: |
echo "Checking for required files..."
test -f README.md || (echo "README.md not found" && exit 1)
test -f LICENSE || (echo "LICENSE not found" && exit 1)
test -f package.json || (echo "package.json not found" && exit 1)
test -f CHANGELOG.md || (echo "CHANGELOG.md not found" && exit 1)
echo "All required files found"
5 changes: 2 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Development files
test/
examples/
.git/
.gitignore

# Test data
# Test data (but keep test files)
**/data/
test-data/
examples/data/*.json

# Development dependencies
node_modules/
Expand Down
57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2025-07-07

### Added
- Initial release of JsonFileCRUD
- Complete CRUD operations (Create, Read, Update, Delete)
- Auto-ID assignment with duplicate prevention
- Configurable ID fields (default: 'id')
- Thread-safe operations with automatic queuing
- Comprehensive error handling and validation
- Zero external dependencies
- Full ESM (ES modules) support
- Comprehensive test suite with 35 tests
- Practical usage examples:
- Basic CRUD operations
- Advanced features with concurrent operations
- User management system example
- Complete API documentation
- Contributing guidelines with improvement ideas

### Features
- **create(item, callback)** - Create new items with auto-ID
- **readAll(callback)** - Read all items from file
- **findById(id, callback)** - Find item by ID
- **findBy(filterFn, callback)** - Find items by custom filter
- **update(id, data, callback)** - Update existing items
- **delete(id, callback)** - Delete items by ID
- **count(callback)** - Get total item count
- **writeAll(items, callback)** - Replace all data

### Performance
- Optimized for small to medium datasets (up to ~10,000 items)
- Sequential operations prevent race conditions
- Automatic file creation on first write
- Memory-efficient data handling

### Documentation
- Complete README with API reference
- Multiple practical examples
- Error handling guide
- Performance considerations
- Contributing guidelines

## [Unreleased]

### Future Improvements
- TypeScript support with .d.ts files
- Promise-based API (async/await)
- Batch operations (createMany, updateMany, deleteMany)
- File locking for multi-process safety
- Enhanced documentation and examples
108 changes: 108 additions & 0 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Publishing Guide

This guide explains how to publish new versions of JsonFileCRUD to npm.

## Prerequisites

1. **npm account**: Make sure you have an npm account and are logged in
```bash
npm login
```

2. **npm token**: For GitHub Actions, add your npm token to repository secrets as `NPM_TOKEN`

3. **Repository access**: Make sure you have push access to the GitHub repository

## Publishing Process

### Option 1: Manual Publishing (Recommended for first time)

1. **Update version and changelog:**
```bash
npm version patch # for bug fixes
npm version minor # for new features
npm version major # for breaking changes
```

2. **Verify everything works:**
```bash
npm test
npm run examples
```

3. **Check what will be published:**
```bash
npm pack --dry-run
```

4. **Publish to npm:**
```bash
npm publish
```

### Option 2: Automated Publishing via GitHub Releases

1. **Create a new release on GitHub:**
- Go to the repository on GitHub
- Click "Releases" → "Create a new release"
- Tag version: `v1.0.0` (match package.json version)
- Release title: `Version 1.0.0`
- Description: Copy from CHANGELOG.md

2. **GitHub Actions will automatically:**
- Run all tests
- Run examples
- Publish to npm (if tests pass)

### Option 3: Using npm version command

```bash
# This will:
# 1. Run tests
# 2. Run examples
# 3. Update version in package.json
# 4. Create git tag
# 5. Push to GitHub
npm version patch
```

Then create a GitHub release for the new tag to trigger npm publishing.

## Version Guidelines

- **Patch (1.0.X)**: Bug fixes, documentation updates
- **Minor (1.X.0)**: New features, non-breaking changes
- **Major (X.0.0)**: Breaking changes

## Checklist Before Publishing

- [ ] All tests pass (`npm test`)
- [ ] Examples work (`npm run examples`)
- [ ] CHANGELOG.md updated
- [ ] README.md updated if needed
- [ ] Version number updated in package.json
- [ ] Git changes committed and pushed

## Post-Publishing

1. **Verify the package:**
```bash
npm view json-file-crud
```

2. **Test installation:**
```bash
mkdir test-install
cd test-install
npm init -y
npm install json-file-crud
```

3. **Update documentation** if needed

## Troubleshooting

- **403 Forbidden**: Make sure you're logged in and have permission to publish
- **Version already exists**: Update the version number
- **Tests fail**: Fix issues before publishing
- **Missing files**: Check .npmignore and package.json files array
27 changes: 24 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "json-file-crud",
"version": "1.0.0",
"title": "JsonFileCRUD",
"description": "CRUD operations for JSON files",
"description": "A simple, robust, and thread-safe CRUD library for managing JSON objects in files",
"main": "./lib/json-file-crud.js",
"type": "module",
"scripts": {
Expand All @@ -14,19 +14,40 @@
"test:update": "node test/test-update.js",
"test:delete": "node test/test-delete.js",
"test:advanced-create": "node test/test-advanced-create.js",
"prepublishOnly": "npm test"
"examples": "node examples/basic-usage.js && node examples/advanced-usage.js && node examples/user-management.js",
"examples:basic": "node examples/basic-usage.js",
"examples:advanced": "node examples/advanced-usage.js",
"examples:user": "node examples/user-management.js",
"version": "npm test && npm run examples && git add CHANGELOG.md",
"preversion": "npm test",
"postversion": "git push && git push --tags",
"prepublishOnly": "npm test && npm run examples"
},
"keywords": [
"crud",
"json",
"file",
"database",
"async",
"callback"
"callback",
"nodejs",
"thread-safe",
"queue",
"auto-id",
"lightweight",
"zero-dependencies"
],
"engines": {
"node": ">=14.0.0"
},
"files": [
"lib/",
"examples/",
"test/",
"README.md",
"CHANGELOG.md",
"LICENSE"
],
"homepage": "https://github.com/r-el/json-file-crud",
"repository": {
"type": "git",
Expand Down