@@ -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
1923async 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 ( / ^ v u e - / , '' )
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 ( / @ u n s c o p e d P a c k a g e N a m e @ / g, config . unscopedPackageName )
135160 . replace ( / @ g l o b a l V a r i a b l e N a m e @ / g, config . globalVariableName )
136161 . 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 )
137165
138166 fs . writeFileSync ( targetPath , content )
139167 } else {
0 commit comments