import * as plugins from './smartpnpm.plugins.js'; export class SmartPnpm { public projectDir: string; constructor(projectDirArg: string) { this.projectDir = projectDirArg; } private smartshellInstance = new plugins.smartshell.Smartshell({ executor: 'bash', }) async getDependencyLicenseJson() { try { // Get store directory const execResult = await this.smartshellInstance.execSilent('pnpm licenses list --json'); const licenseJson: {[key: string]: Array<{ "name": string; "version": string; "path": string; "license": string; "author": string; "homepage": string; "description": string; }>} = JSON.parse(execResult.stdout); return licenseJson; } catch (error) { console.error('Error:', error); } } public async printDependencyLicenseSummary() { const result = await this.getDependencyLicenseJson(); for (const licenseType of Object.keys(result)) { const refArray = result[licenseType]; console.log(`${licenseType}: ${refArray.length} packages.`); if (licenseType !== 'MIT' && licenseType !== 'ISC') { for (const ref of refArray) { console.log(`|-- ${ref.name} (${ref.version})`); } } else { console.log(`|-- ${refArray.length} packages. Not detailing this license type.`); } }; } public async getDependencyLicenseFlatArray() { const result = await this.getDependencyLicenseJson(); const licenseArray: Array<{ "name": string; "version": string; "path": string; "license": string; "author": string; "homepage": string; "description": string; }> = []; for (const licenseType of Object.keys(result)) { const refArray = result[licenseType]; for (const ref of refArray) { licenseArray.push(ref); } } return licenseArray; } public async getDependencyLicenseArray() { const result = await this.getDependencyLicenseJson(); return Object.keys(result); } }