Skip to content

Commit

Permalink
feat(ui): project homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jul 1, 2018
1 parent 653cc30 commit 0199d72
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 8 deletions.
19 changes: 18 additions & 1 deletion packages/@vue/cli-ui/apollo-server/connectors/projects.js
Expand Up @@ -8,6 +8,7 @@ const { defaults } = require('@vue/cli/lib/options')
const { toShortPluginId } = require('@vue/cli-shared-utils')
const { progress: installProgress } = require('@vue/cli/lib/util/installDeps')
const { clearModule } = require('@vue/cli/lib/util/module')
const parseGitConfig = require('parse-git-config')
// Connectors
const progress = require('./progress')
const cwd = require('./cwd')
Expand All @@ -20,6 +21,7 @@ const getContext = require('../context')
// Utils
const { log } = require('../util/logger')
const { notify } = require('../util/notification')
const { getHttpsGitURL } = require('../util/strings')

const PROGRESS_ID = 'project-create'

Expand Down Expand Up @@ -414,6 +416,20 @@ function getType (project) {
return !project.type ? 'vue' : project.type
}

function getHomepage (project, context) {
const gitConfigPath = path.join(project.path, '.git', 'config')
if (fs.existsSync(gitConfigPath)) {
const gitConfig = parseGitConfig.sync({ path: gitConfigPath })
const gitRemoteUrl = gitConfig['remote "origin"']
if (gitRemoteUrl) {
return getHttpsGitURL(gitRemoteUrl.url)
}
}

const pkg = folders.readPackage(project.path, context)
return pkg.homepage
}

