1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 23:06:37 +01:00
metamask-extension/development/ts-migration-dashboard/src/App.tsx

158 lines
5.8 KiB
TypeScript
Raw Normal View History

Add TypeScript migration dashboard (#13820) As we convert parts of the codebase to TypeScript, we will want a way to track progress. This commit adds a dashboard which displays all of the files that we wish to convert to TypeScript and which files we've already converted. The list of all possible files to convert is predetermined by walking the dependency graph of each entrypoint the build system uses to compile the extension (the files that the entrypoint imports, the files that the imports import, etc). The list should not need to be regenerated, but you can do it by running: yarn ts-migration:enumerate The dashboard is implemented as a separate React app. The CircleCI configuration has been updated so that when a new commit is pushed, the React app is built and stored in the CircleCI artifacts. When a PR is merged, the built files will be pushed to a separate repo whose sole purpose is to serve the dashboard via GitHub Pages (this is the same way that the Storybook works). All of the app code and script to build the app are self-contained under `development/ts-migration-dashboard`. To build this app yourself, you can run: yarn ts-migration:dashboard:build or if you want to build automatically as you change files, run: yarn ts-migration:dashboard:watch Then open the following file in your browser (there is no server component): development/ts-migration-dashboard/build/index.html Finally, although you shouldn't have to do this, to manually deploy the dashboard once built, you can run: git remote add ts-migration-dashboard git@github.com:MetaMask/metamask-extension-ts-migration-dashboard.git yarn ts-migration:dashboard:deploy
2022-08-09 22:16:08 +02:00
import React from 'react';
import classnames from 'classnames';
import { Tooltip as ReactTippy } from 'react-tippy';
import { ModulePartition } from '../scripts/build-module-partitions';
// The `brfs` transform for browserify calls `fs.readLineSync` and
// `path.resolve` at build time and inlines file contents into the source code.
// To accomplish this we have to bring in `fs` and `path` using `require` and
// not `import`. This is weird in a TypeScript file, and typescript-eslint
// (rightly) complains about this, but it's actually okay because the above
// `import` lines will actually get turned into `require`s anyway before passing
// through the rest of browserify. However, `brfs` should handle this. There is
// an active bug for this, but there isn't a known workaround yet:
// <https://github.com/browserify/brfs/issues/39>
/* eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires */
const fs = require('fs');
/* eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires */
const path = require('path');
type Summary = {
numConvertedFiles: number;
numFiles: number;
};
function calculatePercentageComplete(summary: Summary) {
return ((summary.numConvertedFiles / summary.numFiles) * 100).toFixed(1);
}
export default function App() {
const partitions = JSON.parse(
fs.readFileSync(
path.resolve(__dirname, '../intermediate/partitions.json'),
{
encoding: 'utf-8',
},
),
) as ModulePartition[];
const allFiles = partitions.flatMap((partition) => {
return partition.children;
});
const overallTotal = {
numConvertedFiles: allFiles.filter((file) => file.hasBeenConverted).length,
numFiles: allFiles.length,
};
return (
<>
<h1 className="page-header">
<img src="images/metamask-fox.svg" className="page-header__icon" />
Extension TypeScript Migration Status
</h1>
<h2
className="overall-summary"
style={{
'--progress': `${calculatePercentageComplete(overallTotal)}%`,
}}
>
OVERALL: {overallTotal.numConvertedFiles}/{overallTotal.numFiles} (
{calculatePercentageComplete(overallTotal)}%)
</h2>
<details className="help">
<summary className="help__question">What is this?</summary>
<div className="help__answer">
<p>
This is a dashboard that tracks the status of converting the
extension codebase from JavaScript to TypeScript. It is updated
whenever a new commit is pushed to the codebase, so it always
represents the current work.
</p>
<p>
Each box
<div className="file file--inline file--to-be-converted">
&nbsp;
</div>
on this page represents a file that either we want to convert or
we've already converted to TypeScript (hover over a box to see the
filename). Boxes that are
<div className="file file--inline file--to-be-converted file--test">
&nbsp;
</div>
greyed out are test or Storybook files.
</p>
<p>
These boxes are further partitioned by <em>level</em>. The level of
a file is how many files you have to import before you reach that
file in the whole codebase. For instance, if we have a file{' '}
<code>foo.js</code>, and that file imports <code>bar.js</code> and{' '}
<code>baz.js</code>, and <code>baz.js</code> imports{' '}
<code>qux.js</code>, then:
</p>
<ul>
<li>
<code>foo.js</code> would be at <em>level 1</em>
</li>
<li>
<code>bar.js</code> and <code>baz.js</code> would be at{' '}
<em>level 2</em>
</li>
<li>
<code>qux.js</code> would be at <em>level 3</em>
</li>
</ul>
<p>
This level assignment can be used to determine a priority for
converting the remaining JavaScript files. Files which have fewer
dependencies should in theory be easier to convert, so files with a
higher level should be converted first. In other words,{' '}
<strong>
you should be able to start from the top and go down
</strong>
.
</p>
</div>
</details>
<div className="levels">
{partitions.map((partition) => {
return (
<div key={partition.level} className="level">
<div className="level__name">level {partition.level}</div>
<div className="level__children">
{partition.children.map(({ name, hasBeenConverted }) => {
const isTest = /\.test\.(?:js|tsx?)/u.test(name);
const isStorybookFile = /\.stories\.(?:js|tsx?)/u.test(name);
return (
<ReactTippy
key={name}
title={name}
arrow={true}
animation="fade"
duration={250}
className="file__tooltipped"
style={{ display: 'block' }}
>
<div
className={classnames('file', {
'file--has-been-converted': hasBeenConverted,
'file--to-be-converted': !hasBeenConverted,
'file--test': isTest,
'file--storybook': isStorybookFile,
})}
/>
</ReactTippy>
);
})}
</div>
</div>
);
})}
</div>
</>
);
}