Skip to content

feat: replace parsePackageAuthor with npm package #904

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 1 commit into from
Oct 8, 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: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"lazy-value": "^3.0.0",
"npm-user": "^5.0.1",
"octokit": "^3.1.0",
"parse-author": "^2.0.0",
"prettier": "^3.0.2",
"replace-in-file": "^7.0.1",
"title-case": "^4.0.0",
Expand All @@ -66,6 +67,7 @@
"@types/git-url-parse": "^9.0.1",
"@types/js-yaml": "^4.0.5",
"@types/node": "^20.5.6",
"@types/parse-author": "^2.0.1",
"@types/prettier": "^2.7.3",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions src/shared/options/createOptionDefaults/parsePackageAuthor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import parse from "parse-author";

import { PartialPackageData } from "../../types.js";

export function parsePackageAuthor(packageData: PartialPackageData) {
const [packageAuthor, packageEmail] =
typeof packageData.author === "string"
? [
packageData.author.split("<")[0].trim(),
packageData.author.split(/<|>/)[1]?.trim(),
]
: [packageData.author?.name, packageData.author?.email];
let packageAuthor: string | undefined;
let packageEmail: string | undefined;

if (typeof packageData.author === "string") {
const parsedAuthor = parse(packageData.author);
packageAuthor = parsedAuthor.name;
packageEmail = parsedAuthor.email;
} else if (packageData.author) {
packageAuthor = packageData.author.name;
packageEmail = packageData.author.email;
}

return {
author: packageAuthor,
Expand Down