UNPKG

zync-nest-library

Version:

NestJS library with database backup and file upload utilities

160 lines (128 loc) • 4.48 kB
#!/usr/bin/env node const { execSync } = require("child_process"); const fs = require("fs"); const path = require("path"); /** * Script to update pnpm links when changes are made to zync-nest-library * This script will: * 1. Build the library * 2. Update the version in package.json * 3. Re-link to consuming projects */ // Configuration - projects that use this library const CONSUMING_PROJECTS = [ "/Users/sabiridwan/Projects/Async/zyncount/zyncount-be", "/Users/sabiridwan/Projects/MalikStream/ms-gold/msgld-be", ]; const LIBRARY_PATH = "/Users/sabiridwan/Projects/Async/zync-library/zync-nest-libary"; function execCommand(command, cwd = process.cwd()) { try { console.log(`\nšŸ”§ Executing: ${command}`); console.log(`šŸ“ In directory: ${cwd}`); const output = execSync(command, { cwd, stdio: "inherit", encoding: "utf8", }); return output; } catch (error) { console.error(`āŒ Error executing command: ${command}`); console.error(error.message); process.exit(1); } } function updateLibraryVersion(versionType = "patch") { console.log(`\nšŸ“¦ Updating library version (${versionType})...`); execCommand(`npm version ${versionType} --no-git-tag-version`, LIBRARY_PATH); // Get the new version const packageJson = JSON.parse( fs.readFileSync(path.join(LIBRARY_PATH, "package.json"), "utf8") ); console.log(`āœ… Updated to version: ${packageJson.version}`); return packageJson.version; } function buildLibrary() { console.log("\nšŸ—ļø Building library..."); execCommand("pnpm run build", LIBRARY_PATH); console.log("āœ… Library built successfully"); } function linkLibraryGlobally() { console.log("\nšŸ”— Linking library globally..."); execCommand("pnpm link --global", LIBRARY_PATH); console.log("āœ… Library linked globally"); } function updateConsumingProjects() { console.log("\nšŸ”„ Updating consuming projects..."); for (const projectPath of CONSUMING_PROJECTS) { if (!fs.existsSync(projectPath)) { console.log(`āš ļø Project not found: ${projectPath}`); continue; } console.log(`\nšŸ“‚ Updating project: ${path.basename(projectPath)}`); // Unlink first (in case it's already linked) try { execCommand("pnpm unlink zync-nest-library", projectPath); } catch (error) { // Ignore errors if not linked } // Link the new version execCommand("pnpm link zync-nest-library", projectPath); console.log(`āœ… Updated ${path.basename(projectPath)}`); } } function main() { console.log("šŸš€ Starting pnpm link update process..."); const args = process.argv.slice(2); const versionType = args[0] || "patch"; // patch, minor, major const skipVersionUpdate = args.includes("--skip-version"); const skipBuild = args.includes("--skip-build"); try { // Update version if not skipped if (!skipVersionUpdate) { updateLibraryVersion(versionType); } // Build library if not skipped if (!skipBuild) { buildLibrary(); } // Link library globally linkLibraryGlobally(); // Update consuming projects updateConsumingProjects(); console.log("\nšŸŽ‰ Pnpm link update completed successfully!"); // Show usage information console.log("\nšŸ“‹ Next steps:"); console.log("1. Test your changes in the consuming projects"); console.log("2. When ready, publish the library: npm publish"); console.log( "3. Update consuming projects to use published version: pnpm update zync-nest-library" ); } catch (error) { console.error("\nāŒ Update process failed:", error.message); process.exit(1); } } // Show help if (process.argv.includes("--help") || process.argv.includes("-h")) { console.log(` šŸ“– Pnpm Link Update Script Usage: node update-links.js [version-type] [options] Arguments: version-type Version bump type: patch (default), minor, major Options: --skip-version Skip version update --skip-build Skip build step --help, -h Show this help message Examples: node update-links.js # Patch version update with build node update-links.js minor # Minor version update with build node update-links.js --skip-build # Update links without building node update-links.js patch --skip-version --skip-build # Only update links Projects that will be updated: ${CONSUMING_PROJECTS.map((p) => ` - ${p}`).join("\n")} `); process.exit(0); } main();