Skip to content

Commit 0199d72

Browse files
author
Guillaume Chau
committed
feat(ui): project homepage
1 parent 653cc30 commit 0199d72

File tree

9 files changed

+94
-8
lines changed

9 files changed

+94
-8
lines changed

packages/@vue/cli-ui/apollo-server/connectors/projects.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { defaults } = require('@vue/cli/lib/options')
88
const { toShortPluginId } = require('@vue/cli-shared-utils')
99
const { progress: installProgress } = require('@vue/cli/lib/util/installDeps')
1010
const { clearModule } = require('@vue/cli/lib/util/module')
11+
const parseGitConfig = require('parse-git-config')
1112
// Connectors
1213
const progress = require('./progress')
1314
const cwd = require('./cwd')
@@ -20,6 +21,7 @@ const getContext = require('../context')
2021
// Utils
2122
const { log } = require('../util/logger')
2223
const { notify } = require('../util/notification')
24+
const { getHttpsGitURL } = require('../util/strings')
2325

2426
const PROGRESS_ID = 'project-create'
2527

@@ -414,6 +416,20 @@ function getType (project) {
414416
return !project.type ? 'vue' : project.type
415417
}
416418

419+
function getHomepage (project, context) {
420+
const gitConfigPath = path.join(project.path, '.git', 'config')
421+
if (fs.existsSync(gitConfigPath)) {
422+
const gitConfig = parseGitConfig.sync({ path: gitConfigPath })
423+
const gitRemoteUrl = gitConfig['remote "origin"']
424+
if (gitRemoteUrl) {
425+
return getHttpsGitURL(gitRemoteUrl.url)
426+
}
427+
}
428+
429+
const pkg = folders.readPackage(project.path, context)
430+
return pkg.homepage
431+
}
432+
417433
// Open last project
418434
async function autoOpenLastProject () {
419435
const context = getContext()
@@ -446,5 +462,6 @@ module.exports = {
446462
setFavorite,
447463
initCreator,
448464
removeCreator,
449-
getType
465+
getType,
466+
getHomepage
450467
}

packages/@vue/cli-ui/apollo-server/schema/project.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Project {
3232
favorite: Int
3333
plugins: [Plugin]
3434
tasks: [Task]
35+
homepage: String
3536
}
3637
3738
enum ProjectType {
@@ -82,7 +83,8 @@ exports.resolvers = {
8283
Project: {
8384
type: (project, args, context) => projects.getType(project),
8485
plugins: (project, args, context) => plugins.list(project.path, context),
85-
tasks: (project, args, context) => tasks.list({ file: project.path, api: false }, context)
86+
tasks: (project, args, context) => tasks.list({ file: project.path, api: false }, context),
87+
homepage: (project, args, context) => projects.getHomepage(project, context)
8688
},
8789

8890
Query: {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.getHttpsGitURL = url => {
2+
if (url.startsWith('http')) {
3+
return url.replace('.git', '')
4+
} else if (url.startsWith('git@')) {
5+
return url
6+
.replace(':', '/')
7+
.replace('git@', 'https://')
8+
.replace(/.git([^.git]*)$/, '')
9+
}
10+
return url
11+
}

packages/@vue/cli-ui/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@
149149
},
150150
"top-bar": {
151151
"no-favorites": "No favorite projects",
152-
"favorite-projects": "Favorite projects"
152+
"favorite-projects": "Favorite projects",
153+
"homepage": "Home page"
153154
},
154155
"view-badge": {
155156
"labels": {

packages/@vue/cli-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"lru-cache": "^4.1.2",
4848
"node-ipc": "^9.1.1",
4949
"node-notifier": "^5.2.1",
50+
"parse-git-config": "^2.0.2",
5051
"portfinder": "^1.0.13",
5152
"semver": "^5.5.0",
5253
"shortid": "^2.2.8",
@@ -60,7 +61,7 @@
6061
"@vue/cli-plugin-eslint": "^3.0.0-rc.3",
6162
"@vue/cli-service": "^3.0.0-rc.3",
6263
"@vue/eslint-config-standard": "^3.0.0-rc.3",
63-
"@vue/ui": "^0.4.4",
64+
"@vue/ui": "^0.4.5",
6465
"ansi_up": "^2.0.2",
6566
"cross-env": "^5.1.5",
6667
"eslint": "^4.16.0",

packages/@vue/cli-ui/src/components/ProjectSelectListItem.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
</ListItemInfo>
2626
</div>
2727
<div class="actions">
28+
<VueButton
29+
v-if="project.homepage"
30+
:href="project.homepage"
31+
target="_blank"
32+
class="icon-button"
33+
icon-left="open_in_new"
34+
v-tooltip="project.homepage"
35+
@click.stop
36+
/>
2837
<VueButton
2938
class="icon-button"
3039
icon-left="close"

packages/@vue/cli-ui/src/components/TopBar.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
>
1717
{{ $t('org.vue.components.project-select-list-item.tooltips.favorite') }}
1818
</VueSwitch>
19+
20+
<VueDropdownButton
21+
v-if="projectCurrent.homepage"
22+
:href="projectCurrent.homepage"
23+
:label="$t('org.vue.components.top-bar.homepage')"
24+
target="_blank"
25+
icon-left="open_in_new"
26+
/>
1927
</template>
2028

2129
<div class="dropdown-separator"/>

packages/@vue/cli-ui/src/graphql/projectFragment.gql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ fragment project on Project {
44
type
55
path
66
favorite
7+
homepage
78
}

yarn.lock

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,9 @@
10481048
dependencies:
10491049
lodash "^4.17.4"
10501050

1051-
"@vue/ui@^0.4.4":
1052-
version "0.4.4"
1053-
resolved "https://registry.yarnpkg.com/@vue/ui/-/ui-0.4.4.tgz#47c843f6b1da21e3f919c7668f9e3a49c27bcd80"
1051+
"@vue/ui@^0.4.5":
1052+
version "0.4.5"
1053+
resolved "https://registry.yarnpkg.com/@vue/ui/-/ui-0.4.5.tgz#003334fd98e42ef600e8f3f3fbd98733e9a9fadd"
10541054
dependencies:
10551055
focus-visible "^4.1.4"
10561056
material-design-icons "^3.0.1"
@@ -4656,6 +4656,12 @@ expand-range@^1.8.1:
46564656
dependencies:
46574657
fill-range "^2.1.0"
46584658

4659+
expand-tilde@^2.0.2:
4660+
version "2.0.2"
4661+
resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
4662+
dependencies:
4663+
homedir-polyfill "^1.0.1"
4664+
46594665
expect@^22.4.0:
46604666
version "22.4.3"
46614667
resolved "https://registry.yarnpkg.com/expect/-/expect-22.4.3.tgz#d5a29d0a0e1fb2153557caef2674d4547e914674"
@@ -5149,6 +5155,10 @@ fs-constants@^1.0.0:
51495155
version "1.0.0"
51505156
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
51515157

5158+
fs-exists-sync@^0.1.0:
5159+
version "0.1.0"
5160+
resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add"
5161+
51525162
fs-extra@4.0.1:
51535163
version "4.0.1"
51545164
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.1.tgz#7fc0c6c8957f983f57f306a24e5b9ddd8d0dd880"
@@ -5349,6 +5359,14 @@ git-clone@^0.1.0:
53495359
version "0.1.0"
53505360
resolved "https://registry.yarnpkg.com/git-clone/-/git-clone-0.1.0.tgz#0d76163778093aef7f1c30238f2a9ef3f07a2eb9"
53515361

5362+
git-config-path@^1.0.1:
5363+
version "1.0.1"
5364+
resolved "https://registry.yarnpkg.com/git-config-path/-/git-config-path-1.0.1.tgz#6d33f7ed63db0d0e118131503bab3aca47d54664"
5365+
dependencies:
5366+
extend-shallow "^2.0.1"
5367+
fs-exists-sync "^0.1.0"
5368+
homedir-polyfill "^1.0.0"
5369+
53525370
git-raw-commits@^1.3.0, git-raw-commits@^1.3.6:
53535371
version "1.3.6"
53545372
resolved "https://registry.yarnpkg.com/git-raw-commits/-/git-raw-commits-1.3.6.tgz#27c35a32a67777c1ecd412a239a6c19d71b95aff"
@@ -5824,6 +5842,12 @@ hogan.js@^3.0.2:
58245842
mkdirp "0.3.0"
58255843
nopt "1.0.10"
58265844

5845+
homedir-polyfill@^1.0.0, homedir-polyfill@^1.0.1:
5846+
version "1.0.1"
5847+
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc"
5848+
dependencies:
5849+
parse-passwd "^1.0.0"
5850+
58275851
hosted-git-info@^2.1.4, hosted-git-info@^2.5.0:
58285852
version "2.6.0"
58295853
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.6.0.tgz#23235b29ab230c576aab0d4f13fc046b0b038222"
@@ -6105,7 +6129,7 @@ inherits@2.0.1:
61056129
version "2.0.1"
61066130
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"
61076131

6108-
ini@^1.3.2, ini@^1.3.4, ini@~1.3.0:
6132+
ini@^1.3.2, ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
61096133
version "1.3.5"
61106134
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
61116135

@@ -9213,6 +9237,14 @@ parse-asn1@^5.0.0:
92139237
evp_bytestokey "^1.0.0"
92149238
pbkdf2 "^3.0.3"
92159239

9240+
parse-git-config@^2.0.2:
9241+
version "2.0.2"
9242+
resolved "https://registry.yarnpkg.com/parse-git-config/-/parse-git-config-2.0.2.tgz#9f3154b069aefa747b199cbf95fefd2e749f7b36"
9243+
dependencies:
9244+
expand-tilde "^2.0.2"
9245+
git-config-path "^1.0.1"
9246+
ini "^1.3.5"
9247+
92169248
parse-github-repo-url@^1.3.0:
92179249
version "1.4.1"
92189250
resolved "https://registry.yarnpkg.com/parse-github-repo-url/-/parse-github-repo-url-1.4.1.tgz#9e7d8bb252a6cb6ba42595060b7bf6df3dbc1f50"
@@ -9239,6 +9271,10 @@ parse-json@^4.0.0:
92399271
error-ex "^1.3.1"
92409272
json-parse-better-errors "^1.0.1"
92419273

9274+
parse-passwd@^1.0.0:
9275+
version "1.0.0"
9276+
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
9277+
92429278
parse5@4.0.0:
92439279
version "4.0.0"
92449280
resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608"

0 commit comments

Comments
 (0)