Skip to content

Commit 791332d

Browse files
feat: add hydration script for existing repos (#441)
## PR Checklist - [x] Addresses an existing open issue: fixes #374 - [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 Adds the script as a `bin` command you can run with `npx template-typescript-node-package`. Which bumps up a few dependencies from `devDependency` to `dependency`. This has the nice side effect of standardizing formatting for an assortment of files. Hence the large _Files changed_ count outside of the new `src/hydrate/` directory. Things I've intentionally not done here, so they can be filed as followup issues: * Filling in unit test coverage * Running [`all-contributors-for-repository`](https://github.com/JoshuaKGoldberg/all-contributors-for-repository) to fill in the `.all-contributorsrc` * Removing existing image badges from the README.md * Removing existing `CODE_OF_CONDUCT.md` * Use the GitHub API to set up labels and other repo settings * Run `pnpm run lint --fix` * CLI flag for hydration to just refresh files locally * Getting hydration to the point where it doesn't make changes in this repo _(is that possible?)_ * A copy&pastable script to run in a repo to update it to the latest tooling (migrations?!)
1 parent 3ee08b7 commit 791332d

Some content is hidden

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

62 files changed

+2507
-111
lines changed

.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ module.exports = {
7979
},
8080
},
8181
{
82+
extends: ["plugin:yml/standard", "plugin:yml/prettier"],
8283
files: ["**/*.{yml,yaml}"],
8384
parser: "yaml-eslint-parser",
84-
extends: ["plugin:yml/standard", "plugin:yml/prettier"],
8585
rules: {
8686
"yml/file-extension": ["error", { extension: "yml" }],
8787
"yml/sort-keys": [

.github/CODE_OF_CONDUCT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ representative at an online or offline event.
6060

6161
Instances of abusive, harassing, or otherwise unacceptable behavior may be
6262
reported to the community leaders responsible for enforcement at
63-
git@joshuakgoldberg.com.
63+
npm@joshuakgoldberg.com.
6464
All complaints will be reviewed and investigated promptly and fairly.
6565

6666
All community leaders are obligated to respect the privacy and security of the

.github/DEVELOPMENT.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,38 @@ Calls to `console.log`, `console.warn`, and other console methods will cause a t
6767
This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests.
6868
To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5).
6969

70+
## The Hydration Script
71+
72+
This template's "hydration" script is located in `src/hydrate/`.
73+
It needs to be [built](#building) before it can be run.
74+
75+
Be warned that running the hydration script in a repository -including this one- will modify that repository.
76+
To test out the script, you may want to create a new test repository to run on:
77+
78+
```shell
79+
cd ..
80+
mkdir temp
81+
cd temp
82+
echo node_modules > .gitignore
83+
git init
84+
npm init --yes
85+
```
86+
87+
Then, in that directory, you can directly call the hydration script:
88+
89+
```shell
90+
node ../template-typescript-node-package -- description "Hooray, trying things out locally."
91+
```
92+
93+
Along with the hydration script itself, end-to-end tests are removed on package setup.
94+
95+
## The Setup Script
96+
97+
This template's "setup" script is located in `script/`.
98+
7099
### Testing the Setup Script
71100

72-
In addition to unit tests, this template also includes an "end-to-end" test for `script/setup.js`.
101+
This template source includes an "end-to-end" test for `script/setup.js`.
73102
You can run it locally on the command-line:
74103

75104
```shell
@@ -81,4 +110,4 @@ That end-to-end test executes `script/setup-test-e2e.js`, which:
81110
1. Runs the setup script using `--skip-api`
82111
2. Checks that the local repository's files were changed correctly (e.g. removed setup-only files)
83112

84-
As with the setup script itself, end-to-end tests are removed on package setup.
113+
Along with the setup script itself, end-to-end tests are removed on package setup.

.github/actions/prepare/action.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
description: Prepares the repo for a typical CI job
22

33
name: Prepare
4+
45
runs:
56
steps:
67
- uses: pnpm/action-setup@v2

.github/workflows/build.yml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ name: Build
1111

1212
on:
1313
pull_request: ~
14-
1514
push:
1615
branches:
1716
- main

.github/workflows/compliance.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
- uses: mtfoley/pr-compliance-action@main
66
with:
77
body-auto-close: false
8-
ignore-authors: |
8+
ignore-authors: |-
99
allcontributors
1010
allcontributors[bot]
1111
renovate

.github/workflows/hydrate.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
jobs:
2+
hydrate:
3+
runs-on: ubuntu-latest
4+
steps:
5+
- uses: actions/checkout@v3
6+
- uses: ./.github/actions/prepare
7+
- run: pnpm run build
8+
- run: pnpm run setup:test
9+
10+
name: Test Hydrate Script
11+
12+
on:
13+
pull_request: ~
14+
15+
push:
16+
branches:
17+
- main

.github/workflows/knip.yml renamed to .github/workflows/lint-knip.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
jobs:
2-
knip:
2+
lint_knip:
33
runs-on: ubuntu-latest
44
steps:
55
- uses: actions/checkout@v3
@@ -10,7 +10,6 @@ name: Lint Knip
1010

1111
on:
1212
pull_request: ~
13-
1413
push:
1514
branches:
1615
- main

.github/workflows/markdown.yml renamed to .github/workflows/lint-markdown.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
jobs:
2-
markdown:
2+
lint_markdown:
33
runs-on: ubuntu-latest
44
steps:
55
- uses: actions/checkout@v3
@@ -10,7 +10,6 @@ name: Lint Markdown
1010

1111
on:
1212
pull_request: ~
13-
1413
push:
1514
branches:
1615
- main

.github/workflows/package.yml renamed to .github/workflows/lint-package.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
jobs:
2-
package:
2+
lint_package:
33
runs-on: ubuntu-latest
44
steps:
55
- uses: actions/checkout@v3
@@ -10,7 +10,6 @@ name: Lint Package
1010

1111
on:
1212
pull_request: ~
13-
1413
push:
1514
branches:
1615
- main
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
jobs:
2-
spelling:
2+
lint_spelling:
33
runs-on: ubuntu-latest
44
steps:
55
- uses: actions/checkout@v3
66
- uses: ./.github/actions/prepare
77
- run: pnpm lint:spelling
88

9-
name: Lint Spelling
9+
name: Lint spelling
1010

1111
on:
1212
pull_request: ~
13-
1413
push:
1514
branches:
1615
- main

.github/workflows/lint.yml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ name: Lint
1010

1111
on:
1212
pull_request: ~
13-
1413
push:
1514
branches:
1615
- main

.github/workflows/post-release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
jobs:
22
post_release:
3-
name: Comment on relevant PRs and issues
43
runs-on: ubuntu-latest
54
steps:
65
- uses: actions/checkout@v3
@@ -24,5 +23,6 @@ name: Post Release
2423

2524
on:
2625
release:
27-
types: [published]
26+
types:
27+
- published
2828
workflow_dispatch: ~

.github/workflows/prettier.yml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ name: Prettier
1010

1111
on:
1212
pull_request: ~
13-
1413
push:
1514
branches:
1615
- main

.github/workflows/release.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ jobs:
4242
uses: actions/[email protected]
4343
with:
4444
github-token: ${{ secrets.ACCESS_TOKEN }}
45-
# Note: keep this inline script in sync with script/setup.js!
46-
# Todo: it would be nice to not have two sources of truth...
47-
# https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/145
4845
script: |
4946
github.request(
5047
`PUT /repos/JoshuaKGoldberg/template-typescript-node-package/branches/main/protection`,
@@ -65,13 +62,13 @@ jobs:
6562
checks: [
6663
{ context: "build" },
6764
{ context: "compliance" },
68-
{ context: "knip" },
6965
{ context: "lint" },
70-
{ context: "markdown" },
71-
{ context: "package" },
72-
{ context: "packages" },
66+
{ context: "lint_knip" },
67+
{ context: "lint_markdown" },
68+
{ context: "lint_package" },
69+
{ context: "lint_packages" },
70+
{ context: "lint_spelling" },
7371
{ context: "prettier" },
74-
{ context: "spelling" },
7572
{ context: "test" },
7673
],
7774
strict: false,

.github/workflows/test.yml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ name: Test
1414

1515
on:
1616
pull_request: ~
17-
1817
push:
1918
branches:
2019
- main

.husky/pre-commit

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
3-
43
npx lint-staged

.npmpackagejsonlintrc.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
22
"extends": "npm-package-json-lint-config-default",
3-
"rules": {
4-
"require-description": "error",
5-
"require-license": "error"
6-
}
3+
"rules": { "require-description": "error", "require-license": "error" }
74
}

.prettierrc

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
"$schema": "http://json.schemastore.org/prettierrc",
33
"plugins": ["prettier-plugin-packagejson"],
44
"overrides": [
5-
{
6-
"files": ".*rc",
7-
"options": { "parser": "json" }
8-
},
9-
{
10-
"files": ".nvmrc",
11-
"options": { "parser": "yaml" }
12-
}
5+
{ "files": ".*rc", "options": { "parser": "json" } },
6+
{ "files": ".nvmrc", "options": { "parser": "yaml" } }
137
],
148
"useTabs": true
159
}

.vscode/settings.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"editor.codeActionsOnSave": {
3-
"source.fixAll.eslint": true
4-
},
2+
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },
53
"editor.defaultFormatter": "esbenp.prettier-vscode",
64
"editor.formatOnSave": true,
75
"editor.rulers": [80],

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,44 @@ pnpm run setup --repository "testing-repository" --title "Testing Title" --owner
8989

9090
> Tip: after running `pnpm run setup` with `--skip-api`, you can always `git add -A; git reset --hard HEAD` to completely reset all changes.
9191
92+
## Repository Hydration
93+
94+
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.
95+
96+
```shell
97+
npx template-typescript-node-package
98+
```
99+
100+
Repository settings will be auto-filled from the repository's files if possible, but can be provided manually as well:
101+
102+
- `author` _(`string`)_: e.g. `"Josh Goldberg"`
103+
- `description` _(`string`)_: e.g. `"A quickstart-friendly TypeScript template with comprehensive formatting, linting, releases, testing, and other great tooling built-in. ✨"`
104+
- `email` _(`string`)_: e.g. `"[email protected]"`
105+
- `funding` _(`string`, optional)_: e.g. `"JoshuaKGoldberg"`
106+
- `owner` _(`string`)_: e.g. `"JoshuaKGoldberg"`
107+
- `repository` _(`string`)_: e.g. `"template-typescript-node-package"`
108+
- `title` _(`string`)_: e.g. `"Template TypeScript Node Package"`
109+
110+
For example, providing a `funding` value different from the `author`:
111+
112+
```shell
113+
npx template-typescript-node-package --funding MyOrganization
114+
```
115+
116+
The hydration script by default will include all the features in this template.
117+
You can disable some of them on the command-line:
118+
119+
- `releases` _(`boolean`)_: Whether to include automated package publishing
120+
- `unitTests` _(`boolean`)_: Whether to include unit tests with code coverage tracking
121+
122+
```shell
123+
npx template-typescript-node-package --releases false --unitTests false
124+
```
125+
126+
> **Warning**
127+
> This will override many files in your repository.
128+
> You'll want to review each of the changes and make sure nothing important is removed.
129+
92130
## Usage
93131

94132
```shell

cspell.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
"commitlint",
1616
"contributorsrc",
1717
"conventionalcommits",
18-
"infile",
18+
"execa",
1919
"knip",
2020
"lcov",
21+
"markdownlintignore",
22+
"npmpackagejsonlintrc",
23+
"outro",
2124
"packagejson",
25+
"Unstaged",
2226
"quickstart",
23-
"wontfix",
24-
"outro",
25-
"execa"
27+
"wontfix"
2628
]
2729
}

knip.jsonc

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"$schema": "https://unpkg.com/knip@next/schema.json",
3-
"entry": ["src/index.ts!", "script/setup*.js"],
3+
"entry": [
4+
"src/index.ts!",
5+
"src/hydrate/index.ts",
6+
"script/*e2e.js",
7+
"script/setup*.js"
8+
],
49
"ignoreBinaries": ["dedupe", "gh"],
510
"project": ["src/**/*.ts!", "script/**/*.js"]
611
}

0 commit comments

Comments
 (0)