Skip to content

Instantly share code, notes, and snippets.

@tassoevan
Last active November 22, 2023 20:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tassoevan/73795e501a0adbdf5ded6f3826840bc0 to your computer and use it in GitHub Desktop.
Save tassoevan/73795e501a0adbdf5ded6f3826840bc0 to your computer and use it in GitHub Desktop.
ZX Script to compute the conversion ratio of the TypeScript migration on Rocket.Chat's main repo
#!/usr/bin/env zx
console.log("Fetching stats...");
const files = await globby(["**/*.{js,jsx,ts,tsx}", "!apps/meteor/tests/**/*"], {
onlyFiles: true,
followSymbolicLinks: false,
gitignore: true,
});
const stats = { ts: { count: 0, loc: 0 }, js: { count: 0, loc: 0, big: [] } };
for (const file of files) {
switch (path.extname(file)) {
case '.js':
case '.jsx':
stats.js.count++;
stats.js.loc += (await fs.readFile(file, 'utf-8')).split('\n').filter(s => Boolean(s.trim())).length;
const stat = await fs.stat(file);
if (stat.size > (stats.js.big[0]?.size ?? 0)) {
stats.js.big.unshift({ file, size: stat.size });
stats.js.big.splice(10);
}
break;
case '.ts':
case '.tsx':
stats.ts.count++;
stats.ts.loc += (await fs.readFile(file, 'utf-8')).split('\n').filter(s => Boolean(s.trim())).length;
break;
}
}
console.log(" JavaScript files:", stats.js.count);
console.log(" TypeScript files:", stats.ts.count);
console.log(" Conversion:", (stats.ts.count / (stats.js.count + stats.ts.count) * 100).toFixed(2) + "%");
console.log();
console.log(" JavaScript LOCs:", stats.js.loc);
console.log(" TypeScript LOCs:", stats.ts.loc);
console.log(" Conversion:", (stats.ts.loc / (stats.js.loc + stats.ts.loc) * 100).toFixed(2) + "%");
console.log();
console.log(" JavaScript biggest files:");
for (const { file, size } of stats.js.big) {
console.log(" ", file, "(" + (size / 1024).toFixed(2) + "kb)");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment