Skip to content

Commit 1a934f3

Browse files
Initial commit
0 parents  commit 1a934f3

23 files changed

+16070
-0
lines changed

.changeset/config.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": [
4+
"@changesets/changelog-github",
5+
{ "repo": "apollographql/typescript-repo-template" }
6+
],
7+
"commit": false,
8+
"access": "public",
9+
"baseBranch": "main"
10+
}

.circleci/config.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: 2.1
2+
3+
orbs:
4+
node: circleci/[email protected]
5+
6+
commands:
7+
install-volta:
8+
description: Install volta to manage Node/npm versions
9+
steps:
10+
- run:
11+
name: Install volta
12+
# Teach the volta installer to update Circle's special env
13+
# file instead of the default.
14+
command: |
15+
curl https://get.volta.sh | PROFILE="$BASH_ENV" bash
16+
17+
setup-node:
18+
parameters:
19+
node-version:
20+
type: string
21+
default: ''
22+
steps:
23+
- install-volta
24+
- checkout
25+
- when:
26+
condition: << parameters.node-version >>
27+
steps:
28+
- run: volta pin node@<< parameters.node-version >>
29+
- run: node --version
30+
- run: npm --version
31+
- node/install-packages
32+
33+
jobs:
34+
NodeJS:
35+
parameters:
36+
node-version:
37+
type: string
38+
docker:
39+
- image: cimg/base:stable
40+
steps:
41+
- setup-node:
42+
node-version: <<parameters.node-version>>
43+
- run: npm run test:ci
44+
- store_test_results:
45+
path: junit.xml
46+
47+
Prettier:
48+
docker:
49+
- image: cimg/base:stable
50+
steps:
51+
- setup-node
52+
- run: npm run prettier-check
53+
54+
Spell Check:
55+
docker:
56+
- image: cimg/base:stable
57+
steps:
58+
- setup-node
59+
- run: npm run spell-check
60+
61+
workflows:
62+
version: 2
63+
Build:
64+
jobs:
65+
- NodeJS:
66+
name: NodeJS << matrix.node-version >>
67+
matrix:
68+
parameters:
69+
node-version:
70+
- "14"
71+
- "16"
72+
- "18"
73+
- Prettier
74+
- Spell Check

.codesandbox/ci.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sandboxes": [],
3+
"node": "16",
4+
"installCommand": "install-with-npm-8.5"
5+
}

.envrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export VOLTA_HOME="$PWD/.volta"
2+
PATH_add "$VOLTA_HOME/bin"
3+
4+
if ! [ -f "$VOLTA_HOME/bin/volta" ]; then
5+
echo "Volta not found in $VOLTA_HOME/bin/volta, installing..."
6+
curl https://get.volta.sh/ | bash
7+
fi
8+
9+
# Allow you to run jest and other things in node_modules/.bin without npx.
10+
layout node

.github/workflows/release-pr.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Repo
14+
uses: actions/checkout@v3
15+
with:
16+
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
17+
fetch-depth: 0
18+
19+
- name: Setup Node.js 16.x
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 16.x
23+
24+
- name: Install Dependencies
25+
run: npm i
26+
27+
- name: Create Release Pull Request / NPM Publish
28+
uses: changesets/action@v1
29+
with:
30+
publish: npm run publish-changeset
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Ignore the compiled output.
2+
dist/
3+
4+
# TypeScript incremental compilation cache
5+
*.tsbuildinfo
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Coverage (from Jest)
15+
coverage/
16+
17+
# JUnit Reports (used mainly in CircleCI)
18+
reports/
19+
junit.xml
20+
21+
# Node modules
22+
node_modules/
23+
24+
# Mac OS
25+
.DS_Store
26+
27+
# Intellij Configuration Files
28+
.idea/
29+
30+
# Volta binaries (when using direnv/.envrc)
31+
.volta

.npmignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*
2+
!src/**/*
3+
src/**/__tests__/**
4+
!dist/**/*
5+
dist/**/__tests__/**
6+
!package.json
7+
!README.md
8+
!tsconfig.base.json
9+
!tsconfig.json
10+
!tsconfig.build.json

.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.json
2+
*.json5
3+
*.yml
4+
*.md
5+
6+
dist/

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"trailingComma": "all",
3+
"singleQuote": true
4+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022- Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# TypeScript Template
2+
3+
This repo is meant to act as a reasonable foundation for a single NPM package developed in TypeScript. It makes use of a few tools that we've found particularly useful. Below are some notes on how to get started using these tools and ways in which you might want (or need) to configure them.
4+
5+
## GitHub
6+
7+
In the GitHub settings tab, we typically configure a few things.
8+
9+
**General**
10+
✅ Automatically delete head branches
11+
12+
**Collaborators and Teams**
13+
Add relevant teams and contributors with appropriate roles
14+
15+
**Branches**
16+
Typically we add a branch protection rule for `main`
17+
Generally, this rule enables:
18+
* ✅ Require a pull request before merging
19+
* ✅ Require approvals (1)
20+
* ✅ Require status checks to pass before merging
21+
* Each status check must be selected via the search box. Typing "ci/" will show you a list of the ones which exist within this template. "CLA" should also be enabled.
22+
23+
**Code Security and Analysis**
24+
* Enable "Dependabot security updates" to receive security-related PRs from Dependabot
25+
26+
## CircleCI
27+
28+
This repo comes with a few Circle jobs already implemented (see [`.circleci/config.yml`](.circleci/config.yml)). Circle will run tests on the versions of Node specified in the matrix and enforce linting via Prettier.
29+
30+
In order to enable CircleCI on your new repo, visit the [Apollo org's dashboard](https://app.circleci.com/projects/project-dashboard/github/apollographql/) and add your project. If your repo has already been initialized and added to the apollographql org, you should see the option to add your new project.
31+
32+
## Jest
33+
34+
Jest is a testing framework used by most of Apollo's current projects.
35+
36+
To run tests in the repo:
37+
`npm test`
38+
39+
The Jest configuration can be found at `jest.config.ts`. As configured, Jest will run all files named `*.test.ts` found within any `__tests__` folder. This is simply a convention chosen by this repo and can be reconfigured via the `testRegex` configuration option in [`jest.config.ts`](jest.config.ts).
40+
41+
For more information on configuring Jest see the [Jest docs](https://jestjs.io/docs/configuration).
42+
43+
## Changesets
44+
45+
Changesets is a tool for managing package versioning, NPM releases, GitHub releases, and CHANGELOG entries. In this template, it comes configured for all of the above.
46+
47+
### Basic usage
48+
49+
Changesets uses changeset files in the `.changeset` directory to determine what versioning upgrades need to happen next, along with related `CHANGELOG` updates and release notes. A changeset file is created by running `npx changeset` and following the prompts. PRs which make functional changes to the package should always come with an accompanying changeset file. The Changeset bot (details below) will comment on PRs as a reminder to contributors to include a changeset file when appropriate.
50+
51+
### Changeset bot
52+
53+
#### Installation
54+
55+
[GitHub app](https://github.com/apps/changeset-bot)
56+
> Note: a GitHub _org_ admin must approve app installations. By adding a GitHub app to your repo, you'll be submitting a request for approval. At the time of writing this, the GitHub UI doesn't make this clear.
57+
58+
59+
You might also be interested in adding `changeset-bot` to the repo - it leaves comments about the changeset (or lack thereof) for each PR. This serves as a nice reminder and set of instructions for how to create a changeset.
60+
61+
### Changesets enforced in CI (alternative to Changeset bot)
62+
63+
The `changeset-bot` will leave a comment on every PR. If you'd prefer to enforce changesets in CI without the additional noise, you can do so by adding a step to your CircleCI config. We use the following in the Apollo Server repo:
64+
65+
```yaml
66+
# Ensure that any PR that changes packages has a changeset on it (perhaps
67+
# an empty one created with `changeset --empty`).
68+
# We run the Changesets job itself on all branches so that we can require
69+
# it to pass, but we don't run any steps on the "Version Packages" PRs
70+
# themselves.
71+
Changesets:
72+
docker:
73+
- image: cimg/base:stable
74+
steps:
75+
- run: echo Ensure there is at least one step
76+
- unless:
77+
condition:
78+
matches:
79+
pattern: "^changeset-release/.+$"
80+
value: << pipeline.git.branch >>
81+
steps:
82+
- setup-node
83+
- run: npm run changeset-check
84+
```
85+
86+
The referenced script `changeset-check` is defined in `package.json` and is a simple script that runs `changeset status` and exits with a non-zero status if there are any changesets missing like so:
87+
88+
```json
89+
{
90+
// ...
91+
"scripts": {
92+
// ...
93+
"changeset-check": "changeset-check": "changeset status --verbose --since=origin/main"
94+
}
95+
}
96+
```
97+
98+
### CHANGELOG updates
99+
100+
For proper CHANGELOG management, you MUST configure the [`.changeset/config.json`](.changeset/config.json) file for your repo. The `changelog.repo` field must be the `<org>/<name>` of the repo.
101+
102+
### NPM Publishing
103+
104+
Changesets manages and updates a release PR automatically via a GitHub action [`.github/workflows/release-pr.yml`](.github/workflows/release-pr.yml). The PR consumes all of the committed changesets on `main` in order to bump versions of packages and update the `CHANGELOG` accordingly. Merging this PR will result in publishes to npm IF you've provided an `NPM_TOKEN` as a secret to your repo's GitHub actions (`https://github.com/apollographql/<repo-name>/settings/secrets/actions`). Please reach out to anyone in the `#npm-apollo-bot-owners` Slack channel for a token. Changesets will also publish a GitHub release when this PR is merged.
105+
106+
> Our action borrows directly from the action provided by `changesets`. Visit [the changesets action repo](https://github.com/changesets/action) for more info.
107+
108+
### Removing Changesets
109+
110+
If you're not interested in using `changesets`, just delete the [workflow](.github/workflows/release-pr.yml), uninstall the related dependencies, and delete the related scripts.
111+
112+
> For additional information on `changesets`, [visit the docs](https://github.com/changesets/changesets#documentation).
113+
114+
## CodeSandbox CI
115+
116+
> At the time of writing this, CodeSandbox CI only works for public repos.
117+
118+
### Installation
119+
120+
[GitHub app](https://github.com/apps/codesandbox)
121+
> Note: a GitHub _org_ admin must approve app installations. By adding a GitHub app to your repo, you'll be submitting a request for approval. At the time of writing this, the GitHub UI doesn't make this clear.
122+
123+
CodeSandbox CI provides an installable build of your package on every PR. If your package builds successfully, CS:CI will leave a comment on the PR with instructions on how to try out your build in a project. This gives contributors access to their work immediately, allowing them to manually test their builds or even use a fix right away.
124+
125+
CS:CI will also provide links to sandboxes which use your newly built package if you choose. This is configurable via the `sandboxes` field in [`.codesandbox/ci.json`](.codesandbox/ci.json). This field is a list of sandbox IDs which you can find via the CodeSandbox web interface. For example, the Apollo Server repo specifies both JS and TS Apollo Server sandboxes like so: `["apollo-server-typescript-3opde","apollo-server"]`.
126+
127+
> For additional information on configuring CS:CI, [visit the docs](https://codesandbox.io/docs/ci).
128+
129+
## Renovate
130+
131+
### Installation
132+
133+
[GitHub app](https://github.com/apps/renovate)
134+
135+
> Note: a GitHub _org_ admin must approve app installations. By adding a GitHub app to your repo, you'll be submitting a request for approval. At the time of writing this, the GitHub UI doesn't make this clear.
136+
137+
Renovate automates dependency updates. The bot will open and merge PRs with updates to a variety of dependencies (including but not limited to npm dependencies). Renovate is _highly_ configurable via the [renovate.json5](renovate.json5) file. Package restrictions and scheduling are just a couple things that we commonly configure.
138+
139+
If you've configured PRs to require approval (mentioned in [GitHub](#github)), you may want to also install [Renovate's Approve bot](https://github.com/apps/renovate-approve). The approve bot will approve all renovate PRs in order to appease the PR approval requirement.
140+
141+
If you're unfamiliar with Renovate, the docs are really worth perusing even if just to get an idea of what kinds of configuration are possible.
142+
143+
> For additional information on configuring Renovate, [visit the docs](https://docs.renovatebot.com/).
144+
145+
## Prettier
146+
147+
Prettier is an opinionated code formatting tool.
148+
149+
To check for formatting issues:
150+
`npm run prettier:check`
151+
152+
To auto-fix formatting issues:
153+
`npm run prettier:fix`
154+
155+
This is enforced in CI via the `Prettier` job.
156+
157+
> For additional information on configuring Prettier, [visit the docs](https://prettier.io/docs/en/options).
158+
159+
## Volta
160+
161+
Volta is a fast JS toolchain manager. Similar in effect to nvm, Volta allows for projects to specify their node / npm versions and will automatically handle the switching for you.
162+
163+
If using [direnv](https://direnv.net/), Volta will automatically be installed for you. The node and npm versions are specified in [`package.json`](package.json) and Renovate handles keeping these versions up to date.
164+
165+
> For additional information on configuring Volta, [visit the docs](https://docs.volta.sh/guide/).

cspell-dict.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apollographql
2+
asynciterable
3+
changesets
4+
cimg
5+
circleci
6+
codesandbox
7+
direnv
8+
opde

0 commit comments

Comments
 (0)