smartlegal/ts/mod.licensechecker/classes.licensechecker.ts
2023-10-12 01:21:12 +02:00

34 lines
1.2 KiB
TypeScript

import * as plugins from './plugins.js';
import { CheckResult } from './classes.checkresult.js';
export class LicenseChecker {
async excludeLicenseWithinPath(pathArg: string, licenseArrayArg: string[]) {
const checkResult = new CheckResult();
const pnpm = new plugins.smartpnpm.SmartPnpm(pathArg);
const plainResultArray = await pnpm.getDependencyLicenseFlatArray();
plainResultArray.forEach((licenseResult) => {
if (licenseArrayArg.indexOf(licenseResult.license) === -1) {
checkResult.addPassing(licenseResult);
} else {
checkResult.addFailing(licenseResult);
}
});
return checkResult;
}
async includeLicencesWithinPath(pathArg: string, licenseArrayArg: string[]) {
const checkResult = new CheckResult();
const pnpm = new plugins.smartpnpm.SmartPnpm(pathArg);
const plainResultArray = await pnpm.getDependencyLicenseFlatArray();
plainResultArray.forEach((licenseResult) => {
if (licenseArrayArg.indexOf(licenseResult.license) !== -1) {
checkResult.addPassing(licenseResult);
} else {
checkResult.addFailing(licenseResult);
}
});
return checkResult;
}
}