UNPKG

@solidstate/hardhat-license-identifier

Version:
18 lines (17 loc) 929 B
import { hasMatchingLicense, prependLicenseToFileContent, readLicenseFromPackageJson, } from '../lib/license_identifier.js'; import { writeUtf8File } from '@nomicfoundation/hardhat-utils/fs'; export default async () => ({ preprocessProjectFileBeforeBuilding: async (context, sourceName, fsPath, fileContent, solcVersion, next) => { const config = context.config.licenseIdentifier; if (config.runOnCompile) { const license = config.license ?? (await readLicenseFromPackageJson(context.config.paths.root)); const overwrite = config.overwrite; if (!hasMatchingLicense(fileContent, license, overwrite)) { fileContent = prependLicenseToFileContent(fileContent, license); await writeUtf8File(fsPath, fileContent); } } return await next(context, sourceName, fsPath, fileContent, solcVersion); }, });