Skip to content

Commit 5c511c6

Browse files
committed
Initial commit
0 parents  commit 5c511c6

21 files changed

+5653
-0
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.eslintrc.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
root: true,
3+
4+
extends: ['@metamask/eslint-config'],
5+
6+
overrides: [
7+
{
8+
files: ['*.ts'],
9+
extends: ['@metamask/eslint-config-typescript'],
10+
},
11+
12+
{
13+
files: ['*.js'],
14+
parserOptions: {
15+
sourceType: 'script',
16+
},
17+
extends: ['@metamask/eslint-config-nodejs'],
18+
},
19+
20+
{
21+
files: ['*.test.ts', '*.test.js'],
22+
extends: ['@metamask/eslint-config-jest'],
23+
},
24+
],
25+
26+
ignorePatterns: ['!.eslintrc.js', '!.prettierrc.js', 'dist/'],
27+
};

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
3+
yarn.lock linguist-generated=false

.github/CODEOWNERS

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Lines starting with '#' are comments.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
* @MetaMask/devs

.github/dependabot.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Please see the documentation for all configuration options:
2+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3+
4+
version: 2
5+
updates:
6+
- package-ecosystem: 'npm'
7+
directory: '/'
8+
schedule:
9+
interval: 'daily'
10+
time: '06:00'
11+
allow:
12+
- dependency-name: '@metamask/*'
13+
target-branch: 'main'
14+
versioning-strategy: 'increase-if-necessary'
15+
open-pull-requests-limit: 10

