Skip to content

Commit d22544f

Browse files
feat: reworked setup flow and renamed to "initialization" and "migration" (#668)
<!-- 👋 Hi, thanks for sending a PR to template-typescript-node-package! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #613 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview * Renames the existing scripts and refers to them under the umbrella term of "setup": * "Hydration": is now called "migration" * "Setup": is now called "initialization" * Splits their usage docs into `./docs/*.md` files, with more explanations of what they do
1 parent 8620991 commit d22544f

File tree

80 files changed

+358
-291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+358
-291
lines changed

.github/DEVELOPMENT.md

+59-25
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pnpm install
1313
1414
## Building
1515

16-
Run [[**tsup**](https://tsup.egoist.dev) locally to build source files from `src/` into output files in `lib/`:
16+
Run [**tsup**](https://tsup.egoist.dev) locally to build source files from `src/` into output files in `lib/`:
1717

1818
```shell
1919
pnpm build
@@ -87,47 +87,81 @@ Add `--watch` to keep the type checker running in a watch mode that updates the
8787
pnpm tsc --watch
8888
```
8989

90-
## The Hydration Script
90+
## Setup Scripts
9191

92-
This template's "hydration" script is located in `src/hydrate/`.
93-
It needs to be [built](#building) before it can be run.
92+
As described in the `README.md` file and `docs/`, this template repository comes with two scripts that can set up an existing or new repository.
9493

95-
Be warned that running the hydration script in a repository -including this one- will modify that repository.
96-
To test out the script, you may want to create a new test repository to run on:
94+
> **Warning**
95+
> Both setup scripts override many files in the directory they're run in.
96+
> Make sure to save any changes you want to preserve before running them.
97+
98+
### The Initialization Script
99+
100+
This template's "initialization" script is located in `src/initialize/`.
101+
You can run it locally with `pnpm run initialize`.
102+
It uses [`tsx`](https://github.com/esbuild-kit/tsx) so you don't need to build files before running.
97103

98104
```shell
99-
cd ..
100-
mkdir temp
101-
cd temp
102-
echo node_modules > .gitignore
103-
git init
104-
npm init --yes
105+
pnpm run initialize
105106
```
106107

107-
Then, in that directory, you can directly call the hydration script:
108+
> 💡 Consider running `git add -A` to stage all local changes before running.
109+
110+
#### Testing the Initialization Script
111+
112+
You can run the end-to-end test for initializing locally on the command-line.
113+
Note that files need to be built with `pnpm run build` beforehand.
108114

109115
```shell
110-
node ../template-typescript-node-package/lib/hydrate/index.js -- description "Hooray, trying things out locally."
116+
pnpm run initialize:test
111117
```
112118

113-
Along with the hydration script itself, end-to-end tests are removed on package setup.
119+
That end-to-end test executes `script/initialize-test-e2e.js`, which:
114120

115-
## The Setup Script
121+
1. Runs the initialization script using `--skip-github-api` and other skip flags
122+
2. Checks that the local repository's files were changed correctly (e.g. removed initialization-only files)
123+
3. Runs `pnpm run lint:knip` to make sure no excess dependencies or files were left over
124+
4. Resets everything
125+
5. Runs initialization a second time, capturing test coverage
116126

117-
This template's "setup" script is located in `script/`.
127+
The `pnpm run initialize:test` script is run in CI to ensure that templating changes are in sync with the template's actual files.
128+
See `.github/workflows/test-initialize.yml`.
118129

119-
### Testing the Setup Script
130+
### The Migration Script
120131

121-
This template source includes an "end-to-end" test for `script/setup.js`.
122-
You can run it locally on the command-line:
132+
This template's "migration" script is located in `src/migrate/`.
133+
Note that files need to be built with `pnpm run build` beforehand.
134+
135+
To test out the script locally, run it from a different repository's directory:
136+
137+
```shell
138+
cd ../other-repo
139+
node ../template-typescript-node-package/bin/migrate.js
140+
```
141+
142+
The migration script will work on any directory.
143+
You can try it out in a blank directory with scripts like:
144+
145+
```shell
146+
cd ..
147+
mkdir temp
148+
cd temp
149+
node ../template-typescript-node-package/bin/migrate.js
150+
```
151+
152+
#### Testing the Migration Script
153+
154+
You can run the end-to-end test for migrating locally on the command-line:
123155

124156
```shell
125-
pnpm run setup:test
157+
pnpm run initiamigratelize:test
126158
```
127159

128-
That end-to-end test executes `script/setup-test-e2e.js`, which:
160+
That end-to-end test executes `script/migrate-test-e2e.js`, which:
129161

130-
1. Runs the setup script using `--skip-api`
131-
2. Checks that the local repository's files were changed correctly (e.g. removed setup-only files)
162+
1. Runs the migration script using `--skip-github-api` and other skip flags
163+
2. Checks that only a small list of allowed files were changed
164+
3. Checks that the local repository's files were changed correctly (e.g. removed initialization-only files)
132165

133-
Along with the setup script itself, end-to-end tests are removed on package setup.
166+
The `pnpm run migrate:test` script is run in CI to ensure that templating changes are in sync with the template's actual files.
167+
See `.github/workflows/test-migrate.yml`.

.github/workflows/setup.yml .github/workflows/test-initialize.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
jobs:
2-
setup:
2+
initialize:
33
runs-on: ubuntu-latest
44
steps:
55
- uses: actions/checkout@v3
66
- uses: ./.github/actions/prepare
77
- run: pnpm run build
8-
- run: pnpm run setup:test
8+
- run: pnpm run initialize:test
99
- name: Codecov
1010
uses: codecov/codecov-action@v3
1111
with:
12-
files: coverage-setup/lcov.info
13-
flags: setup
12+
files: coverage-initialize/lcov.info
13+
flags: initialize
1414
- if: always()
1515
name: Archive code coverage results
1616
uses: actions/upload-artifact@v3
1717
with:
18-
path: coverage-setup
18+
path: coverage-initialize
1919

20-
name: Test Setup Script
20+
name: Test Initialization Script
2121

2222
on:
2323
pull_request: ~

.github/workflows/hydrate.yml .github/workflows/test-migrate.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
jobs:
2-
hydrate:
2+
migrate:
33
runs-on: ubuntu-latest
44
steps:
55
- uses: actions/checkout@v3
66
- uses: ./.github/actions/prepare
77
- run: pnpm run build
8-
- run: pnpm run hydrate:test
8+
- run: pnpm run migrate:test
99
- name: Codecov
1010
uses: codecov/codecov-action@v3
1111
with:
12-
files: coverage-hydrate/lcov.info
13-
flags: hydrate
12+
files: coverage-migrate/lcov.info
13+
flags: migrate
1414
- if: always()
1515
name: Archive code coverage results
1616
uses: actions/upload-artifact@v3
1717
with:
18-
path: coverage-hydrate
18+
path: coverage-migrate
1919

20-
name: Test Hydrate Script
20+
name: Test Migration Script
2121

2222
on:
2323
pull_request: ~

README.md

+15-107
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,23 @@
2626
<img alt="TypeScript: Strict 💪" src="https://img.shields.io/badge/typescript-strict_💪-21bb42.svg" />
2727
</p>
2828

29+
## Getting Started
30+
31+
First make sure you have the following installed:
32+
33+
- [GitHub CLI](https://cli.github.com) _(you'll need to be logged in)_
34+
- [Node.js](https://nodejs.org)
35+
- [pnpm](https://pnpm.io)
36+
37+
This repository comes with two scripts to set up an existing or new repository with tooling.
38+
Use the corresponding docs page to get started:
39+
40+
- [Initializing from the template](./docs/Initialization.md): creating a new repository with the [_Use this template_](https://github.com/JoshuaKGoldberg/template-typescript-node-package/generate) button on GitHub
41+
- [Migrating an existing repository](./docs/Migration.md): adding this template's tooling on top of an existing repository
42+
2943
## Explainer
3044

31-
This template is available for anybody who wants to set up a basic Node application using TypeScript.
45+
This template is available for anybody who wants to set up a Node application using TypeScript.
3246
It sets up the following tooling for you:
3347

3448
- [**All Contributors**](https://allcontributors.org): Tracks various kinds of contributions and displays them in a nicely formatted table in the README.md.
@@ -44,112 +58,6 @@ It sets up the following tooling for you:
4458
- [**TypeScript**](https://typescriptlang.org): A typed superset of JavaScript, configured with strict compiler options.
4559
- [**Vitest**](https://vitest.dev): Fast unit tests, configured with coverage tracking and [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test).
4660

47-
## Setup
48-
49-
This package comes with a bootstrap/initialization setup script that fills out your repository's details, installs necessary packages, then removes itself and uninstalls setup dependencies.
50-
51-
First make sure you have the following installed:
52-
53-
- [GitHub CLI](https://cli.github.com) _(you'll need to be logged in)_
54-
- [Node.js](https://nodejs.org)
55-
- [pnpm](https://pnpm.io)
56-
57-
To use this template:
58-
59-
1. Click the [_Use this template_](https://github.com/JoshuaKGoldberg/template-typescript-node-package/generate) button to create a new repository with the same Git history
60-
2. Open that repository, such as by [cloning it locally](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) or [developing in a codespace](https://docs.github.com/en/codespaces/developing-in-codespaces/developing-in-a-codespace)
61-
3. Create two tokens in [repository secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets):
62-
- `ACCESS_TOKEN`: A [GitHub PAT](https://github.com/settings/tokens/new) with _repo_ and _workflow_ permissions
63-
- `NPM_TOKEN`: An [npm access token](https://docs.npmjs.com/creating-and-viewing-access-tokens/) with _Automation_ permissions
64-
4. `pnpm install`
65-
5. `pnpm run setup` to run the setup script
66-
6. Install the [Codecov GitHub App](https://github.com/marketplace/codecov) and [Renovate GitHub App](https://github.com/marketplace/renovate)
67-
68-
> The setup script removes the `## Explainer`, `## Setup`, and `## Repository Hydration` sections from this README.md.
69-
70-
### Setup Options
71-
72-
The setup script requires four options to fill out repository details.
73-
It will interactively prompt for any that are not provided as a string CLI flag:
74-
75-
1. `repository`: The kebab-case name of the repository (e.g. `template-typescript-node-package`)
76-
2. `title`: Title Case title for the repository to be used in documentation (e.g. `Template TypeScript Node Package`)
77-
3. `owner`: GitHub organization or user the repository is underneath (e.g. `JoshuaKGoldberg`)
78-
4. `description`: Sentence case description of the repository (e.g. `A quickstart-friendly TypeScript package with lots of great repository tooling. ✨`)
79-
80-
Additionally, a `--skip-api` boolean CLI flag may be specified to prevent the setup script from calling to GitHub APIs for repository hydration.
81-
The script normally posts to GitHub APIs to set information such as repository description and branch protections on github.com.
82-
Specifying `--skip-api` prevents those API calls, effectively limiting setup changes to local files in Git.
83-
Doing so can be useful to preview what running setup does.
84-
85-
For example, pre-populating all values and skipping API calls:
86-
87-
```shell
88-
pnpm run setup --repository "testing-repository" --title "Testing Title" --owner "TestingOwner" --description "Test Description" --skip-api
89-
```
90-
91-
> Tip: after running `pnpm run setup` with `--skip-api`, you can always `git add -A; git reset --hard HEAD` to completely reset all changes.
92-
93-
## Repository Hydration
94-
95-
> **Warning**
96-
> Hydration will override many files in your repository.
97-
> You'll want to review each of the changes and make sure nothing important is removed.
98-
99-
Alternately, if you have an existing repository that you'd like to give the files from this repository, you can run `template-typescript-node-package` in a repository to "hydrate" it.
100-
101-
```shell
102-
npx template-typescript-node-package
103-
```
104-
105-
Repository settings will be auto-filled from the repository's files if possible, but can be provided manually as well:
106-
107-
- `author` _(`string`)_: e.g. `"Josh Goldberg"`
108-
- `description` _(`string`)_: e.g. `"A quickstart-friendly TypeScript template with comprehensive formatting, linting, releases, testing, and other great tooling built-in. ✨"`
109-
- `email` _(`string`)_: e.g. `"[email protected]"`
110-
- `funding` _(`string`, optional)_: e.g. `"JoshuaKGoldberg"`
111-
- `owner` _(`string`)_: e.g. `"JoshuaKGoldberg"`
112-
- `repository` _(`string`)_: e.g. `"template-typescript-node-package"`
113-
- `title` _(`string`)_: e.g. `"Template TypeScript Node Package"`
114-
115-
For example, providing a `funding` value different from the `author`:
116-
117-
```shell
118-
npx template-typescript-node-package --funding MyOrganization
119-
```
120-
121-
The hydration script by default will include all the features in this template.
122-
You can disable some of them on the command-line:
123-
124-
- `releases` _(`boolean`)_: Whether to include automated package publishing
125-
- `unitTests` _(`boolean`)_: Whether to include unit tests with code coverage tracking
126-
127-
```shell
128-
npx template-typescript-node-package --releases false --unitTests false
129-
```
130-
131-
You can prevent the hydration script from making network-based changes using either or both of the following CLI flags:
132-
133-
- `--skip-contributors` _(`boolean`)_: Skips detecting existing contributors with [`all-contributors-for-repository`](https://github.com/JoshuaKGoldberg/all-contributors-for-repository)
134-
- `--skip-install` _(`boolean`)_: Skips installing all the new template packages with `pnpm`
135-
- `--skip-setup` _(`boolean`)_: Skips running the setup script at the end of hydration
136-
137-
```shell
138-
npx template-typescript-node-package --skip-install --skip-setup
139-
```
140-
141-
## Usage
142-
143-
```shell
144-
npm i template-typescript-node-package
145-
```
146-
147-
```ts
148-
import { greet } from "template-typescript-node-package";
149-
150-
greet("Hello, world!");
151-
```
152-
15361
## Development
15462

15563
See [`.github/CONTRIBUTING.md`](./.github/CONTRIBUTING.md), then [`.github/DEVELOPMENT.md`](./.github/DEVELOPMENT.md).

bin/hydrate.js

-4
This file was deleted.

bin/migrate.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
import { migrate } from "../lib/migrate/index.js";
3+
4+
process.exitCode = await migrate(process.argv.slice(2));

docs/FAQs.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# FAQs
2+
3+
## Can I use &lt;insert tool here&gt with this template?
4+
5+
Yes!
6+
After you set up a repository, you can substitute in any tools you'd like.
7+
8+
If you think the tool would be broadly useful to most consumers of this template, feel free to [file a feature request](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/new?assignees=&labels=type%3A+feature&projects=&template=03-feature.yml&title=%F0%9F%9A%80+Feature%3A+%3Cshort+description+of+the+feature%3E) to add it in.
9+
10+
## Is there a way to pull in template updates to previously created repositories?
11+
12+
Not yet.
13+
You can always copy & paste them in manually.
14+
15+
See [🚀 Feature: Add a script to sync the tooling updates from forked template repo #498](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/498): it will likely eventually be possible.
16+
17+
## Why does this package include so many tools?
18+
19+
This repository is meant to serve as a starter that includes all the general tooling a modern TypeScript/Node repository could possibly need.
20+
Each of the included tools exists for a good reason and provides real value.
21+
22+
If you don't want to use any particular tool, you can always remove it manually.

0 commit comments

Comments
 (0)