2024-06-21 17:48:43 +00:00
|
|
|
import * as plugins from './mod.plugins.js';
|
|
|
|
import * as paths from '../paths.js';
|
|
|
|
import { Project } from '../classes.project.js';
|
|
|
|
|
|
|
|
import { logger } from '../gitzone.logging.js';
|
|
|
|
|
2024-06-23 20:57:09 +00:00
|
|
|
const incompatibleLicenses: string[] = ['AGPL', 'GPL', 'SSPL'];
|
2024-06-21 17:48:43 +00:00
|
|
|
|
|
|
|
export const run = async (projectArg: Project) => {
|
2024-06-23 20:57:09 +00:00
|
|
|
const nodeModulesInstalled = await plugins.smartfile.fs.isDirectory(
|
|
|
|
plugins.path.join(paths.cwd, 'node_modules'),
|
|
|
|
);
|
2024-06-23 11:26:51 +00:00
|
|
|
if (!nodeModulesInstalled) {
|
|
|
|
logger.log('warn', 'No node_modules found. Skipping license check');
|
|
|
|
return;
|
|
|
|
}
|
2024-06-21 17:48:43 +00:00
|
|
|
const licenseChecker = await plugins.smartlegal.createLicenseChecker();
|
2024-06-23 20:57:09 +00:00
|
|
|
const licenseCheckResult = await licenseChecker.excludeLicenseWithinPath(
|
|
|
|
paths.cwd,
|
|
|
|
incompatibleLicenses,
|
|
|
|
);
|
2024-06-21 17:48:43 +00:00
|
|
|
if (licenseCheckResult.failingModules.length === 0) {
|
|
|
|
logger.log('info', 'Success -> licenses passed!');
|
|
|
|
} else {
|
|
|
|
logger.log('error', 'Error -> licenses failed. Here is why:');
|
|
|
|
for (const failedModule of licenseCheckResult.failingModules) {
|
|
|
|
console.log(`${failedModule.name} fails with license ${failedModule.license}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|