Skip to content

codenote-net/github-rag-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub RAG Examples

A Node.js project that demonstrates running TypeScript files natively without transpilation using Node.js v22.15.0+ and the experimental type stripping feature.

Prerequisites

  • Node.js v22.15.0 or higher
  • npm (comes with Node.js)

Setup

  1. Clone this repository:

    git clone https://github.com/codenote-net/github-rag-examples.git
    cd github-rag-examples
  2. Install dependencies:

    npm install

Running TypeScript Natively

This project is configured to run TypeScript files directly with Node.js without the need for transpilation, using the --experimental-strip-types flag.

Basic TypeScript Example

Run the basic example:

npm start

This executes the src/index.ts file directly using Node.js.

GitHub Repository Clone Script

This project includes a script to clone a GitHub repository using a GitHub App installation token. The script uses the x-access-token authentication method as described in the GitHub documentation.

How the Clone Script Works

The src/clone-repo.ts script:

  1. Uses the GitHub App installation token with the x-access-token authentication method
  2. Validates environment variables for token and repository information
  3. Constructs a secure clone URL with the token
  4. Removes any existing clone directory to ensure a clean clone
  5. Clones the repository with optimized options:
    • --single-branch: Clones only the default branch
    • --no-tags: Skips downloading tags
    • --depth 1: Creates a shallow clone with only the latest commit

The script is configured in package.json to run with the --experimental-strip-types flag, which enables TypeScript execution without transpilation:

{
  "scripts": {
    "clone": "node --experimental-strip-types src/clone-repo.ts"
  }
}

Usage

  1. Set the required environment variables:
export GITHUB_TOKEN="your_github_app_installation_token"
export REPO_OWNER="repository_owner"
export REPO_NAME="repository_name"
export CLONE_DIR="./cloned-repo"  # Optional, defaults to './cloned-repo'
  1. Run the clone script using npm:
npm run clone

This command executes the TypeScript file directly using Node.js with type stripping, eliminating the need for a separate build step before running the script.

How It Works

Starting with Node.js v22.6.0, Node.js has experimental support for TypeScript syntax through "type stripping". This allows you to run valid TypeScript code directly in Node.js without the need to transpile it first.

From Node.js v23.6.0 onwards, type stripping is enabled by default, but this project explicitly uses the flag for compatibility with Node.js v22.x.

Project Structure

  • /src - TypeScript source files
  • package.json - Project configuration

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published