Skip to content

Advanced Features

Discover advanced capabilities of the pjt tool to optimize your workflow.

Terminal window
# Process multiple repos
find . -name ".git" -type d -execdir pjt \;
# With parallelism
find . -name ".git" -type d -print0 | xargs -0 -P 4 -I {} sh -c 'cd "{}" && pjt'
Terminal window
# Only node_modules
find . -name "node_modules" -type d -exec rm -rf {} +
# Only empty directories
find . -type d -empty -delete
Terminal window
# Verbose mode
PJT_VERBOSE=1 pjt
# Custom timeout
PJT_TIMEOUT=60000 pjt
# Dry run
PJT_DRY_RUN=1 pjt
.pjtrc.js
module.exports = {
verbose: true,
timeout: 30000,
exclude: ['node_modules/**', '.git/**'],
include: ['src/**', 'tests/**']
};
name: Clean Repository
on: [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: pjt
stages:
- clean
clean_job:
stage: clean
script:
- npm install -g pjt
- pjt
only:
- merge_requests
.husky/pre-commit
#!/bin/sh
# Run pjt pre commit
pjt --clean-only
# Check if there are changes
if [ -n "$(git status --porcelain)" ]; then
echo "Repository not clean, staging changes..."
git add .
fi
.husky/pre-push
#!/bin/sh
# Run full cleaning pre push
pjt
# Check tests
npm test
clean-repos.js
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());
clean-all-repos.sh
#!/bin/bash
find . -type d -name ".git" | while read gitdir; do
repo_dir=$(dirname "$gitdir")
echo "Cleaning $repo_dir"
cd "$repo_dir"
pjt
cd - > /dev/null
done
Terminal window
# Increase timeout for large projects
PJT_TIMEOUT=120000 pjt
# Disable verbose for faster execution
pjt --quiet
Terminal window
# Limit heap size
NODE_OPTIONS="--max-old-space-size=4096" pjt
Terminal window
# Enable debug logging
DEBUG=pjt:* pjt
# With verbose
DEBUG=pjt:* PJT_VERBOSE=1 pjt
Terminal window
# Save log to file
pjt 2>&1 | tee pjt.log
# Filter errors
pjt 2>&1 | grep -i error
my-pjt-plugin.js
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');
}
}
}
};
Terminal window
# Install plugin
npm install my-pjt-plugin
# Use plugin
pjt my-command
Terminal window
# Increase network timeout
PJT_NETWORK_TIMEOUT=60000 pjt
Terminal window
# With sudo (carefully!)
sudo pjt
# Or fix permissions
chmod -R u+w node_modules/
Terminal window
# Nuclear option
rm -rf node_modules package-lock.json
npm install

Always make a backup before mass operations.

Test on staging environment.

Monitor performance and resources.

Document custom configurations.