fix(core): initial
This commit is contained in:
7
ts/index.ts
Normal file
7
ts/index.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import * as plugins from './legal.plugins';
|
||||
import { ICompany } from '@tsclass/tsclass';
|
||||
|
||||
export const createLicenseChecker = async () => {
|
||||
const licenseCheckerMod = await import('./mod.licensechecker/classes.licensechecker');
|
||||
return new licenseCheckerMod.LicenseChecker();
|
||||
};
|
13
ts/legal.plugins.ts
Normal file
13
ts/legal.plugins.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// sub packages
|
||||
import * as legalDocs from '@umbrellazone/legal-docs';
|
||||
export { legalDocs };
|
||||
|
||||
// @tsclass
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
export { tsclass };
|
||||
|
||||
// @pushrocks
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartmarkdown from '@pushrocks/smartmarkdown';
|
||||
import * as smartmustache from '@pushrocks/smartmustache';
|
||||
export { smartpromise, smartmarkdown, smartmustache };
|
87
ts/mod.licensechecker/classes.licensechecker.ts
Normal file
87
ts/mod.licensechecker/classes.licensechecker.ts
Normal file
@ -0,0 +1,87 @@
|
||||
import * as plugins from '../legal.plugins';
|
||||
import * as licenseChecker from 'license-checker';
|
||||
|
||||
export interface IModuleLicenseResult {
|
||||
moduleName: string;
|
||||
license: string;
|
||||
repository: string;
|
||||
publisher: string;
|
||||
email: string;
|
||||
path: string;
|
||||
licenseFile: string;
|
||||
}
|
||||
|
||||
export class CheckResult {
|
||||
passingModules: IModuleLicenseResult[] = [];
|
||||
failingModules: IModuleLicenseResult[] = [];
|
||||
addPassing(moduleResultArg: IModuleLicenseResult) {
|
||||
this.passingModules.push(moduleResultArg);
|
||||
}
|
||||
|
||||
addFailing(moduleResultArg: IModuleLicenseResult) {
|
||||
this.failingModules.push(moduleResultArg);
|
||||
}
|
||||
}
|
||||
|
||||
export class LicenseChecker {
|
||||
async excludeLicenseWithinPath(pathArg: string, licenseArrayArg: string[]) {
|
||||
const checkResult = new CheckResult();
|
||||
const plainResultArray = await this.createPlainResultArray(pathArg);
|
||||
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 plainResultArray = await this.createPlainResultArray(pathArg);
|
||||
plainResultArray.forEach(licenseResult => {
|
||||
if (licenseArrayArg.indexOf(licenseResult.license) !== -1) {
|
||||
checkResult.addPassing(licenseResult);
|
||||
} else {
|
||||
checkResult.addFailing(licenseResult);
|
||||
}
|
||||
});
|
||||
return checkResult;
|
||||
}
|
||||
|
||||
async createPlainResultArray(pathArg: string) {
|
||||
const licenseJson = await this.getJsonForPath(pathArg);
|
||||
const resultArray: IModuleLicenseResult[] = [];
|
||||
for (let moduleKey in licenseJson) {
|
||||
const refObject = licenseJson[moduleKey];
|
||||
resultArray.push({
|
||||
moduleName: moduleKey,
|
||||
email: refObject.email,
|
||||
licenseFile: refObject.licenseFile,
|
||||
license: refObject.licenses,
|
||||
path: refObject.path,
|
||||
publisher: refObject.publisher,
|
||||
repository: refObject.repository
|
||||
});
|
||||
}
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
private async getJsonForPath(checkPathArg) {
|
||||
let done = plugins.smartpromise.defer<any>();
|
||||
licenseChecker.init(
|
||||
{
|
||||
start: checkPathArg
|
||||
},
|
||||
function(err, licenseJson) {
|
||||
if (err) {
|
||||
done.reject(err);
|
||||
} else {
|
||||
done.resolve(licenseJson);
|
||||
}
|
||||
}
|
||||
);
|
||||
return await done.promise;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user