@@ -14,13 +14,18 @@ type Config = {
14
14
targetDirName : string
15
15
targetDirPath : string
16
16
templateDirPath : string
17
+ githubPath : string
18
+ githubUrl : string
19
+ githubIssues : string
20
+ githubRepository : string
17
21
}
18
22
19
23
async function init ( ) {
20
24
const cwd = process . cwd ( )
21
25
22
26
let result : {
23
27
packageName ?: string
28
+ githubPath ? : string
24
29
} = { }
25
30
26
31
try {
@@ -31,6 +36,11 @@ async function init() {
31
36
type : 'text' ,
32
37
message : 'Package name' ,
33
38
initial : '@skirtle/test-project'
39
+ } , {
40
+ name : 'githubPath' ,
41
+ type : 'text' ,
42
+ message : 'GitHub path, e.g. skirtles-code/test-project (optional)' ,
43
+ initial : ''
34
44
}
35
45
] ,
36
46
{
@@ -52,12 +62,23 @@ async function init() {
52
62
process . exit ( 1 )
53
63
}
54
64
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
+
55
72
const unscopedPackageName = scopedPackageName . replace ( / .* \/ / , '' )
56
73
const shortUnscopedPackageName = unscopedPackageName . replace ( / ^ v u e - / , '' )
57
74
const projectName = unscopedPackageName . replace ( / - + / g, ' ' ) . trim ( ) . split ( ' ' ) . map ( s => s [ 0 ] . toUpperCase ( ) + s . slice ( 1 ) ) . join ( ' ' )
58
75
const globalVariableName = projectName . replace ( / / g, '' )
59
76
const targetDirName = unscopedPackageName
60
77
78
+ const githubUrl = githubPath ? `https://github.com/${ githubPath } ` : ''
79
+ const githubIssues = githubPath ? `${ githubUrl } /issues` : ''
80
+ const githubRepository = githubPath ? `git+${ githubUrl } .git` : ''
81
+
61
82
const targetDirPath = path . join ( cwd , targetDirName )
62
83
63
84
if ( fs . existsSync ( targetDirPath ) ) {
@@ -77,7 +98,11 @@ async function init() {
77
98
globalVariableName,
78
99
targetDirName,
79
100
targetDirPath,
80
- templateDirPath
101
+ templateDirPath,
102
+ githubPath,
103
+ githubUrl,
104
+ githubIssues,
105
+ githubRepository
81
106
}
82
107
83
108
copyTemplate ( 'base' , config )
@@ -134,6 +159,9 @@ function copyFiles(templateFile: string, config: Config) {
134
159
. replace ( / @ u n s c o p e d P a c k a g e N a m e @ / g, config . unscopedPackageName )
135
160
. replace ( / @ g l o b a l V a r i a b l e N a m e @ / g, config . globalVariableName )
136
161
. replace ( / @ s c o p e d P a c k a g e N a m e @ / g, config . scopedPackageName )
162
+ . replace ( / @ g i t h u b U r l @ / g, config . githubUrl )
163
+ . replace ( / @ g i t h u b I s s u e s @ / g, config . githubIssues )
164
+ . replace ( / @ g i t h u b R e p o s i t o r y @ / g, config . githubRepository )
137
165
138
166
fs . writeFileSync ( targetPath , content )
139
167
} else {
0 commit comments