feat(format): add check and fix workflows
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { BaseFormatter } from '../classes.baseformatter.js';
|
||||
import type { IPlannedChange } from '../interfaces.format.js';
|
||||
import type { IFormatWarning, IPlannedChange } from '../interfaces.format.js';
|
||||
import * as plugins from '../mod.plugins.js';
|
||||
import * as paths from '../../paths.js';
|
||||
import { logger } from '../../gitzone.logging.js';
|
||||
@@ -11,6 +11,10 @@ export class LicenseFormatter extends BaseFormatter {
|
||||
return 'license';
|
||||
}
|
||||
|
||||
get runsWithoutChanges(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
async analyze(): Promise<IPlannedChange[]> {
|
||||
// License formatter only checks for incompatible licenses
|
||||
// It does not modify any files, so return empty array
|
||||
@@ -18,29 +22,34 @@ export class LicenseFormatter extends BaseFormatter {
|
||||
return [];
|
||||
}
|
||||
|
||||
async validate(): Promise<IFormatWarning[]> {
|
||||
const result = await this.checkLicenses();
|
||||
if (!result || result.failingModules.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
level: 'error',
|
||||
module: this.name,
|
||||
message: `License check failed for ${result.failingModules.length} module(s): ${result.failingModules
|
||||
.map((failedModule) => `${failedModule.name} (${failedModule.license})`)
|
||||
.join(', ')}`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
async execute(changes: IPlannedChange[]): Promise<void> {
|
||||
const startTime = this.stats.moduleStartTime(this.name);
|
||||
this.stats.startModule(this.name);
|
||||
|
||||
try {
|
||||
// Check if node_modules exists
|
||||
const nodeModulesPath = plugins.path.join(paths.cwd, 'node_modules');
|
||||
const nodeModulesExists = await plugins.smartfs
|
||||
.directory(nodeModulesPath)
|
||||
.exists();
|
||||
|
||||
if (!nodeModulesExists) {
|
||||
const licenseCheckResult = await this.checkLicenses();
|
||||
if (!licenseCheckResult) {
|
||||
logger.log('warn', 'No node_modules found. Skipping license check');
|
||||
return;
|
||||
}
|
||||
|
||||
// Run license check
|
||||
const licenseChecker = await plugins.smartlegal.createLicenseChecker();
|
||||
const licenseCheckResult = await licenseChecker.excludeLicenseWithinPath(
|
||||
paths.cwd,
|
||||
INCOMPATIBLE_LICENSES,
|
||||
);
|
||||
|
||||
if (licenseCheckResult.failingModules.length === 0) {
|
||||
logger.log('info', 'License check passed - no incompatible licenses found');
|
||||
} else {
|
||||
@@ -59,4 +68,23 @@ export class LicenseFormatter extends BaseFormatter {
|
||||
async applyChange(change: IPlannedChange): Promise<void> {
|
||||
// No file changes for license formatter
|
||||
}
|
||||
|
||||
private async checkLicenses(): Promise<{
|
||||
failingModules: Array<{ name: string; license: string }>;
|
||||
} | undefined> {
|
||||
const nodeModulesPath = plugins.path.join(paths.cwd, 'node_modules');
|
||||
const nodeModulesExists = await plugins.smartfs
|
||||
.directory(nodeModulesPath)
|
||||
.exists();
|
||||
|
||||
if (!nodeModulesExists) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const licenseChecker = await plugins.smartlegal.createLicenseChecker();
|
||||
return await licenseChecker.excludeLicenseWithinPath(
|
||||
paths.cwd,
|
||||
INCOMPATIBLE_LICENSES,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user