UNPKG

@primexop/pbk

Version:

Primexop Backend Kit - A powerful TypeScript utility for managing backend projects with features like B2F Portal integration, cross-project validation, and Next.js support

50 lines (49 loc) 2.21 kB
import fs from 'fs'; import path from 'path'; import { execSync } from 'child_process'; export async function addDevVersion(targetDir) { try { // Use current directory if no target directory provided const targetDirectory = targetDir || process.cwd(); const packageJsonPath = path.join(targetDirectory, 'package.json'); // Check if package.json exists if (!fs.existsSync(packageJsonPath)) { console.error(`No package.json found in ${targetDirectory}`); return; } console.log(`Updating package.json in ${targetDirectory}`); // Read the package.json file const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf-8'); const packageJson = JSON.parse(packageJsonContent); // Update or add the dependency const pbkPath = 'file:C:/primexopRepos/pbk'; const originalVersion = packageJson.dependencies?.['@primexop/pbk'] || packageJson.devDependencies?.['@primexop/pbk']; // Determine if it's in dependencies or devDependencies let dependencyType = 'dependencies'; if (!packageJson.dependencies?.['@primexop/pbk'] && packageJson.devDependencies?.['@primexop/pbk']) { dependencyType = 'devDependencies'; } // Create the section if it doesn't exist if (!packageJson[dependencyType]) { packageJson[dependencyType] = {}; } // Update the dependency packageJson[dependencyType]['@primexop/pbk'] = pbkPath; // Save the updated package.json fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); console.log(`Updated @primexop/pbk to use local version: ${pbkPath}`); if (originalVersion) { console.log(`Original version was: ${originalVersion}`); } // Run npm install console.log('Running npm install...'); execSync('npm install', { stdio: 'inherit', cwd: targetDirectory }); console.log('Successfully installed the local development version of @primexop/pbk'); } catch (error) { console.error('Error adding dev version:', error); } }