Skip to content

Commit 5ad6a13

Browse files
refactor(shared): ♻︎ add git-remote-origin-url and git-url-parse to getDefaultSettings (#519)
<!-- 👋 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 #518 - [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 - Refactored the getDefaultSettings. - Added the installed packages to uninstallPackages script.
1 parent 89a9bc9 commit 5ad6a13

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@clack/prompts": "^0.6.3",
5050
"@octokit/request-error": "^3.0.3",
5151
"@types/eslint": "^8.37.0",
52+
"@types/git-url-parse": "^9.0.1",
5253
"@types/js-yaml": "^4.0.5",
5354
"@types/prettier": "^2.7.2",
5455
"@typescript-eslint/eslint-plugin": "^5.59.5",
@@ -71,6 +72,8 @@
7172
"eslint-plugin-regexp": "^1.15.0",
7273
"eslint-plugin-vitest": "^0.2.2",
7374
"eslint-plugin-yml": "^1.7.0",
75+
"git-remote-origin-url": "^4.0.0",
76+
"git-url-parse": "^13.1.0",
7477
"globby": "^13.1.4",
7578
"husky": "^8.0.3",
7679
"jsonc-eslint-parser": "^2.3.0",

pnpm-lock.yaml

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup/steps/uninstallPackages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { $ } from "execa";
22

33
export async function uninstallPackages() {
44
await $`pnpm remove chalk execa js-yaml`;
5-
await $`pnpm remove @clack/prompts @octokit/request-error @types/js-yaml @types/prettier all-contributors-cli c8 globby octokit npm-user replace-in-file title-case tsx -D`;
5+
await $`pnpm remove @clack/prompts @octokit/request-error @types/git-url-parse @types/js-yaml @types/prettier all-contributors-cli c8 git-remote-origin-url git-url-parse globby npm-user octokit replace-in-file title-case tsx -D`;
66
}

src/shared/defaults.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import chalk from "chalk";
2-
import { $ } from "execa";
2+
import gitRemoteOriginUrl from "git-remote-origin-url";
3+
import gitUrlParse from "git-url-parse";
34

45
import { logLine } from "./cli/lines.js";
56

67
export async function getDefaultSettings() {
7-
let gitRemoteFetch;
88
try {
9-
// Grep only the origin remote and its fetch URL
10-
gitRemoteFetch = await $`git remote -v`
11-
.pipeStdout?.($({ stdin: "pipe" })`grep origin`)
12-
.pipeStdout?.($({ stdin: "pipe" })`grep fetch`);
9+
const gitRemoteUrl = await gitRemoteOriginUrl();
10+
const { name, owner } = gitUrlParse(gitRemoteUrl);
11+
12+
return { defaultOwner: owner, defaultRepository: name };
1313
} catch {
1414
logLine();
1515
logLine(
@@ -23,15 +23,4 @@ export async function getDefaultSettings() {
2323
defaultRepository: "my-lovely-repository",
2424
};
2525
}
26-
27-
const remoteFetchMatch = gitRemoteFetch?.stdout.match(
28-
/\s.+\/([^/]+)\/([^/]+) \(fetch\)/
29-
);
30-
if (!remoteFetchMatch) {
31-
throw new Error("Could not match a fetch remote from git.");
32-
}
33-
34-
const [, defaultOwner, defaultRepository] = remoteFetchMatch;
35-
36-
return { defaultOwner, defaultRepository };
3726
}

0 commit comments

Comments
 (0)