Skip to content

Commit e15c844

Browse files
committed
fix: relative path will be saved as absolute path in .milirc
resolve #48
1 parent 5437fcf commit e15c844

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/apply-template/generate-milirc/template.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mili:
22
version: {{mili.version}}
33
template:
4-
repository: {{{template.repository.url}}}
4+
repository: {{{template.repository.path}}}
55
version: {{template.version.number}}
66
interaction: {{template.interactionSHA1}}
77
answers:

src/utils/format-repository.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ const formatRepository = repository => {
1414
const matched = repository.match(gitUrlRegexp)
1515
const [, , , , , , , links] = matched
1616
const [owner, name] = links.split('/').slice(-2)
17-
return { type: 'git', service: 'github', url: repository, owner, name }
17+
return { type: 'git', service: 'github', url: repository, owner, name, path: repository }
1818
}
1919

20-
return { type: 'git', service: 'unknow', url: repository, owner: null, name: null }
21-
} else if (isAbsolute(repository)) {
22-
return { type: 'local', url: repository, owner: null, name: null }
20+
return { type: 'git', service: 'unknow', url: repository, owner: null, name: null, path: repository }
2321
}
2422

25-
return { type: 'unknow', url: repository ,owner: null, name: null }
23+
return { type: 'unknow', url: repository ,owner: null, name: null, path: repository }
2624
}
2725

2826

@@ -38,11 +36,16 @@ const dirExist = async link => {
3836

3937
module.exports = (link) => {
4038
const cwd = process.cwd()
39+
4140
if (isRelative(link) || isAbsolute(link)) {
42-
if (isAbsolute(link) && dirExist(link)) return formatRepository(link)
41+
if (isAbsolute(link) && dirExist(link)) {
42+
return { type: 'local', url: link, owner: null, name: null, path: link }
43+
}
4344

44-
link = join(cwd, link)
45-
if (dirExist(link)) return formatRepository(link)
45+
const url = join(cwd, link)
46+
if (dirExist(url)) {
47+
return { type: 'local', url, owner: null, name: null, path: link }
48+
}
4649

4750
throwError('Template path cannot be found. Ensure it is an exist directory.')
4851
} else if (githubSH.test(link)) {

0 commit comments

Comments
 (0)