// Open last project
async function autoOpenLastProject () {
const context = getContext()
Expand Down Expand Up @@ -446,5 +462,6 @@ module.exports = {
setFavorite,
initCreator,
removeCreator,
getType
getType,
getHomepage
}
4 changes: 3 additions & 1 deletion packages/@vue/cli-ui/apollo-server/schema/project.js
Expand Up @@ -32,6 +32,7 @@ type Project {
favorite: Int
plugins: [Plugin]
tasks: [Task]
homepage: String
}
enum ProjectType {
Expand Down Expand Up @@ -82,7 +83,8 @@ exports.resolvers = {
Project: {
type: (project, args, context) => projects.getType(project),
plugins: (project, args, context) => plugins.list(project.path, context),
tasks: (project, args, context) => tasks.list({ file: project.path, api: false }, context)
tasks: (project, args, context) => tasks.list({ file: project.path, api: false }, context),
homepage: (project, args, context) => projects.getHomepage(project, context)
},

Query: {
Expand Down
11 changes: 11 additions & 0 deletions packages/@vue/cli-ui/apollo-server/util/strings.js
@@ -0,0 +1,11 @@
exports.getHttpsGitURL = url => {
if (url.startsWith('http')) {
return url.replace('.git', '')
} else if (url.startsWith('git@')) {
return url
.replace(':', '/')
.replace('git@', 'https://')
.replace(/.git([^.git]*)$/, '')
}
return url
}
3 changes: 2 additions & 1 deletion packages/@vue/cli-ui/locales/en.json
Expand Up @@ -149,7 +149,8 @@
},
"top-bar": {
"no-favorites": "No favorite projects",
"favorite-projects": "Favorite projects"
"favorite-projects": "Favorite projects",
"homepage": "Home page"
},
"view-badge": {
"labels": {
Expand Down
3 changes: 2 additions & 1 deletion packages/@vue/cli-ui/package.json
Expand Up @@ -47,6 +47,7 @@
"lru-cache": "^4.1.2",
"node-ipc": "^9.1.1",
"node-notifier": "^5.2.1",
"parse-git-config": "^2.0.2",
"portfinder": "^1.0.13",
"semver": "^5.5.0",
"shortid": "^2.2.8",
Expand All @@ -60,7 +61,7 @@
"@vue/cli-plugin-eslint": "^3.0.0-rc.3",
"@vue/cli-service": "^3.0.0-rc.3",
"@vue/eslint-config-standard": "^3.0.0-rc.3",
"@vue/ui": "^0.4.4",
"@vue/ui": "^0.4.5",
"ansi_up": "^2.0.2",
"cross-env": "^5.1.5",
"eslint": "^4.16.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/@vue/cli-ui/src/components/ProjectSelectListItem.vue
Expand Up @@ -25,6 +25,15 @@
</ListItemInfo>
</div>
<div class="actions">
<VueButton
v-if="project.homepage"
:href="project.homepage"
target="_blank"
class="icon-button"
icon-left="open_in_new"
v-tooltip="project.homepage"
@click.stop
/>
<VueButton
class="icon-button"
icon-left="close"
Expand Down
8 changes: 8 additions & 0 deletions packages/@vue/cli-ui/src/components/TopBar.vue
Expand Up @@ -16,6 +16,14 @@
>
{{ $t('org.vue.components.project-select-list-item.tooltips.favorite') }}
</VueSwitch>

<VueDropdownButton
v-if="projectCurrent.homepage"
:href="projectCurrent.homepage"
:label="$t('org.vue.components.top-bar.homepage')"
target="_blank"
icon-left="open_in_new"
/>
</template>

<div class="dropdown-separator"/>
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli-ui/src/graphql/projectFragment.gql
Expand Up @@ -4,4 +4,5 @@ fragment project on Project {
type
path
favorite
homepage
}
44 changes: 40 additions & 4 deletions yarn.lock
Expand Up @@ -1048,9 +1048,9 @@
dependencies:
lodash "^4.17.4"

"@vue/ui@^0.4.4":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@vue/ui/-/ui-0.4.4.tgz#47c843f6b1da21e3f919c7668f9e3a49c27bcd80"
"@vue/ui@^0.4.5":
version "0.4.5"
resolved "https://registry.yarnpkg.com/@vue/ui/-/ui-0.4.5.tgz#003334fd98e42ef600e8f3f3fbd98733e9a9fadd"
dependencies:
focus-visible "^4.1.4"
material-design-icons "^3.0.1"
Expand Down Expand Up @@ -4656,6 +4656,12 @@ expand-range@^1.8.1:
dependencies:
fill-range "^2.1.0"

expand-tilde@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
dependencies:
homedir-polyfill "^1.0.1"

expect@^22.4.0:
version "22.4.3"
resolved "https://registry.yarnpkg.com/expect/-/expect-22.4.3.tgz#d5a29d0a0e1fb2153557caef2674d4547e914674"
Expand Down Expand Up @@ -5149,6 +5155,10 @@ fs-constants@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"

fs-exists-sync@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add"

fs-extra@4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.1.tgz#7fc0c6c8957f983f57f306a24e5b9ddd8d0dd880"
Expand Down Expand Up @@ -5349,6 +5359,14 @@ git-clone@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/git-clone/-/git-clone-0.1.0.tgz#0d76163778093aef7f1c30238f2a9ef3f07a2eb9"

git-config-path@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/git-config-path/-/git-config-path-1.0.1.tgz#6d33f7ed63db0d0e118131503bab3aca47d54664"
dependencies:
extend-shallow "^2.0.1"
fs-exists-sync "^0.1.0"
homedir-polyfill "^1.0.0"

git-raw-commits@^1.3.0, git-raw-commits@^1.3.6:
version "1.3.6"
resolved "https://registry.yarnpkg.com/git-raw-commits/-/git-raw-commits-1.3.6.tgz#27c35a32a67777c1ecd412a239a6c19d71b95aff"
Expand Down Expand Up @@ -5824,6 +5842,12 @@ hogan.js@^3.0.2:
mkdirp "0.3.0"
nopt "1.0.10"

homedir-polyfill@^1.0.0, homedir-polyfill@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc"
dependencies:
parse-passwd "^1.0.0"

hosted-git-info@^2.1.4, hosted-git-info@^2.5.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.6.0.tgz#23235b29ab230c576aab0d4f13fc046b0b038222"
Expand Down Expand Up @@ -6105,7 +6129,7 @@ inherits@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"

ini@^1.3.2, ini@^1.3.4, ini@~1.3.0:
ini@^1.3.2, ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
version "1.3.5"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"

Expand Down Expand Up @@ -9213,6 +9237,14 @@ parse-asn1@^5.0.0:
evp_bytestokey "^1.0.0"
pbkdf2 "^3.0.3"

parse-git-config@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/parse-git-config/-/parse-git-config-2.0.2.tgz#9f3154b069aefa747b199cbf95fefd2e749f7b36"
dependencies:
expand-tilde "^2.0.2"
git-config-path "^1.0.1"
ini "^1.3.5"

parse-github-repo-url@^1.3.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/parse-github-repo-url/-/parse-github-repo-url-1.4.1.tgz#9e7d8bb252a6cb6ba42595060b7bf6df3dbc1f50"
Expand All @@ -9239,6 +9271,10 @@ parse-json@^4.0.0:
error-ex "^1.3.1"
json-parse-better-errors "^1.0.1"

parse-passwd@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"

parse5@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608"
Expand Down

0 comments on commit 0199d72

Please sign in to comment.