G1 TypeScript Common Packages

This monorepo contains common TypeScript packages used across Generation One projects.

Repository Structure

g1-ts-common-packages/
├── packages/                 # All packages are stored here
│   ├── sse-client/           # Server-Sent Events client package
│   └── [future-packages]/    # Additional packages will be added here
├── scripts/                  # Utility scripts for the repository
├── docs/                     # Documentation
└── .github/workflows/        # CI/CD workflows

Available Packages

SSE Client (@g1/sse-client)

A custom Server-Sent Events (SSE) client that supports headers and bypasses certificate issues.

  • Supports custom headers for SSE connections
  • Handles reconnection with exponential backoff
  • Works in both browser and Node.js environments
  • Provides connection management utilities

Getting Started

Prerequisites

  • Node.js 16+
  • pnpm (recommended) or npm

Installation

Clone the repository:

git clone https://git.generation.one/GenerationOne/g1-ts-common-packages.git
cd g1-ts-common-packages

Install dependencies:

pnpm install

Build all packages:

pnpm build

Using the Packages

In Another Project

Add the package to your project:

# Configure the Gitea registry
echo "@g1:registry=https://git.generation.one/api/packages/GenerationOne/npm/" > .npmrc
echo "//git.generation.one/api/packages/GenerationOne/npm/:_authToken=${GITEA_TOKEN}" >> .npmrc

# Install the package
pnpm add @g1/sse-client

Example Usage

import { SSEClient } from '@g1/sse-client';

// Create a new SSE client
const client = new SSEClient('https://api.example.com/events', {
  headers: {
    'Authorization': 'Bearer your-token'
  }
});

// Connect to the SSE endpoint
client.connect();

// Add event listeners
client.on('message', (event) => {
  console.log('Received message:', event.data);
});

// Close the connection when done
client.close();

Development

Adding a New Package

  1. Create a new directory in the packages folder
  2. Initialize the package with pnpm init
  3. Set the package name with the @g1 scope (e.g., @g1/your-package-name)
  4. Set the initial version to 0.2.0 (our standard starting version)
  5. Add your code and build configuration

Building Packages

To build a specific package:

cd packages/package-name
pnpm build

To build all packages:

pnpm -r build

Testing Packages

To run tests for a specific package:

cd packages/package-name
pnpm test

To test all packages:

pnpm -r test

Publishing Packages

Prerequisites

  • Gitea access token with packages:write permission
  • Access to the Generation One Gitea repository

Publishing a Package

Use the provided script:

# Set your Gitea token
export GITEA_TOKEN="your-token-here"
# Or create a .gitea-token file in the root directory

# Publish with a patch version bump
./scripts/publish-package.sh packages/sse-client patch

# Publish with a specific version
./scripts/publish-package.sh packages/sse-client version:0.3.0

# Publish without changing the version
./scripts/publish-package.sh packages/sse-client none

For more detailed publishing instructions, see docs/DEPLOY_KEYS.md.

CI/CD

This repository includes GitHub Actions workflows for automated testing and publishing:

  • Publish Package: Publishes a package to the Gitea registry

To use the workflows, you need to set up the following secrets in your GitHub repository:

  • GITEA_TOKEN: Your Gitea access token
  • GITEA_DEPLOY_KEY: SSH deploy key for the repository

License

MIT

Description
No description provided
Readme 186 KiB
Languages
TypeScript 60.6%
JavaScript 12.9%
HTML 10.3%
Shell 9.4%
Vue 6.8%