API Reference
Complete API documentation for BetterPack's programmatic interface.
Core API
detectPackageManager()
const { detectPackageManager } = require('betterpack');
const pm = detectPackageManager();
console.log(pm); // 'npm', 'yarn', 'pnpm', or 'bun'
Detects the package manager based on lock files in the current directory.
executeCommand(command, args)
const { executeCommand } = require('betterpack');
await executeCommand('install', []);
await executeCommand('add', ['express', '--save-dev']);
Executes a universal command using the detected package manager.
Agent API
ProjectAnalyzer
const { ProjectAnalyzer } = require('betterpack/agent');
const analyzer = new ProjectAnalyzer();
const analysis = await analyzer.analyzeProject('./my-project');
console.log(analysis.health); // Health score 0-100
console.log(analysis.issues); // Array of detected issues
console.log(analysis.recommendations); // Suggested actions
SmartAgent
const { SmartAgent } = require('betterpack/agent');
const agent = new SmartAgent({
mode: 'conservative', // 'conservative', 'balanced', 'aggressive'
aiProvider: 'google',
apiKey: process.env.GOOGLE_API_KEY // Free tier available
});
await agent.start('./my-project');
Bundler API
ProjectBundler
const { ProjectBundler } = require('betterpack/bundler');
const bundler = new ProjectBundler();
// Bundle as single JS file
await bundler.bundle({
format: 'js',
output: 'dist/bundle.js',
minify: true
});
// Create executable
await bundler.bundle({
format: 'exe',
output: 'dist/myapp.exe',
platform: 'win32'
});