UNPKG

@coworker-agency/rag

Version:

Retrieval Augmented Generation (RAG) library for document indexing, vector storage, and AI-powered question answering

75 lines (59 loc) 2.51 kB
#!/usr/bin/env node import fs from 'fs'; import path from 'path'; import { execSync } from 'child_process'; import { fileURLToPath } from 'url'; // Get dirname equivalent in ESM const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Path to package files const packageJsonPath = path.resolve(__dirname, '../package.json'); const packageMinimalJsonPath = path.resolve(__dirname, '../package.minimal.json'); // Read both package files const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const packageMinimalJson = JSON.parse(fs.readFileSync(packageMinimalJsonPath, 'utf8')); // Parse and increment version function incrementVersion(version, type = 'patch') { const [major, minor, patch] = version.split('.').map(Number); switch (type.toLowerCase()) { case 'major': return `${major + 1}.0.0`; case 'minor': return `${major}.${minor + 1}.0`; case 'patch': default: return `${major}.${minor}.${patch + 1}`; } } // Get increment type from command line arguments const args = process.argv.slice(2); const incrementType = args[0] || 'patch'; // Default to patch // Current versions console.log(`Current versions:`); console.log(` - package.json: ${packageJson.version}`); console.log(` - package.minimal.json: ${packageMinimalJson.version}`); // Determine base version (use the higher one) const baseVersion = packageJson.version > packageMinimalJson.version ? packageJson.version : packageMinimalJson.version; // Increment version const newVersion = incrementVersion(baseVersion, incrementType); console.log(`\nIncrementing ${incrementType} version`); console.log(`New version: ${newVersion}`); // Update both files packageJson.version = newVersion; packageMinimalJson.version = newVersion; // Write updated files fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n'); fs.writeFileSync(packageMinimalJsonPath, JSON.stringify(packageMinimalJson, null, 2) + '\n'); console.log('\nVersion updated in both package files'); // If using git, offer to commit the changes try { const gitStatus = execSync('git status --porcelain package.json package.minimal.json').toString(); if (gitStatus.trim()) { console.log('\nDo you want to commit the version change?'); console.log('Run: git commit -m "chore: bump version to ' + newVersion + '" package.json package.minimal.json'); } } catch (error) { // Git not available or not a git repository, skip this part }