Skip to content

feat: add hydration script for existing repos #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ module.exports = {
},
},
{
extends: ["plugin:yml/standard", "plugin:yml/prettier"],
files: ["**/*.{yml,yaml}"],
parser: "yaml-eslint-parser",
extends: ["plugin:yml/standard", "plugin:yml/prettier"],
rules: {
"yml/file-extension": ["error", { extension: "yml" }],
"yml/sort-keys": [
Expand Down
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ representative at an online or offline event.

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

All community leaders are obligated to respect the privacy and security of the
Expand Down
33 changes: 31 additions & 2 deletions .github/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,38 @@ Calls to `console.log`, `console.warn`, and other console methods will cause a t
This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests.
To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5).

## The Hydration Script

This template's "hydration" script is located in `src/hydrate/`.
It needs to be [built](#building) before it can be run.

Be warned that running the hydration script in a repository -including this one- will modify that repository.
To test out the script, you may want to create a new test repository to run on:

```shell
cd ..
mkdir temp
cd temp
echo node_modules > .gitignore
git init
npm init --yes
```

Then, in that directory, you can directly call the hydration script:

```shell
node ../template-typescript-node-package -- description "Hooray, trying things out locally."
```

Along with the hydration script itself, end-to-end tests are removed on package setup.

## The Setup Script

This template's "setup" script is located in `script/`.

### Testing the Setup Script

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

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

As with the setup script itself, end-to-end tests are removed on package setup.
Along with the setup script itself, end-to-end tests are removed on package setup.
1 change: 1 addition & 0 deletions .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
description: Prepares the repo for a typical CI job

name: Prepare

runs:
steps:
- uses: pnpm/action-setup@v2
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ name: Build

on:
pull_request: ~

push:
branches:
- main
2 changes: 1 addition & 1 deletion .github/workflows/compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
- uses: mtfoley/pr-compliance-action@main
with:
body-auto-close: false
ignore-authors: |
ignore-authors: |-
allcontributors
allcontributors[bot]
renovate
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/hydrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
jobs:
hydrate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/prepare
- run: pnpm run build
- run: pnpm run setup:test

name: Test Hydrate Script

on:
pull_request: ~

push:
branches:
- main
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jobs:
knip:
lint_knip:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -10,7 +10,6 @@ name: Lint Knip

on:
pull_request: ~

push:
branches:
- main
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jobs:
markdown:
lint_markdown:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -10,7 +10,6 @@ name: Lint Markdown

on:
pull_request: ~

push:
branches:
- main
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jobs:
package:
lint_package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -10,7 +10,6 @@ name: Lint Package

on:
pull_request: ~

push:
branches:
- main
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
jobs:
spelling:
lint_spelling:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/prepare
- run: pnpm lint:spelling

name: Lint Spelling
name: Lint spelling

on:
pull_request: ~

push:
branches:
- main
1 change: 0 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ name: Lint

on:
pull_request: ~

push:
branches:
- main
4 changes: 2 additions & 2 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
jobs:
post_release:
name: Comment on relevant PRs and issues
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -24,5 +23,6 @@ name: Post Release

on:
release:
types: [published]
types:
- published
workflow_dispatch: ~
1 change: 0 additions & 1 deletion .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ name: Prettier

on:
pull_request: ~

push:
branches:
- main
13 changes: 5 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ jobs:
uses: actions/[email protected]
with:
github-token: ${{ secrets.ACCESS_TOKEN }}
# Note: keep this inline script in sync with script/setup.js!
# Todo: it would be nice to not have two sources of truth...
# https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/145
script: |
github.request(
`PUT /repos/JoshuaKGoldberg/template-typescript-node-package/branches/main/protection`,
Expand All @@ -65,13 +62,13 @@ jobs:
checks: [
{ context: "build" },
{ context: "compliance" },
{ context: "knip" },
{ context: "lint" },
{ context: "markdown" },
{ context: "package" },
{ context: "packages" },
{ context: "lint_knip" },
{ context: "lint_markdown" },
{ context: "lint_package" },
{ context: "lint_packages" },
{ context: "lint_spelling" },
{ context: "prettier" },
{ context: "spelling" },
{ context: "test" },
],
strict: false,
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ name: Test

on:
pull_request: ~

push:
branches:
- main
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
5 changes: 1 addition & 4 deletions .npmpackagejsonlintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": "npm-package-json-lint-config-default",
"rules": {
"require-description": "error",
"require-license": "error"
}
"rules": { "require-description": "error", "require-license": "error" }
}
10 changes: 2 additions & 8 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
"$schema": "http://json.schemastore.org/prettierrc",
"plugins": ["prettier-plugin-packagejson"],
"overrides": [
{
"files": ".*rc",
"options": { "parser": "json" }
},
{
"files": ".nvmrc",
"options": { "parser": "yaml" }
}
{ "files": ".*rc", "options": { "parser": "json" } },
{ "files": ".nvmrc", "options": { "parser": "yaml" } }
],
"useTabs": true
}
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.rulers": [80],
Expand Down
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,44 @@ pnpm run setup --repository "testing-repository" --title "Testing Title" --owner

> Tip: after running `pnpm run setup` with `--skip-api`, you can always `git add -A; git reset --hard HEAD` to completely reset all changes.

## Repository Hydration

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.

```shell
npx template-typescript-node-package
```

Repository settings will be auto-filled from the repository's files if possible, but can be provided manually as well:

- `author` _(`string`)_: e.g. `"Josh Goldberg"`
- `description` _(`string`)_: e.g. `"A quickstart-friendly TypeScript template with comprehensive formatting, linting, releases, testing, and other great tooling built-in. ✨"`
- `email` _(`string`)_: e.g. `"[email protected]"`
- `funding` _(`string`, optional)_: e.g. `"JoshuaKGoldberg"`
- `owner` _(`string`)_: e.g. `"JoshuaKGoldberg"`
- `repository` _(`string`)_: e.g. `"template-typescript-node-package"`
- `title` _(`string`)_: e.g. `"Template TypeScript Node Package"`

For example, providing a `funding` value different from the `author`:

```shell
npx template-typescript-node-package --funding MyOrganization
```

The hydration script by default will include all the features in this template.
You can disable some of them on the command-line:

- `releases` _(`boolean`)_: Whether to include automated package publishing
- `unitTests` _(`boolean`)_: Whether to include unit tests with code coverage tracking

```shell
npx template-typescript-node-package --releases false --unitTests false
```

> **Warning**
> This will override many files in your repository.
> You'll want to review each of the changes and make sure nothing important is removed.

## Usage

```shell
Expand Down
10 changes: 6 additions & 4 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"commitlint",
"contributorsrc",
"conventionalcommits",
"infile",
"execa",
"knip",
"lcov",
"markdownlintignore",
"npmpackagejsonlintrc",
"outro",
"packagejson",
"Unstaged",
"quickstart",
"wontfix",
"outro",
"execa"
"wontfix"
]
}
7 changes: 6 additions & 1 deletion knip.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"$schema": "https://unpkg.com/knip@next/schema.json",
"entry": ["src/index.ts!", "script/setup*.js"],
"entry": [
"src/index.ts!",
"src/hydrate/index.ts",
"script/*e2e.js",
"script/setup*.js"
],
"ignoreBinaries": ["dedupe", "gh"],
"project": ["src/**/*.ts!", "script/**/*.js"]
}
Loading