Skip to content

Commit

Permalink
chore(scripts): Add conversion metrics to typecheck command (#23025)
Browse files Browse the repository at this point in the history
  • Loading branch information
blainekasten authored Apr 13, 2020
1 parent 21d0e5b commit cb224bb
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions scripts/check-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const execa = require(`execa`)

console.log(`TS Check: Running...`)

const PACKAGES_DIR = path.resolve(__dirname, `../packages`)
const toAbsolutePath = relativePath => path.join(__dirname, `..`, relativePath)
const PACKAGES_DIR = toAbsolutePath(`/packages`)

const filterPackage = yargs.argv._[0]

Expand Down Expand Up @@ -59,9 +60,34 @@ if (filterPackage) {
}
}

let totalTsFiles = 0
let totalJsFiles = 0

packagesWithTs.forEach(project => {
const tsFiles = glob.sync(
toAbsolutePath(
`./packages/${project.split(/.*packages[/\\]/)[1]}/src/**/*.ts`
)
).length

const jsFiles = glob.sync(
toAbsolutePath(
`./packages/${project.split(/.*packages[/\\]/)[1]}/src/**/*.js`
)
).length

totalTsFiles += tsFiles
totalJsFiles += jsFiles

const percentConverted = Number(
((tsFiles / (jsFiles + tsFiles)) * 100).toFixed(1)
)

console.log(
`TS Check: Checking ./packages/${project.split(/.*packages[/\\]/)[1]}`
`TS Check: Checking ./packages/${project.split(/.*packages[/\\]/)[1]}`,
`\n - TS Files: ${tsFiles}`,
`\n - JS Files: ${jsFiles}`,
`\n - Percent Converted: ${percentConverted}%`
)

const args = [
Expand All @@ -84,3 +110,15 @@ packagesWithTs.forEach(project => {
})

console.log(`TS Check: Success`)

if (!filterPackage) {
const percentConverted = Number(
((totalTsFiles / (totalJsFiles + totalTsFiles)) * 100).toFixed(1)
)

console.log(
` - Total TS Files: ${totalJsFiles}`,
`\n - Total JS Files: ${totalJsFiles}`,
`\n - Percent Converted: ${percentConverted}%`
)
}

0 comments on commit cb224bb

Please sign in to comment.