forked from stream-labs/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrict-null-progress.js
38 lines (32 loc) · 1.37 KB
/
strict-null-progress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* show the progress of strict-null migration
*/
const fs = require('fs');
const glob = require('glob');
// read all files eligible for the strictNulls checking
const filesPath = 'strict-null-check-files';
const files = fs.readdirSync(filesPath);
const migratedFilesPatterns = [];
files.forEach(file => {
const json = JSON.parse(fs.readFileSync(`${filesPath}/${file}`));
if (json.ts) migratedFilesPatterns.push(...json.ts);
if (json.tsx) migratedFilesPatterns.push(...json.tsx);
});
const allFiles = glob.sync('app/**/*.ts').concat(glob.sync('app/**/*.tsx'));
let migratedFiles = [];
migratedFilesPatterns.forEach(pattern => {
migratedFiles = migratedFiles.concat(glob.sync(pattern));
});
const allLines = allFiles
.map(file => fs.readFileSync(file).toString().split('\n').length)
.reduce((prev, curr) => prev + curr);
const migratedLines = migratedFiles
.map(file => fs.readFileSync(file).toString().split('\n').length)
.reduce((prev, curr) => prev + curr);
const progress = migratedLines / allLines;
const scale = 30;
const barsCount = Math.round(progress * scale);
console.log('\n\nStrict nulls migration progress');
console.log(`[${ '#'.repeat(barsCount) }${ '-'.repeat(scale - barsCount) }] ${ Math.round(progress * 100)}%`);
console.log('migrated:', migratedFiles.length, 'files', migratedLines, 'lines');
console.log('total:', allFiles.length, 'files', allLines, 'lines');