Skip to content

Commit

Permalink
Add remaining code to complete MVP
Browse files Browse the repository at this point in the history
All of the commits up to now have been adding code to support an MVP
version of this tool. This commit ties up the MVP by adding a first
rule, which merely verifies that a project has a `src/` directory, the
entrypoint function to the tool, and the executable which kicks off the
whole thing. This commit also adds a package script, `run-tool`, which
can be used in development to quickly smoke test new changes.
  • Loading branch information
mcmire committed Nov 12, 2023
1 parent 6daffb1 commit f204d33
Show file tree
Hide file tree
Showing 17 changed files with 988 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ module.exports = {
'@metamask/eslint-config-nodejs',
],
},

{
files: ['src/cli.ts'],
parserOptions: {
sourceType: 'script',
},
rules: {
// It's okay if this file has a shebang; it's meant to be executed
// directly.
'n/shebang': 'off',
},
},
],

ignorePatterns: [
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ node_modules/
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Repositories that this tool clones, and other temporary data
tmp
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: ['./src/**/*.ts'],
collectCoverageFrom: ['./src/**/*.ts', '!./src/cli.ts'],

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"bin": "./dist/cli.js",
"files": [
"dist/cjs/**",
"dist/esm/**",
Expand All @@ -44,14 +45,16 @@
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepack": "./scripts/prepack.sh",
"run-tool": "ts-node --swc src/cli.ts",
"test": "jest && jest-it-up",
"test:watch": "jest --watch"
},
"dependencies": {
"@metamask/utils": "^8.2.0",
"chalk": "^4.1.2",
"dependency-graph": "^0.11.0",
"execa": "^5.1.1"
"execa": "^5.1.1",
"yargs": "^17.7.2"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.3.1",
Expand Down
22 changes: 22 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

import {
DEFAULT_PROJECT_NAMES,
DEFAULT_CACHED_REPOSITORIES_DIRECTORY_PATH,
} from './constants';
import { main } from './main';

main({
argv: process.argv,
stdout: process.stdout,
stderr: process.stderr,
config: {
cachedRepositoriesDirectoryPath: DEFAULT_CACHED_REPOSITORIES_DIRECTORY_PATH,
defaultProjectNames: DEFAULT_PROJECT_NAMES,
},
}).catch((error) => {
console.error(error);
process.exitCode = 1;
});

// vi: ft=typescript
124 changes: 124 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,129 @@
import path from 'path';

/**
* The number of milliseconds in an hour, used to determine when to pull the
* latest changes for previously cached repositories.
*/
export const ONE_HOUR = 60 * 60 * 1000;

/**
* The name of this project. Used to exclude this repo as a lintable project.
*/
export const THIS_PROJECT_NAME = 'module-lint';

/**
* The root directory of this project.
*/
export const THIS_PROJECT_DIRECTORY_PATH = path.resolve(__dirname, '..');

/**
* Wherever the tool was run.
*/
export const WORKING_DIRECTORY_PATH = process.cwd();

/**
* The usage text printed when the user requests help or provides invalid input.
*/
export const USAGE_TEXT = `
Analyzes one or more repos for divergence from a template repo.
${THIS_PROJECT_NAME} OPTIONS [ARGUMENTS...]
Pass the names of one or more MetaMask repositories to lint them, or pass
nothing to lint all MetaMask repositories.
`.trim();

/**
* In order to lint a remote repository, that repository must be cloned first.
* This is the temporary directory where the clone lives.
*/
export const DEFAULT_CACHED_REPOSITORIES_DIRECTORY_PATH = path.join(
THIS_PROJECT_DIRECTORY_PATH,
'tmp/repositories',
);

/**
* The name of the template repository that project repositories will be
* compared to. The only such repository we have is the module template.
*/
export const DEFAULT_TEMPLATE_REPOSITORY_NAME = 'metamask-module-template';

/**
* All of the remote MetaMask repositories that will be linted if a list is not
* explicitly provided.
*
* Derived from: <https://github.com/MetaMask/core/issues/1079>
*/
export const DEFAULT_PROJECT_NAMES = [
'KeyringController',
'abi-utils',
'action-create-release-pr',
'action-is-release',
'action-npm-publish',
'action-publish-gh-pages',
'action-publish-release',
'action-tech-challenge-setup',
'action-utils',
'actions-test-repo',
'api-playground',
'api-specs',
'auto-changelog',
'bify-module-groups',
'browser-passworder',
'contract-metadata',
'create-release-branch',
'design-tokens',
'detect-provider',
'docusaurus-openrpc',
'eth-block-tracker',
'eth-hd-keyring',
'eth-json-rpc-filters',
'eth-json-rpc-infura',
'eth-json-rpc-middleware',
'eth-json-rpc-provider',
'eth-ledger-bridge-keyring',
'eth-method-registry',
'eth-phishing-detect',
'eth-sig-util',
'eth-simple-keyring',
'eth-snap-keyring',
'eth-token-tracker',
'eth-trezor-keyring',
'ethereum-provider-openrpc-generator',
'etherscan-link',
'extension-port-stream',
'extension-provider',
'iframe-ee-openrpc-inspector-transport',
'json-rpc-engine',
'json-rpc-middleware-stream',
'key-tree',
'keyring-api',
'keyring-snaps-registry',
'logo',
'metamask-eth-abis',
'metamask-onboarding',
'mobile-provider',
'noble-secp256k1-compat-wrapper',
'nonce-tracker',
'object-multiplex',
'obs-store',
'open-rpc-docs-react',
'openrpc-inspector-transport',
'phishing-warning',
'post-message-stream',
'ppom-validator',
'providers',
'rpc-errors',
'safe-event-emitter',
'smart-transactions-controller',
'snap-simple-keyring',
'snaps-registry',
'state-log-explorer',
'swappable-obj-proxy',
'template-sync',
'test-dapp',
'types',
'utils',
'vault-decryptor',
'web3-stream-provider',
];
3 changes: 3 additions & 0 deletions src/establish-metamask-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export async function establishMetaMaskRepository({
if (existingRepository.isKnownMetaMaskRepository) {
await requireDefaultBranchSelected(existingRepository);

log(
`(${existingRepository.shortname}) Ensuring default branch is up to date...`,
);
const updatedLastFetchedDate = await ensureDefaultBranchIsUpToDate(
existingRepository.directoryPath,
existingRepository.lastFetchedDate,
Expand Down
Loading

0 comments on commit f204d33

Please sign in to comment.