Skip to content

Commit 35cb74b

Browse files
committed
feat(init): shorthand for the github repository uri
1 parent d369d04 commit 35cb74b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/commands/init.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ const log = require('../log')
1010
const { join, basename } = require('path')
1111
const securityCheck = require('../securityCheck')
1212
const getTemplateStorage = require('../getTemplateStorage')
13+
const formatTemplateLink = require('../formatTemplateLink')
1314

1415

1516
module.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)

src/formatTemplateLink.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// github:xx/xx
2+
const throwError = require('./throwError')
3+
const githubSH = /^(github:)?[-a-zA-Z0-9@:%._\+~#=]+\/[-a-zA-Z0-9@:%._\+~#=]+$/
4+
const cloneLink = /((git|ssh|http(s)?)|(git@[\w.]+))(:(\/\/)?)([\w.@:/\-~]+)(\.git)(\/)?/
5+
6+
module.exports = link => {
7+
if (githubSH.test(link)) {
8+
return `https://github.com/${link.replace(/^github:/, '')}.git`
9+
} else if (cloneLink.test(link)) {
10+
return link
11+
}
12+
13+
throwError(`Invalid repository url: ${link}`)
14+
}

0 commit comments

Comments
 (0)