Skip to content

Commit 3ee3b37

Browse files
committed
Use GitHub Pages for homepage in package.json
1 parent d7e0ca1 commit 3ee3b37

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Config = {
2020
githubRepository: string
2121
githubPagesOrigin: string
2222
docsBase: string
23+
homepageUrl: string
2324
includeDocs: boolean
2425
includeGithubPages: boolean
2526
includePlayground: boolean
@@ -119,6 +120,7 @@ async function init() {
119120
const githubRepository = githubPath ? `git+${githubUrl}.git` : ''
120121
const githubPagesOrigin = githubUserName && result.includeGithubPages ? `https://${githubUserName}.github.io` : ''
121122
const docsBase = githubRepoName && result.includeGithubPages ? `/${githubRepoName}/` : '/'
123+
const homepageUrl = githubPagesOrigin && result.includeGithubPages ? `${githubPagesOrigin}${docsBase}` : githubUrl
122124

123125
const targetDirPath = path.join(cwd, targetDirName)
124126

@@ -146,6 +148,7 @@ async function init() {
146148
githubRepository,
147149
githubPagesOrigin,
148150
docsBase,
151+
homepageUrl,
149152
includeDocs: result.includeDocs,
150153
includeGithubPages: !!result.includeGithubPages,
151154
includePlayground: result.includePlayground,
@@ -227,12 +230,7 @@ function copyFiles(templateFile: string, config: Config) {
227230
const template = fs.readFileSync(templatePath, 'utf-8')
228231
const content = template
229232
.replace(/@projectName@/g, config.shortUnscopedPackageName)
230-
.replace(/@unscopedPackageName@/g, config.unscopedPackageName)
231-
.replace(/@globalVariableName@/g, config.globalVariableName)
232-
.replace(/@scopedPackageName@/g, config.scopedPackageName)
233-
.replace(/@githubUrl@/g, config.githubUrl)
234-
.replace(/@githubIssues@/g, config.githubIssues)
235-
.replace(/@githubRepository@/g, config.githubRepository)
233+
.replace(new RegExp(`@(${Object.keys(config).join('|')})@`, 'g'), (all, setting) => config[setting] ?? all)
236234

237235
fs.writeFileSync(targetPath, content)
238236
} else {

src/template/base/config/packages/@projectName@/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "",
77
"description": "",
88
"keywords": [],
9-
"homepage": "@githubUrl@",
9+
"homepage": "@homepageUrl@",
1010
"bugs": "@githubIssues@",
1111
"repository": {
1212
"type": "git",

0 commit comments

Comments
 (0)