A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
ciphermask/development/ts-migration-dashboard/scripts/write-list-of-files-to-conv...

59 lines
1.6 KiB

import path from 'path';
import fs from 'fs';
import fg from 'fast-glob';
import madge from 'madge';
import {
BASE_DIRECTORY,
ENTRYPOINT_PATTERNS,
FILES_TO_CONVERT_PATH,
} from './constants';
main().catch((error) => {
console.error(error);
process.exit(1);
});
/**
* The entrypoint to this script.
*
* Uses the `madge` package to traverse the dependency graph of a set of
* entrypoints (a combination of the ones that the build script uses to build
* the extension as well as a manually picked list), outputting a JSON array
* containing all JavaScript files that need to be converted to TypeScript.
*/
async function main(): Promise<void> {
const entrypoints = (
await Promise.all(
ENTRYPOINT_PATTERNS.map((entrypointPattern) => {
return fg(
path.resolve(BASE_DIRECTORY, `${entrypointPattern}.{js,ts,tsx}`),
);
}),
)
).flat();
console.log(
`Traversing dependency trees for ${entrypoints.length} entrypoints, please wait...`,
);
const result = await madge(entrypoints, {
baseDir: BASE_DIRECTORY,
});
const dependenciesByFilePath = result.obj();
const sortedFilePaths = Object.keys(dependenciesByFilePath)
.sort()
.filter((filePath) => {
return (
/\.(?:js|tsx?)$/u.test(filePath) &&
!/^(?:\.storybook|node_modules)\//u.test(filePath)
);
});
fs.writeFileSync(
FILES_TO_CONVERT_PATH,
JSON.stringify(sortedFilePaths, null, ' '),
);
console.log(
`${path.relative(process.cwd(), FILES_TO_CONVERT_PATH)} written with ${
sortedFilePaths.length
} modules.`,
);
}