phetsims / tasks

General tasks for PhET that will be tracked on Github
MIT License
5 stars 2 forks source link

TS vs. LS lines of code shell script #1109

Closed marlitas closed 2 years ago

marlitas commented 2 years ago

A shell script that iterates through all common code repos to compare javascript lines of code to typescript lines of code.

marlitas commented 2 years ago

@zepumph Here is updated code tracking all the things. Let's chat on how to make this work for Windows.

```javascript // Copyright 2022, University of Colorado Boulder /* eslint-env es6 */ const child_process = require( 'child_process' ); const fs = require( 'fs' ); const Path = require( 'path' ); const process = require( 'process' ); // babel? //ipaddr.js error - const repos = [ "chipper", "assert", "axon", "babel", "brand", "dot", "joist", "kite", "perennial", "perennial-alias", "phet-core", "phetcommon", "phetmarks", "query-string-machine", "scenery", "scenery-phet", "sherpa", "sun", "tambo", "tandem", "twixt", "utterance-queue", "vegas", ] const formatResult = ( result ) => { const filteredResult = result.toString().split( /\r?\n/ ).filter( string => string ); const linesOfCode = filteredResult && filteredResult.pop(); const linesOfCodeFormatted = linesOfCode ? linesOfCode.split( ' ' ).filter( string => string ).shift() : '0'; return parseInt( linesOfCodeFormatted ); } const formatWordCountResult = ( result ) => { const instances = result.split( /\r?\n/ ).map( string => parseInt( string.slice( -1 ) ) ); let count = 0 instances.forEach( instance => { if ( instance ) { count += instance } } ); return count } const percent = ( numerator, denominator ) => { return ( numerator / denominator ) * 100 | 0 } const rows = repos.map( ( repo ) => { const jsResult = child_process.execSync( 'find . -path ./node_modules -prune -o -name \'*.js\' -print | xargs wc -l', { cwd: `${repo}` } ); const tsResult = child_process.execSync( 'find . -name \'*.ts\' | xargs wc -l', { cwd: `${repo}` } ); const tsIgnoreResult = child_process.spawnSync( 'grep -r -c -w @ts-ignore', { cwd: `${repo}`, shell: true } ); const anyResult = child_process.spawnSync( 'grep -r -c -w any', { cwd: `${repo}`, shell: true } ); const row = { 'Repo': repo, 'JS': formatResult( jsResult ), 'TS': formatResult( tsResult ), '% Complete': percent( formatResult( tsResult ), formatResult( jsResult ) + formatResult( tsResult ) ), 'ts-ignore': formatWordCountResult( tsIgnoreResult[ 'output' ][ 1 ].toString() ), 'any': formatWordCountResult( anyResult['output'][1].toString() ) } return row } ) let totalJS = 0; let totalTS = 0; let totalTSIgnore = 0; let totalAny = 0; rows.forEach( ( row ) => { totalJS += row[ 'JS' ]; totalTS += row[ 'TS' ]; totalTSIgnore += row[ 'ts-ignore']; totalAny += row[ 'any' ]; } ); const repoList = repos.map( repo => ' ' + repo ) const summary = `\n --------- SUMMARY ---------- total "@ts-ignore": ${totalTSIgnore} total "any": ${totalAny} Total JS: ${totalJS} Total TS: ${totalTS} Complete: ${percent( totalTS, totalTS + totalJS )}% ` console.table( rows ); console.log( summary ); ```
marlitas commented 2 years ago

This issue is now being tracked here: https://github.com/phetsims/perennial/issues/274. Closing.