filetree-pro
Version:
A powerful file tree generator for VS Code and Cursor. Generate beautiful file trees in multiple formats with smart exclusions and custom configurations.
96 lines (79 loc) โข 3.13 kB
JavaScript
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
console.log('๐ Building FileTree Pro Extension (Optimized)...');
// Read package.json
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const vsixName = `${packageJson.name}-${packageJson.version}.vsix`;
try {
// Clean previous builds
if (fs.existsSync('temp_package')) {
execSync('rm -rf temp_package');
}
if (fs.existsSync(vsixName)) {
fs.unlinkSync(vsixName);
}
// Build with webpack (production mode)
console.log('๐ฆ Building with Webpack (Production)...');
execSync('npm run build', { stdio: 'inherit' });
// Create package structure
console.log('๐ Creating optimized package structure...');
execSync('mkdir -p temp_package/extension');
// Copy essential files
const filesToCopy = ['package.json', 'README.md', 'LICENSE'];
filesToCopy.forEach(file => {
if (fs.existsSync(file)) {
execSync(`cp ${file} temp_package/extension/`);
}
});
// Copy only production files (exclude tests)
const productionDirs = ['out', 'media'];
productionDirs.forEach(dir => {
if (fs.existsSync(dir)) {
execSync(`cp -r ${dir} temp_package/extension/`);
}
});
// Remove test files from the package
console.log('๐งน Cleaning test files from package...');
const testPatterns = [
'temp_package/extension/out/__tests__',
'temp_package/extension/out/**/*.test.js',
'temp_package/extension/out/**/*.spec.js',
'temp_package/extension/out/**/*.test.js.map',
'temp_package/extension/out/**/*.spec.js.map',
];
testPatterns.forEach(pattern => {
try {
execSync(`find temp_package/extension -path "${pattern}" -delete`, { stdio: 'ignore' });
} catch (e) {
// Ignore errors if files don't exist
}
});
// Create VSIX package
console.log('๐ฆ Creating optimized VSIX package...');
execSync(`cd temp_package && zip -r ../${vsixName} extension/`, { stdio: 'inherit' });
// Clean up
execSync('rm -rf temp_package');
console.log(`โ
Optimized extension packaged successfully: ${vsixName}`);
// Get file size
const stats = fs.statSync(vsixName);
const fileSizeInMB = (stats.size / (1024 * 1024)).toFixed(2);
console.log(`๐ฆ File size: ${fileSizeInMB} MB`);
// Show optimization benefits
console.log('\n๐ฏ Optimization Benefits:');
console.log(' โ
Test files excluded from production build');
console.log(' โ
Source maps removed in production');
console.log(' โ
Code minified and optimized');
console.log(' โ
Dead code eliminated');
console.log(' โ
Console logs removed');
console.log('\n๐ฏ To install locally:');
console.log(` code --install-extension ${vsixName}`);
console.log('\n๐ฏ To analyze bundle:');
console.log(' ANALYZE=true npm run build');
console.log('\n๐ฏ To test in development:');
console.log(' Press F5 in VS Code to open Extension Development Host');
} catch (error) {
console.error('โ Error packaging optimized extension:', error.message);
process.exit(1);
}