### Usage examples for releasearoni version subcommand Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md Examples demonstrating how to use the releasearoni version subcommand within npm scripts, including options for custom changelog paths, additional staged files, and breaking change patterns. ```bash # Default usage "version": "releasearoni version" # With additional staged files "version": "releasearoni version --add package-lock.json" # Custom changelog path "version": "releasearoni version --changelog HISTORY.md" # Custom breaking pattern "version": "releasearoni version --breaking-pattern 'BREAKING CHANGE:|breaking:'" ``` -------------------------------- ### Create GitHub Release with releasearoni-gh CLI Source: https://context7.com/bcomnes/releasearoni/llms.txt A command-line interface that acts as a wrapper for the `gh release create` command, simplifying GitHub release creation when the GitHub CLI is installed and authenticated. It supports basic release creation, dry runs, prereleases with assets, and specifying custom repositories. ```bash # Basic release using gh CLI releasearoni-gh -y # Preview release releasearoni-gh --dry-run # Create prerelease with assets releasearoni-gh --prerelease --assets "dist/bundle.js" -y # Custom repository releasearoni-gh --owner myorg --repo myrepo -y ``` -------------------------------- ### Configure npm scripts for Releasearoni Source: https://context7.com/bcomnes/releasearoni/llms.txt Integrates Releasearoni into the npm lifecycle by defining versioning and release scripts within the package.json file. This setup enables automated changelog generation and GitHub release creation during the standard npm release process. ```json { "name": "my-package", "version": "1.0.0", "repository": { "type": "git", "url": "https://github.com/owner/repo.git" }, "scripts": { "version": "releasearoni version", "release": "git push --follow-tags && releasearoni -y", "prepublishOnly": "npm run build && git push --follow-tags && releasearoni-gh -y" } } ``` -------------------------------- ### Get Release Defaults with releasearoni Source: https://context7.com/bcomnes/releasearoni/llms.txt Reads package.json, CHANGELOG.md, and optionally lerna.json to derive release defaults. It validates version synchronization and checks for unreleased content. Supports GitHub Enterprise mode. ```javascript import { getDefaults } from 'releasearoni/lib/get-defaults.js' // Get defaults from current directory const defaults = await getDefaults(process.cwd()) console.log(defaults) // => { // body: '### Added\n- New feature...', // assets: null, // owner: 'bcomnes', // repo: 'releasearoni', // dryRun: false, // yes: false, // endpoint: 'https://api.github.com', // workpath: '/path/to/project', // prerelease: false, // draft: false, // target_commitish: 'abc123def456...', // tag_name: 'v1.0.0', // name: 'v1.0.0', // } // GitHub Enterprise mode const enterpriseDefaults = await getDefaults('/path/to/project', true) // Error cases try { await getDefaults('/path/to/project') } catch (error) { // Possible errors: // - "You must define a repository for your module" // - "The repository defined in your package.json is invalid" // - "Unreleased changes detected in CHANGELOG.md, aborting" // - "CHANGELOG.md does not contain any versions" // - "CHANGELOG.md out of sync with package.json (v1.0.0 !== v1.0.1)" // - "CHANGELOG.md out of sync with lerna.json (v1.0.0 !== v1.0.1)" } ``` -------------------------------- ### Implement thin wrapper for GitHub releases using Node.js Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md This snippet demonstrates a conceptual implementation of a wrapper that delegates release creation to the official GitHub CLI. It reads project defaults from package.json and the changelog, then executes the 'gh' command with the appropriate arguments. ```javascript import { execFileSync } from 'node:child_process' async function createRelease(opts) { const defaults = await getDefaults(opts.workpath) // pkg.json + changelog const merged = { ...defaults, ...opts } // Write body to temp file (avoids shell escaping issues) const bodyFile = writeTempFile(merged.body) const args = [ 'release', 'create', merged.tag_name, '--title', merged.name, '--notes-file', bodyFile, '--target', merged.target_commitish, ...(merged.draft ? ['--draft'] : []), ...(merged.prerelease ? ['--prerelease'] : []), ...(merged.assets ?? []), ] execFileSync('gh', args, { stdio: 'inherit' }) } ``` -------------------------------- ### Releasearoni CLI Options Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md Lists the available command-line options for the releasearoni CLI tool, including short flags, descriptions, and default values for various release management tasks. ```bash $ releasearoni [options] --tag-name, -t Tag for this release --target-commitish, -c Commitish value for tag --name, -n Release title --body, -b Release body text --owner, -o Repo owner --repo, -r Repo name --draft, -d Publish as draft (default: false) --prerelease, -p Publish as prerelease (default: false) --workpath, -w Path to working directory (default: cwd) --endpoint, -e GitHub API endpoint URL (default: https://api.github.com) --assets, -a Comma-delimited list of assets to upload --dry-run Preview release without creating it (default: false) --yes, -y Skip confirmation prompt (default: false) --help, -h Show help --version, -v Show version ``` -------------------------------- ### Releasearoni CLI Options Reference Source: https://context7.com/bcomnes/releasearoni/llms.txt A comprehensive list of command-line options available for both `releasearoni` and `releasearoni-gh` CLIs. These options control various aspects of release creation, including tagging, naming, asset uploads, draft/prerelease status, and GitHub Enterprise configuration. ```bash Options: --tag-name, -t Tag for this release --target-commitish, -c Commitish value for tag --name, -n Release title --body, -b Release body text --owner, -o Repo owner --repo, -r Repo name --draft, -d Publish as draft (default: false) --prerelease, -p Publish as prerelease (default: false) --workpath, -w Path to working directory (default: cwd) --endpoint, -e GitHub API endpoint URL (default: https://api.github.com) --assets, -a Comma-delimited list of assets to upload --dry-run Preview release without creating it (default: false) --yes, -y Skip confirmation prompt (default: false) --help, -h Show help --version, -v Show version ``` -------------------------------- ### Stage additional files in version script Source: https://github.com/bcomnes/releasearoni/blob/master/README.md Use the --add flag to include extra files like lock files when running the releasearoni version command. ```json "version": "releasearoni version --add package-lock.json" ``` -------------------------------- ### CLI - Subcommand Routing Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md The CLI entry point (`bin/releasearoni.js`) uses subcommand routing to handle different commands, prioritizing the 'version' subcommand. ```APIDOC ## CLI Entry Point - bin/releasearoni.js ### Description This script serves as the main entry point for the Releasearoni CLI. It implements subcommand routing, allowing for commands like `releasearoni version`. ### Method N/A (CLI Script) ### Endpoint `bin/releasearoni.js` ### Logic - Checks `process.argv[2]` for the subcommand. - If the subcommand is `version`, it imports and runs the `runVersion` function from `../lib/version-hook.js`. - If not `version`, it proceeds with the existing release flow. ### Code Example (Snippet) ```javascript // bin/releasearoni.js (top of file) if (process.argv[2] === 'version') { const { runVersion } = await import('../lib/version-hook.js') await runVersion(process.argv.slice(3)) process.exit(0) } // ... existing release flow continues below ``` ``` -------------------------------- ### POST /createRelease Source: https://github.com/bcomnes/releasearoni/blob/master/README.md Programmatically create a GitHub release by reading package metadata and changelog entries. ```APIDOC ## POST /createRelease ### Description Creates a new GitHub release using the provided options. It automatically parses `package.json` and `CHANGELOG.md` to populate release details if not explicitly provided. ### Method POST (Programmatic) ### Parameters #### Request Body - **auth** (object) - Required - { token: string } GitHub API token. - **workpath** (string) - Optional - Path to directory with package.json and CHANGELOG.md. Default: cwd. - **owner** (string) - Optional - Repo owner. Default: parsed from package.json. - **repo** (string) - Optional - Repo name. Default: parsed from package.json. - **tag_name** (string) - Optional - Tag to create. Default: v + package version. - **target_commitish** (string) - Optional - Branch or SHA for the tag. Default: current HEAD. - **name** (string) - Optional - Release title. Default: same as tag_name. - **body** (string) - Optional - Release body. Default: latest CHANGELOG entry. - **draft** (boolean) - Optional - Publish as draft. Default: false. - **prerelease** (boolean) - Optional - Mark as prerelease. Default: false. - **assets** (array) - Optional - Files to upload as release assets. ### Request Example { "auth": { "token": "ghp_exampletoken" }, "repo": "my-repo", "draft": false } ### Response #### Success Response (200) - **html_url** (string) - The URL of the created GitHub release. #### Response Example { "html_url": "https://github.com/owner/repo/releases/tag/v1.0.0" } ``` -------------------------------- ### Configure npm version lifecycle scripts Source: https://github.com/bcomnes/releasearoni/blob/master/README.md Integrate releasearoni into your package.json to automate changelog generation and release pushing during the npm versioning process. ```json { "scripts": { "version": "releasearoni version", "release": "git push --follow-tags && releasearoni -y" } } ``` -------------------------------- ### Implement Subcommand Routing in Releasearoni CLI Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md This JavaScript code snippet demonstrates how to implement subcommand routing for the `releasearoni` CLI tool. It checks for the 'version' subcommand before proceeding with the existing release flow, allowing for modular command handling. This approach keeps a single binary entry point. ```javascript if (process.argv[2] === 'version') { const { runVersion } = await import('../lib/version-hook.js') await runVersion(process.argv.slice(3)) process.exit(0) } // ... existing release flow continues below ``` -------------------------------- ### Programmatic Release Creation with Releasearoni API Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md This JavaScript code illustrates how to use the `releasearoni` programmatic API to create a GitHub release. It shows the required and optional parameters for the `createRelease` function, including authentication, repository details, tag information, and asset management. The function is asynchronous and returns the GitHub API release response object. ```javascript import { createRelease } from 'releasearoni' const result = await createRelease({ // Required auth: { token: 'ghp_...' }, // or process.env.GH_TOKEN / GITHUB_TOKEN owner: 'bcomnes', repo: 'my-project', tag_name: 'v1.2.3', target_commitish: 'abc123', name: 'v1.2.3', body: '## Changes\n...', // Optional draft: false, prerelease: false, endpoint: 'https://api.github.com', assets: [ '/path/to/file.tar.gz', { name: 'renamed.zip', path: '/path/to/original.zip' } ], }) // result: GitHub API release response object // asset upload progress via AsyncIterator or EventEmitter (TBD) ``` -------------------------------- ### Execute release workflow via CLI Source: https://context7.com/bcomnes/releasearoni/llms.txt Commands to trigger the versioning and release process using npm. These commands handle bumping the version, updating the changelog, and pushing tags to GitHub. ```bash # Bump version, generate changelog, commit, tag npm version patch # Push and create GitHub release npm run release ``` -------------------------------- ### Create GitHub Release with releasearoni CLI Source: https://context7.com/bcomnes/releasearoni/llms.txt Automates the creation of GitHub releases using the `releasearoni` CLI. It can read release details from `package.json` and `CHANGELOG.md`, supports interactive prompts or automatic confirmation, and allows overriding various release parameters like tag name, title, assets, and GitHub Enterprise endpoints. ```bash # Basic release (interactive confirmation) releasearoni # Skip confirmation prompt releasearoni -y # Preview release without creating it releasearoni --dry-run # Create a prerelease releasearoni --prerelease -y # Create a draft release releasearoni --draft -y # Override tag name and release title releasearoni --tag-name v2.0.0 --name "Version 2.0.0" -y # Upload assets with the release releasearoni --assets "dist/app.zip,dist/checksums.txt" -y # Custom working directory releasearoni --workpath /path/to/project -y # GitHub Enterprise releasearoni --endpoint https://github.example.com/api/v3 -y ``` -------------------------------- ### Interactive Confirmation with Node.js readline/promises Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md Provides an interactive prompt to the user for confirmation before proceeding with an action, using Node.js's `readline/promises` API. It asks a yes/no question and exits if the answer is not affirmative. ```javascript import { createInterface } from 'node:readline/promises' const rl = createInterface({ input: process.stdin, output: process.stdout }) const answer = await rl.question('Publish release to GitHub? [y/N] ') rl.close() if (!answer.toLowerCase().startsWith('y')) process.exit(0) ``` -------------------------------- ### Argument Parsing with Node.js util.parseArgs Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md Parses command-line arguments for the releasearoni tool using Node.js's built-in `parseArgs` function. It defines options, their types, short aliases, help text, and default values, leveraging `argsclopts` for formatting help text. ```javascript import { parseArgs } from 'node:util' import { formatHelpText } from 'argsclopts' import { join } from 'node:path' const pkgPath = join(import.meta.dirname, '../package.json') export const options = { 'tag-name': { type: 'string', short: 't', help: 'Tag for this release' }, 'target-commitish': { type: 'string', short: 'c', help: 'Commitish value for tag' }, name: { type: 'string', short: 'n', help: 'Release title' }, body: { type: 'string', short: 'b', help: 'Release body text' }, owner: { type: 'string', short: 'o', help: 'Repo owner' }, repo: { type: 'string', short: 'r', help: 'Repo name' }, draft: { type: 'boolean', short: 'd', help: 'Publish as draft', default: false }, prerelease: { type: 'boolean', short: 'p', help: 'Publish as prerelease', default: false }, workpath: { type: 'string', short: 'w', help: 'Working directory', default: process.cwd() }, endpoint: { type: 'string', short: 'e', help: 'GitHub API endpoint', default: 'https://api.github.com' }, assets: { type: 'string', short: 'a', help: 'Comma-delimited asset paths' }, 'dry-run': { type: 'boolean', help: 'Preview without creating', default: false }, yes: { type: 'boolean', short: 'y', help: 'Skip confirmation prompt', default: false }, help: { type: 'boolean', short: 'h', help: 'Show help' }, version: { type: 'boolean', short: 'v', help: 'Show version' }, } export const helpText = await formatHelpText({ options, pkgPath }) export const { values } = parseArgs({ options, allowPositionals: false }) ``` -------------------------------- ### Create GitHub release programmatically Source: https://github.com/bcomnes/releasearoni/blob/master/README.md Use the createRelease function to programmatically generate a GitHub release using the Octokit API. It automatically reads package metadata and changelog entries from the working directory. ```javascript import { createRelease } from 'releasearoni' const release = await createRelease({ auth: { token: process.env.GITHUB_TOKEN }, workpath: process.cwd(), // optional, defaults to cwd }) console.log(release.html_url) ``` -------------------------------- ### Run Version Hook with releasearoni Source: https://context7.com/bcomnes/releasearoni/llms.txt Runs the version lifecycle hook that generates the changelog and stages files. It accepts an array of command-line arguments for customization, such as specifying changelog file, files to add, template, breaking pattern, and working path. ```javascript import { runVersion } from 'releasearoni/lib/version-hook.js' // Basic usage await runVersion([]) // With options await runVersion([ '--changelog', 'HISTORY.md', '--add', 'package-lock.json', '--add', 'yarn.lock', '--template', 'keepachangelog', '--breaking-pattern', 'BREAKING:', '--workpath', '/path/to/project' ]) ``` -------------------------------- ### Create GitHub Release with releasearoni Source: https://context7.com/bcomnes/releasearoni/llms.txt The main programmatic entry point for creating GitHub releases. It reads defaults from package.json and CHANGELOG.md in the working directory and then calls the GitHub Releases API. Supports various options for customization and includes error handling. ```javascript import { createRelease } from 'releasearoni' // Basic usage with token from environment const release = await createRelease({ auth: { token: process.env.GITHUB_TOKEN }, workpath: process.cwd(), }) console.log(release.html_url) // => https://github.com/owner/repo/releases/tag/v1.0.0 // Full options example const release = await createRelease({ auth: { token: process.env.GITHUB_TOKEN }, workpath: '/path/to/project', owner: 'myorg', // Override: parsed from package.json repo: 'myrepo', // Override: parsed from package.json tag_name: 'v2.0.0', // Override: v + package.json version target_commitish: 'main', // Override: git rev-parse HEAD name: 'Release v2.0.0', // Override: same as tag_name body: '## What\'s New\n- Feature', // Override: latest CHANGELOG entry draft: false, prerelease: true, endpoint: 'https://api.github.com', assets: ['dist/bundle.zip', { name: 'app.exe', path: 'dist/app-win.exe' }], }) // Error handling try { const release = await createRelease({ auth: { token: process.env.GITHUB_TOKEN }, }) console.log(`Release created: ${release.html_url}`) } catch (error) { if (error.message.includes('auth.token is required')) { console.error('Missing GitHub token') } else if (error.message.includes('Unreleased changes detected')) { console.error('CHANGELOG.md has unreleased content') } else if (error.message.includes('out of sync')) { console.error('CHANGELOG.md version does not match package.json') } else { console.error('Release failed:', error.message) } } ``` -------------------------------- ### Uploading Assets with Node.js undici Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md Handles the upload of release assets to GitHub using the `undici` library for making HTTP requests. It reads file content, sets appropriate headers including authentication and content type, and sends the file data via a POST request to the specified upload URL. ```javascript import { createReadStream, statSync } from 'node:fs' import { basename } from 'node:path' import { request } from 'undici' async function uploadAsset(uploadUrl, token, asset) { const filePath = typeof asset === 'string' ? asset : asset.path const fileName = typeof asset === 'string' ? basename(asset) : asset.name const { size } = statSync(filePath) const url = uploadUrl.split('{')[0] + `?name=${encodeURIComponent(fileName)}` const { statusCode, body } = await request(url, { method: 'POST', headers: { 'Authorization': `token ${token}`, 'Content-Type': mimeType(fileName), 'Content-Length': String(size), }, body: createReadStream(filePath), }) if (statusCode >= 400) throw new Error(`Upload failed: HTTP ${statusCode}`) return body.json() } ``` -------------------------------- ### Programmatic API - createRelease Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md The `createRelease` function provides a programmatic interface to create GitHub releases. It accepts an options object with details about the release and assets to upload. ```APIDOC ## POST /api/releasearoni/createRelease ### Description Creates a GitHub release and uploads specified assets. This function is asynchronous and returns the GitHub API release response object. ### Method POST (Programmatic) ### Endpoint `import { createRelease } from 'releasearoni'` ### Parameters #### Request Body - **auth** (object) - Required - Authentication details, e.g., `{ token: 'ghp_...' }` or uses `process.env.GH_TOKEN` / `GITHUB_TOKEN`. - **owner** (string) - Required - The owner of the repository. - **repo** (string) - Required - The name of the repository. - **tag_name** (string) - Required - The name of the tag for the release. - **target_commitish** (string) - Required - The commitish value that determines where the Git tag is created from. - **name** (string) - Required - The name of the release. - **body** (string) - Required - The text of the release, typically in Markdown format. - **draft** (boolean) - Optional - Whether the release is a draft. - **prerelease** (boolean) - Optional - Whether the release is a prerelease. - **endpoint** (string) - Optional - The GitHub API endpoint URL. Defaults to `https://api.github.com`. - **assets** (array) - Optional - An array of assets to upload. Each asset can be a file path (string) or an object `{ name: '...', path: '...' }`. ### Request Example ```json { "auth": { "token": "ghp_..." }, "owner": "bcomnes", "repo": "my-project", "tag_name": "v1.2.3", "target_commitish": "abc123", "name": "v1.2.3", "body": "## Changes\n...", "assets": [ "/path/to/file.tar.gz", { "name": "renamed.zip", "path": "/path/to/original.zip" } ] } ``` ### Response #### Success Response (200) - **result** (object) - The GitHub API release response object. - **asset upload progress** (TBD) - Emitted via EventEmitter or callbacks. #### Response Example ```json { "url": "https://api.github.com/repos/bcomnes/my-project/releases/12345", "id": 12345, "tag_name": "v1.2.3", "name": "v1.2.3", "body": "## Changes\n..." // ... other release details } ``` ``` -------------------------------- ### Executing Git Commands with Node.js child_process.execSync Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md Executes synchronous shell commands using Node.js's `execSync` from the `child_process` module. This snippet specifically retrieves the current Git commit SHA. ```javascript import { execSync } from 'node:child_process' const sha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim() ``` -------------------------------- ### Upload Release Assets with releasearoni Source: https://context7.com/bcomnes/releasearoni/llms.txt Uploads release assets to a GitHub release with progress tracking. It takes the GitHub release upload URL, authentication token, and a list of assets to upload. A callback function can be provided for progress updates. ```javascript import { uploadAssets } from 'releasearoni/lib/upload-assets.js' // Upload assets with progress callback const results = await uploadAssets( release.upload_url, // GitHub release upload URL process.env.GITHUB_TOKEN, // Auth token [ 'dist/app.zip', // Simple path { name: 'windows-app.exe', path: 'dist/app.exe' } // Custom name ], (event, name, progress) => { if (event === 'upload-asset') { console.log(`Starting upload: ${name}`) } if (event === 'upload-progress') { console.log(`${name}: ${progress.percentage.toFixed(1)}%`) // progress = { percentage: 50.5, transferred: 1024, length: 2048 } } if (event === 'uploaded-asset') { console.log(`Completed: ${name}`) } } ) // results = array of GitHub asset response objects ``` -------------------------------- ### Releasearoni CLI Authentication Source: https://context7.com/bcomnes/releasearoni/llms.txt The releasearoni CLI supports multiple authentication methods for interacting with GitHub. It prioritizes environment variables (GH_TOKEN, GITHUB_TOKEN, GH_RELEASE_GITHUB_API_TOKEN) and falls back to interactive browser OAuth if no token is found. ```bash # Environment variables (checked in order) export GH_TOKEN=ghp_xxxxxxxxxxxx export GITHUB_TOKEN=ghp_xxxxxxxxxxxx export GH_RELEASE_GITHUB_API_TOKEN=ghp_xxxxxxxxxxxx # If no env var is set, ghauth will prompt for interactive browser OAuth releasearoni -y # => Opens browser for GitHub OAuth flow ``` -------------------------------- ### Manage Version and Changelog with releasearoni version Source: https://context7.com/bcomnes/releasearoni/llms.txt This command generates a `CHANGELOG.md` file using `auto-changelog` and stages it with git, designed to be used as an npm `version` lifecycle script. It allows customization of the changelog filename, additional files to stage, changelog templates, and breaking change patterns. ```bash # Basic usage (generates CHANGELOG.md and stages it) releasearoni version # Custom changelog filename releasearoni version --changelog HISTORY.md # Stage additional files releasearoni version --add package-lock.json # Custom auto-changelog template releasearoni version --template compact # Custom breaking change pattern releasearoni version --breaking-pattern "BREAKING:" # Show help releasearoni version --help ``` -------------------------------- ### Changelog format requirements Source: https://context7.com/bcomnes/releasearoni/llms.txt Releasearoni requires the Keep a Changelog format to correctly parse release notes. The body of the latest versioned entry is extracted and used as the GitHub release description. ```markdown # Changelog ## [Unreleased] ## [1.0.0] - 2024-01-15 ### Added - Initial release - Feature A implementation ### Fixed - Bug B resolution ## [0.9.0] - 2024-01-01 ### Added - Beta feature ``` -------------------------------- ### MIME Type Lookup with mime-types Source: https://github.com/bcomnes/releasearoni/blob/master/plans/releasearoni.md Determines the MIME type of a given filename using the `mime-types` library. If the lookup fails, it defaults to 'application/octet-stream'. This is crucial for setting the correct `Content-Type` header during asset uploads. ```javascript import { lookup } from 'mime-types' function mimeType(filename) { return lookup(filename) || 'application/octet-stream' } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.