Update hooks and ignore markdown files in size check
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 3m16s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 3m16s
This commit is contained in:
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
|
||||
|
||||
if echo "$changed_files" | grep --quiet -E "package.json|package-lock.json"; then
|
||||
echo "📦 Dependencies changed. Syncing..."
|
||||
|
||||
# --no-progress stops the terminal spam
|
||||
# --loglevel error ensures we only see the bad stuff
|
||||
if npm install --no-progress --loglevel error; then
|
||||
echo "✅ Node modules are up to date."
|
||||
else
|
||||
echo "❌ npm install failed! Please check your connection or package.json."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "🔍 Running pre-commit checks..."
|
||||
|
||||
# Get staged files (added, copied, modified)
|
||||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
|
||||
|
||||
if [ -n "$STAGED_FILES" ]; then
|
||||
echo "📏 Checking file sizes..."
|
||||
node .husky/scripts/check-file-size.js $STAGED_FILES
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Generate project structure
|
||||
echo "🗺️ Updating project structure..."
|
||||
node .husky/scripts/generate-project-tree.js
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Auto-add the generated project structure to the commit
|
||||
git add docs/project-structure.txt
|
||||
|
||||
echo "✅ All pre-commit checks passed!"
|
||||
@@ -0,0 +1,61 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const MAX_LINES = 400;
|
||||
|
||||
// List of file patterns to ignore (optional, can be customized)
|
||||
const IGNORE_PATTERNS = [
|
||||
/\.lock$/, // Lock files
|
||||
/\.min\.js$/, // Minified files
|
||||
/\.map$/, // Source maps
|
||||
/package-lock\.json$/,
|
||||
/bun\.lock$/,
|
||||
/tsconfig\.tsbuildinfo$/,
|
||||
/\.md$/, // Markdown documentation files
|
||||
/context\.md$/, // Context files for sub-agents
|
||||
/project-structure\.txt$/, // Generated project structure
|
||||
];
|
||||
|
||||
function shouldIgnore(filePath) {
|
||||
return IGNORE_PATTERNS.some(pattern => pattern.test(filePath));
|
||||
}
|
||||
|
||||
const files = process.argv.slice(2);
|
||||
if (files.length === 0) {
|
||||
console.log('ℹ️ No files to check');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
let hasError = false;
|
||||
|
||||
files.forEach(file => {
|
||||
// Skip ignored patterns
|
||||
if (shouldIgnore(file)) {
|
||||
console.log(`⏭️ Skipping ${file} (ignored pattern)`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if file exists (it might have been deleted)
|
||||
if (!fs.existsSync(file)) {
|
||||
console.log(`⏭️ Skipping ${file} (file does not exist)`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const content = fs.readFileSync(file, 'utf8');
|
||||
const lines = content.split('\n').length;
|
||||
|
||||
if (lines > MAX_LINES) {
|
||||
console.error(`❌ ${file} is too large (${lines} lines, max ${MAX_LINES}). AI agents will struggle. Please refactor!`);
|
||||
hasError = true;
|
||||
} else {
|
||||
console.log(`✅ ${file} (${lines} lines) - OK`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`⚠️ Error reading ${file}: ${err.message}`);
|
||||
// Don't fail on read errors, just warn
|
||||
}
|
||||
});
|
||||
|
||||
if (hasError) {
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
// Directory to start from (project root)
|
||||
const ROOT_DIR = process.cwd();
|
||||
// Output file path
|
||||
const OUTPUT_FILE = path.join(ROOT_DIR, 'docs', 'project-structure.txt');
|
||||
|
||||
// Function to check if a path is ignored by git
|
||||
function isGitIgnored(filePath) {
|
||||
try {
|
||||
// git check-ignore -q returns 0 if ignored, 1 if not
|
||||
execSync(`git check-ignore -q "${filePath}"`, {
|
||||
cwd: ROOT_DIR,
|
||||
stdio: 'ignore'
|
||||
});
|
||||
return true; // Ignored
|
||||
} catch (e) {
|
||||
return false; // Not ignored
|
||||
}
|
||||
}
|
||||
|
||||
// Function to generate tree structure
|
||||
function generateTree(dir, prefix = '', isRoot = true) {
|
||||
let structure = '';
|
||||
|
||||
// Add root directory name if it's the root
|
||||
if (isRoot) {
|
||||
structure += `${path.basename(dir)}/\n`;
|
||||
}
|
||||
|
||||
let items;
|
||||
try {
|
||||
items = fs.readdirSync(dir);
|
||||
} catch (e) {
|
||||
console.error(`Error reading directory ${dir}: ${e.message}`);
|
||||
return structure;
|
||||
}
|
||||
|
||||
// Sort items: directories first, then files
|
||||
const dirs = [];
|
||||
const files = [];
|
||||
|
||||
items.forEach(item => {
|
||||
const itemPath = path.join(dir, item);
|
||||
|
||||
// Skip if ignored by git
|
||||
if (isGitIgnored(itemPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const stat = fs.statSync(itemPath);
|
||||
if (stat.isDirectory()) {
|
||||
dirs.push(item);
|
||||
} else {
|
||||
files.push(item);
|
||||
}
|
||||
} catch (e) {
|
||||
// Skip items we can't stat
|
||||
}
|
||||
});
|
||||
|
||||
// Sort directories and files alphabetically
|
||||
dirs.sort();
|
||||
files.sort();
|
||||
|
||||
const allItems = [...dirs, ...files];
|
||||
|
||||
allItems.forEach((item, index) => {
|
||||
const isLast = index === allItems.length - 1;
|
||||
const connector = isLast ? '└── ' : '├── ';
|
||||
const itemPath = path.join(dir, item);
|
||||
|
||||
structure += `${prefix}${connector}${item}${dirs.includes(item) ? '/' : ''}\n`;
|
||||
|
||||
// Recurse into directories
|
||||
if (dirs.includes(item)) {
|
||||
const newPrefix = prefix + (isLast ? ' ' : '│ ');
|
||||
structure += generateTree(itemPath, newPrefix, false);
|
||||
}
|
||||
});
|
||||
|
||||
return structure;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('🗺️ Generating project structure...');
|
||||
|
||||
// Ensure docs directory exists
|
||||
const docsDir = path.join(ROOT_DIR, 'docs');
|
||||
if (!fs.existsSync(docsDir)) {
|
||||
fs.mkdirSync(docsDir, { recursive: true });
|
||||
console.log('📁 Created docs directory');
|
||||
}
|
||||
|
||||
// Generate tree
|
||||
const tree = generateTree(ROOT_DIR, '', true);
|
||||
|
||||
// Write to file
|
||||
fs.writeFileSync(OUTPUT_FILE, tree);
|
||||
console.log(`✅ Project structure updated: ${OUTPUT_FILE}`);
|
||||
|
||||
} catch (err) {
|
||||
console.error(`❌ Error generating project structure: ${err.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user