.github/workflows/build-test.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build, Lint, and Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
build-lint-test:
10+
name: Build, Lint, and Test
11+
runs-on: ubuntu-20.04
12+
strategy:
13+
matrix:
14+
node-version: [12.x, 14.x, 16.x]
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Use Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- name: Get Yarn cache directory
22+
run: echo "::set-output name=YARN_CACHE_DIR::$(yarn cache dir)"
23+
id: yarn-cache-dir
24+
- name: Get Yarn version
25+
run: echo "::set-output name=YARN_VERSION::$(yarn --version)"
26+
id: yarn-version
27+
- name: Cache yarn dependencies
28+
uses: actions/cache@v2
29+
with:
30+
path: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
31+
key: yarn-cache-${{ runner.os }}-${{ steps.yarn-version.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}
32+
- run: yarn --frozen-lockfile
33+
- run: yarn allow-scripts
34+
- run: yarn build
35+
- run: yarn lint
36+
- run: yarn test
37+
- name: Validate RC changelog
38+
if: ${{ startsWith(github.head_ref, 'release/') }}
39+
run: yarn auto-changelog validate --rc
40+
- name: Validate changelog
41+
if: ${{ !startsWith(github.head_ref, 'release/') }}
42+
run: yarn auto-changelog validate
43+
all-jobs-pass:
44+
name: All jobs pass
45+
runs-on: ubuntu-20.04
46+
needs:
47+
- build-lint-test
48+
steps:
49+
- run: echo "Great success!"
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Create Release Pull Request
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
base-branch:
7+
description: 'The base branch for git operations and the pull request.'
8+
default: 'main'
9+
required: true
10+
release-type:
11+
description: 'A SemVer version diff, i.e. major, minor, patch, prerelease etc. Mutually exclusive with "release-version".'
12+
required: false
13+
release-version:
14+
description: 'A specific version to bump to. Mutually exclusive with "release-type".'
15+
required: false
16+
17+
jobs:
18+
create-release-pr:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: write
22+
pull-requests: write
23+
steps:
24+
- uses: actions/checkout@v2
25+
with:
26+
# This is to guarantee that the most recent tag is fetched.
27+
# This can be configured to a more reasonable value by consumers.
28+
fetch-depth: 0
29+
# We check out the specified branch, which will be used as the base
30+
# branch for all git operations and the release PR.
31+
ref: ${{ github.event.inputs.base-branch }}
32+
- name: Get Node.js version
33+
id: nvm
34+
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
35+
- uses: actions/setup-node@v2
36+
with:
37+
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
38+
- uses: MetaMask/action-create-release-pr@v1
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
with:
42+
release-type: ${{ github.event.inputs.release-type }}
43+
release-version: ${{ github.event.inputs.release-version }}
44+
artifacts-path: gh-action__release-authors
45+
# Upload the release author artifact for use in subsequent workflows
46+
- uses: actions/upload-artifact@v2
47+
with:
48+
name: release-authors
49+
path: gh-action__release-authors
50+
if-no-files-found: error

.github/workflows/publish-release.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
publish-release:
9+
permissions:
10+
contents: write
11+
if: |
12+
github.event.pull_request.merged == true &&
13+
startsWith(github.event.pull_request.head.ref, 'release/')
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
with:
18+
# We check out the release pull request's base branch, which will be
19+
# used as the base branch for all git operations.
20+
ref: ${{ github.event.pull_request.base.ref }}
21+
- name: Get Node.js version
22+
id: nvm
23+
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
24+
- uses: actions/setup-node@v2
25+
with:
26+
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
27+
- uses: MetaMask/action-publish-release@v1
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Require Additional Reviewer for Releases
2+
3+
on:
4+
pull_request:
5+
pull_request_review:
6+
7+
jobs:
8+
require-additional-reviewer:
9+
permissions:
10+
actions: read
11+
contents: read
12+
pull-requests: read
13+
statuses: write
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
with:
18+
# If the base branch has been merged into the release branch, we
19+
# need to find the earliest common ancestor commit of the base and
20+
# release branches.
21+
fetch-depth: 0
22+
# We want the head / feature branch to be checked out, and we will
23+
# compare it to the base branch in the action.
24+
ref: ${{ github.event.pull_request.head.ref }}
25+
- uses: MetaMask/action-require-additional-reviewer@v1
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
with:
29+
read-org-token: ${{ secrets.ORG_READER }}

.gitignore

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.DS_Store
2+
dist/
3+
coverage/
4+
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
38+
# TypeScript cache
39+
*.tsbuildinfo
40+
41+
# Optional npm cache directory
42+
.npm
43+
44+
# Optional eslint cache
45+
.eslintcache
46+
47+
# Microbundle cache
48+
.rpt2_cache/
49+
.rts2_cache_cjs/
50+
.rts2_cache_es/
51+
.rts2_cache_umd/
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
.env.test
65+
66+
# Stores VSCode versions used for testing VSCode extensions
67+
.vscode-test
68+
69+
# yarn v2
70+
.yarn/cache
71+
.yarn/unplugged
72+
.yarn/build-state.yml
73+
.yarn/install-state.gz
74+
.pnp.*

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v12

.prettierrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// All of these are defaults except singleQuote, but we specify them
2+
// for explicitness
3+
module.exports = {
4+
quoteProps: 'as-needed',
5+
singleQuote: true,
6+
tabWidth: 2,
7+
trailingComma: 'all',
8+
};

.yarnrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore-scripts true

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
[Unreleased]: https://github.com/MetaMask/metamask-module-template/

README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# MetaMask Module Template
2+
3+
This TypeScript module is maintained in the style of the MetaMask team.
4+
5+
## Installation
6+
7+
`yarn add @metamask/this-module`
8+
9+
or
10+
11+
`npm install @metamask/this-module`
12+
13+
## Usage
14+
15+
_Add examples here_
16+
17+
## API
18+
19+
_Add examples here_
20+
21+
## Contributing
22+
23+
### Setup
24+
25+
- Install [Node.js](https://nodejs.org) version 12
26+
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
27+
- Install [Yarn v1](https://yarnpkg.com/en/docs/install)
28+
- Run `yarn setup` to install dependencies and run any requried post-install scripts
29+
- **Warning:** Do not use the `yarn` / `yarn install` command directly. Use `yarn setup` instead. The normal install command will skip required post-install scripts, leaving your development environment in an invalid state.
30+
31+
### Testing and Linting
32+
33+
Run `yarn test` to run the tests once. To run tests on file changes, run `yarn test:watch`.
34+
35+
Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
36+
37+
### Release & Publishing
38+
39+
The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.
40+
41+
1. Choose a release version.
42+
43+
- The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.
44+
45+
2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).
46+
47+
- The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.
48+
49+
3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.
50+
51+
- For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
52+
- This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
53+
54+
4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.
55+
56+
- Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
57+
- Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
58+
- Consolidate related changes into one change entry if it makes it easier to explain.
59+
- Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.
60+
61+
5. Review and QA the release.
62+
63+
- If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.
64+
65+
6. Squash & Merge the release.
66+
67+
- This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.
68+
69+
7. Publish the release on npm.
70+
71+
- Be very careful to use a clean local environment to publish the release, and follow exactly the same steps used during CI.
72+
- Use `npm publish --dry-run` to examine the release contents to ensure the correct files are included. Compare to previous releases if necessary (e.g. using `https://unpkg.com/browse/[package name]@[package version]/`).
73+
- Once you are confident the release contents are correct, publish the release using `npm publish`.

0 commit comments

Comments
 (0)