Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

chore: migrate scripts to node (#5918)

authored by yoginth.com and committed by

GitHub 32fc9ca4 f0d26177

+87 -51
+9
README.md
··· 121 121 pnpm biome:fix 122 122 ``` 123 123 124 + ### Maintenance Scripts 125 + 126 + Convenient Node.js helpers reside in the `script` directory: 127 + 128 + - `node script/clean.mjs` removes all `node_modules`, `.next` directories, 129 + `pnpm-lock.yaml`, and `tsconfig.tsbuildinfo` files. 130 + - `node script/update-dependencies.mjs` updates packages across the monorepo, 131 + cleans old installs, and commits the changes in a new branch. 132 + 124 133 ## License 125 134 126 135 This project is licensed under the **AGPL-3.0** license. Please refer to the [LICENSE](./LICENSE) file for full terms and conditions.
-11
script/clean
··· 1 - #!/bin/bash 2 - 3 - # Usage: script/clean 4 - # Clean all node_modules and pnpm-lock.yaml files recursively. 5 - 6 - echo "Deleting all node_modules and pnpm-lock.yaml files recursively 🗑" 7 - find . -name "node_modules" -type d -prune -exec rm -rf '{}' + -print 8 - find . -name ".next" -type d -prune -exec rm -rf '{}' + -print 9 - find . -name "pnpm-lock.yaml" -type f -prune -exec rm -rf '{}' + -print 10 - find . -name "tsconfig.tsbuildinfo" -type f -prune -exec rm -rf '{}' + -print 11 - echo "node_modules and pnpm-lock.yaml files deleted 🎉"
+32
script/clean.mjs
··· 1 + #!/usr/bin/env node 2 + import { readdir, rm } from "node:fs/promises"; 3 + import { join } from "node:path"; 4 + 5 + async function removeTargets(directory) { 6 + const entries = await readdir(directory, { withFileTypes: true }); 7 + await Promise.all( 8 + entries.map(async (entry) => { 9 + const fullPath = join(directory, entry.name); 10 + if (entry.isDirectory()) { 11 + if (entry.name === "node_modules" || entry.name === ".next") { 12 + await rm(fullPath, { force: true, recursive: true }); 13 + console.log(`Deleted ${fullPath}`); 14 + } else { 15 + await removeTargets(fullPath); 16 + } 17 + } else if ( 18 + entry.name === "pnpm-lock.yaml" || 19 + entry.name === "tsconfig.tsbuildinfo" 20 + ) { 21 + await rm(fullPath, { force: true }); 22 + console.log(`Deleted ${fullPath}`); 23 + } 24 + }) 25 + ); 26 + } 27 + 28 + console.log( 29 + "Deleting all node_modules and pnpm-lock.yaml files recursively \ud83d\uddd1" 30 + ); 31 + await removeTargets(process.cwd()); 32 + console.log("node_modules and pnpm-lock.yaml files deleted \ud83c\udf89");
-40
script/update-dependencies
··· 1 - #!/bin/bash 2 - 3 - # Usage: script/update-dependencies 4 - # Update dependencies across all packages 5 - 6 - branch_name="update-dependencies-$(date +%Y-%m-%d-%H-%M)" 7 - commit_message="chore: Update dependencies across all packages" 8 - 9 - # Check for uncommitted changes 10 - if [[ $(git status --porcelain) ]]; then 11 - echo "Uncommitted changes detected. Please commit or stash them before running this script." 12 - exit 1 13 - fi 14 - 15 - # Create a new branch 16 - git checkout -b "$branch_name" 17 - 18 - # Update dependencies 19 - pnpm update --interactive --recursive --latest 20 - 21 - # Check for changes 22 - if [[ ! $(git status --porcelain) ]]; then 23 - echo "No changes in dependencies. Exiting." 24 - exit 0 25 - fi 26 - 27 - # Call the clean script 28 - ./script/clean 29 - 30 - # Install dependencies again 31 - pnpm install 32 - 33 - # Commit changes 34 - git add . 35 - git commit -m "$commit_message" 36 - 37 - # Push the branch 38 - git push -u origin "$branch_name" 39 - 40 - echo "Dependencies updated and pushed to branch $branch_name."
+46
script/update-dependencies.mjs
··· 1 + #!/usr/bin/env node 2 + import { execSync } from "node:child_process"; 3 + import { format } from "node:util"; 4 + 5 + function exec(cmd) { 6 + execSync(cmd, { stdio: "inherit" }); 7 + } 8 + 9 + function hasChanges() { 10 + const output = execSync("git status --porcelain").toString().trim(); 11 + return output.length > 0; 12 + } 13 + 14 + if (hasChanges()) { 15 + console.error( 16 + "Uncommitted changes detected. Please commit or stash them before running this script." 17 + ); 18 + process.exit(1); 19 + } 20 + 21 + const now = new Date(); 22 + const pad = (n) => String(n).padStart(2, "0"); 23 + const branchName = format( 24 + "update-dependencies-%d-%s-%s-%s-%s", 25 + now.getFullYear(), 26 + pad(now.getMonth() + 1), 27 + pad(now.getDate()), 28 + pad(now.getHours()), 29 + pad(now.getMinutes()) 30 + ); 31 + const commitMessage = "chore: Update dependencies across all packages"; 32 + 33 + exec(`git checkout -b ${branchName}`); 34 + exec("pnpm update --interactive --recursive --latest"); 35 + 36 + if (!hasChanges()) { 37 + console.log("No changes in dependencies. Exiting."); 38 + process.exit(0); 39 + } 40 + 41 + exec("node ./script/clean.mjs"); 42 + exec("pnpm install"); 43 + exec("git add ."); 44 + exec(`git commit -m "${commitMessage}"`); 45 + exec(`git push -u origin ${branchName}`); 46 + console.log(`Dependencies updated and pushed to branch ${branchName}.`);