Skip to content
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

🚀 Feature: Infer --base from existing package.json scripts during migration #933

Closed
3 tasks done
JoshuaKGoldberg opened this issue Oct 2, 2023 · 4 comments · Fixed by #993
Closed
3 tasks done
Labels
status: accepting prs Please, send a pull request to resolve this! type: feature New enhancement or request

Comments

@JoshuaKGoldberg
Copy link
Owner

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Overview

Right now, if you run npx create-typescript-app in an existing repository made from the template, you always get the standard mode selection:

◆  How much tooling would you like the template to set up for you?
│  ○ everything  The most comprehensive tooling imaginable: sorting, spellchecking, and more!
│  ● common      Bare starters plus testing and automation for all-contributors and releases. (recommended)
│  ○ minimum     Just bare starter tooling: building, formatting, linting, and type checking.
│  ○ prompt      (allow me to customize)
└

But as a convenience, we could set a default value for this based on package.json's scripts. Let's say:

  1. If >=3 of the scripts listed under the everything base exist, set the initial value to everything
  2. If >=2 of the scripts listed under the common base exist, set the initial value to common

Additional Info

No response

@JoshuaKGoldberg JoshuaKGoldberg added type: feature New enhancement or request status: accepting prs Please, send a pull request to resolve this! labels Oct 2, 2023
@GV14982
Copy link
Contributor

GV14982 commented Oct 27, 2023

I'd like to take this, but I'm not quite understanding the potential solution. Could you give me an example please?

@JoshuaKGoldberg
Copy link
Owner Author

Absolutely - thanks for asking!

Suppose npx create-typescript-app --mode migrate (or, if running from a local build, node path/to/create-typescript-app/bin/index.js --mode migrate) is run in a directory that includes a package.json with the following "scripts":

{
	"scripts": {
		"build": "tsup",
		"format": "prettier \"**/*\" --ignore-unknown",
		"initialize": "tsx ./src/bin/index.js --mode initialize",
		"lint": "eslint . .*js --max-warnings 0",
		"lint:knip": "knip",
		"lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line",
		"lint:package-json": "npmPkgJsonLint .",
		"lint:packages": "pnpm dedupe --check",
		"lint:spelling": "cspell \"**\" \".github/**/*\"",
		"prepare": "husky install",
		"should-semantic-release": "should-semantic-release --verbose",
		"test": "vitest",
		"tsc": "tsc"
	}
}

The migration script could infer that the repo is probably using the "everything" base (https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/docs/Options.md#base-and-mode). In that case it shouldn't need to ask for which base to use:

const base =
options.base ??
filterPromptCancel<OptionsBase | symbol>(
await prompts.select({
initialValue: "common" as OptionsBase,
message: `How much tooling would you like the template to set up for you?`,

Does that answer what you're looking for?

@GV14982
Copy link
Contributor

GV14982 commented Oct 28, 2023

Ah yeah, that makes sense! Thanks for the explainer :)

JoshuaKGoldberg added a commit that referenced this issue Oct 31, 2023
<!-- 👋 Hi, thanks for sending a PR to create-typescript-app! 💖.
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 #933
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Add a naive solution for checking the existing `package.json` during
migration to infer the base.

🐸

---------

Co-authored-by: Josh Goldberg <[email protected]>
@github-actions
Copy link

🎉 This is included in version v1.42.0 🎉

The release is available on:

Cheers! 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: feature New enhancement or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants