File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -10,21 +10,23 @@ const log = require('../log')
1010const { join, basename } = require ( 'path' )
1111const securityCheck = require ( '../securityCheck' )
1212const getTemplateStorage = require ( '../getTemplateStorage' )
13+ const formatTemplateLink = require ( '../formatTemplateLink' )
1314
1415
1516module . exports = async ( options = { } ) => {
1617 const {
1718 cwd = process . cwd ( ) ,
1819 // project name
1920 name,
20- // template repository
21- repository,
2221 // whether to skip the security check
2322 force = false ,
2423 // template version expected
2524 version,
2625 } = options
2726
27+ // template repository
28+ const repository = formatTemplateLink ( options . repository )
29+ console . log ( repository )
2830 if ( ! force ) await securityCheck ( process . cwd ( ) )
2931
3032 const templateStoragePath = await getTemplateStorage ( repository )
Original file line number Diff line number Diff line change 1+ // github:xx/xx
2+ const throwError = require ( './throwError' )
3+ const githubSH = / ^ ( g i t h u b : ) ? [ - a - z A - Z 0 - 9 @ : % . _ \+ ~ # = ] + \/ [ - a - z A - Z 0 - 9 @ : % . _ \+ ~ # = ] + $ /
4+ const cloneLink = / ( ( g i t | s s h | h t t p ( s ) ? ) | ( g i t @ [ \w . ] + ) ) ( : ( \/ \/ ) ? ) ( [ \w . @ : / \- ~ ] + ) ( \. g i t ) ( \/ ) ? /
5+
6+ module . exports = link => {
7+ if ( githubSH . test ( link ) ) {
8+ return `https://github.com/${ link . replace ( / ^ g i t h u b : / , '' ) } .git`
9+ } else if ( cloneLink . test ( link ) ) {
10+ return link
11+ }
12+
13+ throwError ( `Invalid repository url: ${ link } ` )
14+ }
You can’t perform that action at this time.
0 commit comments