Advanced Features
Advanced Features
Section titled “Advanced Features”Discover advanced capabilities of the pjt tool to optimize your workflow.
Batch operations
Section titled “Batch operations”Multiple repositories
Section titled “Multiple repositories”# Process multiple reposfind . -name ".git" -type d -execdir pjt \;
# With parallelismfind . -name ".git" -type d -print0 | xargs -0 -P 4 -I {} sh -c 'cd "{}" && pjt'Selective cleaning
Section titled “Selective cleaning”# Only node_modulesfind . -name "node_modules" -type d -exec rm -rf {} +
# Only empty directoriesfind . -type d -empty -deleteConfiguration
Section titled “Configuration”Environment variables
Section titled “Environment variables”# Verbose modePJT_VERBOSE=1 pjt
# Custom timeoutPJT_TIMEOUT=60000 pjt
# Dry runPJT_DRY_RUN=1 pjtConfig file
Section titled “Config file”module.exports = { verbose: true, timeout: 30000, exclude: ['node_modules/**', '.git/**'], include: ['src/**', 'tests/**']};Integrations
Section titled “Integrations”With CI/CD
Section titled “With CI/CD”GitHub Actions
Section titled “GitHub Actions”name: Clean Repositoryon: [push, pull_request]
jobs: clean: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' - name: Install pjt run: npm install -g pjt - name: Clean repository run: pjtGitLab CI
Section titled “GitLab CI”stages: - clean
clean_job: stage: clean script: - npm install -g pjt - pjt only: - merge_requestsWith Git hooks
Section titled “With Git hooks”Pre-commit
Section titled “Pre-commit”#!/bin/sh# Run pjt pre commitpjt --clean-only
# Check if there are changesif [ -n "$(git status --porcelain)" ]; then echo "Repository not clean, staging changes..." git add .fiPre-push
Section titled “Pre-push”#!/bin/sh# Run full cleaning pre pushpjt
# Check testsnpm testScripting
Section titled “Scripting”Node.js script
Section titled “Node.js script”const { execSync } = require('child_process');const { readdirSync, statSync } = require('fs');const path = require('path');
function cleanRepos(dir) { const items = readdirSync(dir);
for (const item of items) { const fullPath = path.join(dir, item); const stat = statSync(fullPath);
if (stat.isDirectory() && item === '.git') { console.log(`Cleaning ${dir}`); execSync('pjt', { cwd: path.dirname(fullPath), stdio: 'inherit' }); } else if (stat.isDirectory()) { cleanRepos(fullPath); } }}
cleanRepos(process.cwd());Bash script
Section titled “Bash script”#!/bin/bashfind . -type d -name ".git" | while read gitdir; do repo_dir=$(dirname "$gitdir") echo "Cleaning $repo_dir" cd "$repo_dir" pjt cd - > /dev/nulldonePerformance tuning
Section titled “Performance tuning”Large projects
Section titled “Large projects”# Increase timeout for large projectsPJT_TIMEOUT=120000 pjt
# Disable verbose for faster executionpjt --quietMemory optimization
Section titled “Memory optimization”# Limit heap sizeNODE_OPTIONS="--max-old-space-size=4096" pjtDebugging
Section titled “Debugging”Debug mode
Section titled “Debug mode”# Enable debug loggingDEBUG=pjt:* pjt
# With verboseDEBUG=pjt:* PJT_VERBOSE=1 pjtLog files
Section titled “Log files”# Save log to filepjt 2>&1 | tee pjt.log
# Filter errorspjt 2>&1 | grep -i errorCustom plugins
Section titled “Custom plugins”Plugin structure
Section titled “Plugin structure”module.exports = { name: 'my-plugin', version: '1.0.0',
hooks: { preClean: async (context) => { console.log('Pre-clean hook'); },
postClean: async (context) => { console.log('Post-clean hook'); } },
commands: { 'my-command': { description: 'My custom command', action: async () => { console.log('Custom command executed'); } } }};Using plugins
Section titled “Using plugins”# Install pluginnpm install my-pjt-plugin
# Use pluginpjt my-commandTroubleshooting advanced scenarios
Section titled “Troubleshooting advanced scenarios”Network timeouts
Section titled “Network timeouts”# Increase network timeoutPJT_NETWORK_TIMEOUT=60000 pjtPermission issues
Section titled “Permission issues”# With sudo (carefully!)sudo pjt
# Or fix permissionschmod -R u+w node_modules/Corrupted node_modules
Section titled “Corrupted node_modules”# Nuclear optionrm -rf node_modules package-lock.jsonnpm installBest practices
Section titled “Best practices”1. Backup
Section titled “1. Backup”Always make a backup before mass operations.
2. Testing
Section titled “2. Testing”Test on staging environment.
3. Monitoring
Section titled “3. Monitoring”Monitor performance and resources.
4. Documentation
Section titled “4. Documentation”Document custom configurations.
Community resources
Section titled “Community resources”- GitHub Issues - Report problems
- Discussions - Ask questions
- Contributing Guide - Contribute