UNPKG

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
#!/usr/bin/env node 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); }