export async function doLicense()

in scripts/license.ts [53:98]


export async function doLicense(write: boolean): Promise<boolean> {
  let count = 0;

  const filesToChange: string[] = globSync(globPattern, {
    ignore: ["**/node_modules/**", "./node_modules/**", "**/dist/**"],
  });

  console.log(`Validating license headers in ${filesToChange.length} files.`);
  const files = await readFiles(filesToChange);

  await Promise.all(
    files.map(({ contents, path }) => {
      let result = contents;

      // Files with no license block at all.
      if (result.match(copyrightPattern) == null) {
        result =
          licenseHeader.replace("2023", String(new Date().getFullYear())) +
          result;
        console.log(`Adding license to ${path}.`);
      }

      // Files with no @license tag.
      if (result.match(/@license/) == null) {
        result = addLicenseTag(result);
        console.log(`Adding @license tag to ${path}.`);
      }

      if (contents !== result) {
        count++;
        if (write) {
          return fs.writeFileSync(path, result, "utf-8");
        }
      } else {
        return Promise.resolve();
      }
    }),
  );
  if (count === 0) {
    console.log(`No files needed license changes.`);
    return false;
  } else {
    console.log(`${count} files had license headers updated.`);
    return true;
  }
}