| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import {glob} from 'fast-glob'; |
| 9 | import * as fs from 'fs/promises'; |
| 10 | import ora from 'ora'; |
| 11 | import yargs from 'yargs/yargs'; |
| 12 | import libraryCompatCheck from './checks/libraryCompat'; |
| 13 | import reactCompilerCheck from './checks/reactCompiler'; |
| 14 | import strictModeCheck from './checks/strictMode'; |
| 15 | |
| 16 | async function main() { |
| 17 | const argv = yargs(process.argv.slice(2)) |
| 18 | .scriptName('healthcheck') |
| 19 | .usage('$ npx healthcheck <src>') |
| 20 | .option('src', { |
| 21 | description: 'glob expression matching src files to compile', |
| 22 | type: 'string', |
| 23 | default: '**/+(*.{js,mjs,jsx,ts,tsx}|package.json)', |
| 24 | }) |
| 25 | .parseSync(); |
| 26 | |
| 27 | const spinner = ora('Checking').start(); |
| 28 | let src = argv.src; |
| 29 | |
| 30 | const globOptions = { |
| 31 | onlyFiles: true, |
| 32 | ignore: [ |
| 33 | '**/node_modules/**', |
| 34 | '**/dist/**', |
| 35 | '**/tests/**', |
| 36 | '**/__tests__/**', |
| 37 | '**/__mocks__/**', |
| 38 | '**/__e2e__/**', |
| 39 | ], |
| 40 | }; |
| 41 | |
| 42 | for (const path of await glob(src, globOptions)) { |
| 43 | const source = await fs.readFile(path, 'utf-8'); |
| 44 | spinner.text = `Checking ${path}`; |
| 45 | reactCompilerCheck.run(source, path); |
| 46 | strictModeCheck.run(source, path); |
| 47 | libraryCompatCheck.run(source, path); |
| 48 | } |
| 49 | spinner.stop(); |
| 50 | |
| 51 | reactCompilerCheck.report(); |
| 52 | strictModeCheck.report(); |
| 53 | libraryCompatCheck.report(); |
| 54 | } |
| 55 | |
| 56 | main(); |