Skip to content

Commit 70f20f8

Browse files
committed
Add a prompt for GitHub repo
1 parent c9bed95 commit 70f20f8

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

src/index.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ type Config = {
1414
targetDirName: string
1515
targetDirPath: string
1616
templateDirPath: string
17+
githubPath: string
18+
githubUrl: string
19+
githubIssues: string
20+
githubRepository: string
1721
}
1822

1923
async function init() {
2024
const cwd = process.cwd()
2125

2226
let result: {
2327
packageName?: string
28+
githubPath?: string
2429
} = {}
2530

2631
try {
@@ -31,6 +36,11 @@ async function init() {
3136
type: 'text',
3237
message: 'Package name',
3338
initial: '@skirtle/test-project'
39+
}, {
40+
name: 'githubPath',
41+
type: 'text',
42+
message: 'GitHub path, e.g. skirtles-code/test-project (optional)',
43+
initial: ''
3444
}
3545
],
3646
{
@@ -52,12 +62,23 @@ async function init() {
5262
process.exit(1)
5363
}
5464

65+
const githubPath = result.githubPath
66+
67+
if (githubPath && !/[\w-]+\/[\w-]+/.test(githubPath)) {
68+
console.log('Invalid GitHub path: ' + githubPath)
69+
process.exit(1)
70+
}
71+
5572
const unscopedPackageName = scopedPackageName.replace(/.*\//, '')
5673
const shortUnscopedPackageName = unscopedPackageName.replace(/^vue-/, '')
5774
const projectName = unscopedPackageName.replace(/-+/g, ' ').trim().split(' ').map(s => s[0].toUpperCase() + s.slice(1)).join(' ')
5875
const globalVariableName = projectName.replace(/ /g, '')
5976
const targetDirName = unscopedPackageName
6077

78+
const githubUrl = githubPath ? `https://github.com/${githubPath}` : ''
79+
const githubIssues = githubPath ? `${githubUrl}/issues` : ''
80+
const githubRepository = githubPath ? `git+${githubUrl}.git` : ''
81+
6182
const targetDirPath = path.join(cwd, targetDirName)
6283

6384
if (fs.existsSync(targetDirPath)) {
@@ -77,7 +98,11 @@ async function init() {
7798
globalVariableName,
7899
targetDirName,
79100
targetDirPath,
80-
templateDirPath
101+
templateDirPath,
102+
githubPath,
103+
githubUrl,
104+
githubIssues,
105+
githubRepository
81106
}
82107

83108
copyTemplate('base', config)
@@ -134,6 +159,9 @@ function copyFiles(templateFile: string, config: Config) {
134159
.replace(/@unscopedPackageName@/g, config.unscopedPackageName)
135160
.replace(/@globalVariableName@/g, config.globalVariableName)
136161
.replace(/@scopedPackageName@/g, config.scopedPackageName)
162+
.replace(/@githubUrl@/g, config.githubUrl)
163+
.replace(/@githubIssues@/g, config.githubIssues)
164+
.replace(/@githubRepository@/g, config.githubRepository)
137165

138166
fs.writeFileSync(targetPath, content)
139167
} else {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
"license": "",
77
"description": "",
88
"keywords": [],
9-
"homepage": "",
10-
"bugs": "",
11-
"repository": "",
9+
"homepage": "@githubUrl@",
10+
"bugs": "@githubIssues@",
11+
"repository": {
12+
"type": "git",
13+
"url": "@githubRepository@"
14+
},
1215
"sideEffects": false,
1316
"main": "dist/@[email protected]",
1417
"module": "dist/@[email protected]",

src/template/base/packages/docs/.vitepress/config.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export default ({ mode }: { mode: string }) => defineConfigWithTheme({
5555
{ text: 'Guide', link: '/introduction' }
5656
],
5757

58-
// socialLinks: [
59-
// { icon: 'github', link: 'https://github.com/' }
60-
// ],
58+
socialLinks: [
59+
{ icon: 'github', link: '@githubUrl@' }
60+
],
6161

6262
sidebar: [
6363
{

0 commit comments

Comments
 (0)