smartlegal/ts/mod.licensechecker/classes.licensechecker.ts

34 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-10-11 23:21:12 +00:00
import * as plugins from './plugins.js';
import { CheckResult } from './classes.checkresult.js';
2020-01-17 16:34:40 +00:00
export class LicenseChecker {
2023-10-11 23:21:12 +00:00
2020-01-17 16:34:40 +00:00
async excludeLicenseWithinPath(pathArg: string, licenseArrayArg: string[]) {
const checkResult = new CheckResult();
2023-10-11 23:21:12 +00:00
const pnpm = new plugins.smartpnpm.SmartPnpm(pathArg);
const plainResultArray = await pnpm.getDependencyLicenseFlatArray();
2021-05-17 15:46:59 +00:00
plainResultArray.forEach((licenseResult) => {
2020-01-17 16:34:40 +00:00
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();
2023-10-11 23:21:12 +00:00
const pnpm = new plugins.smartpnpm.SmartPnpm(pathArg);
const plainResultArray = await pnpm.getDependencyLicenseFlatArray();
2021-05-17 15:46:59 +00:00
plainResultArray.forEach((licenseResult) => {
2020-01-17 16:34:40 +00:00
if (licenseArrayArg.indexOf(licenseResult.license) !== -1) {
checkResult.addPassing(licenseResult);
} else {
checkResult.addFailing(licenseResult);
}
});
return checkResult;
}
}