Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor config & task icons #1450

Merged
merged 5 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions docs/plugin-dev-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ api.describeConfig({

#### Config icon

Specify an icon with either a file type (like `'json'`) or a file name (like `.babelrc` to get the babel icon). This is powered by file-icons.
It can be either a [Material icon](https://material.io/tools/icons) code or a custom image (see [Public static files](#public-static-files)):

```js
api.describeConfig({
/* ... */
// Icon generated using file-icons
icon: '.eslintrc.json'
// Config icon
icon: 'application_settings'
})
```

If you don't specify an icon, the plugin logo will be displayed if any (see [Logo](#logo)).

#### Config file

By default, a configuration UI might read and write to a configuration file, for example `.eslintrc.js`.
Expand Down Expand Up @@ -253,6 +255,20 @@ api.describeTask({
})
```

#### Task icon

It can be either a [Material icon](https://material.io/tools/icons) code or a custom image (see [Public static files](#public-static-files)):

```js
api.describeTask({
/* ... */
// Task icon
icon: 'application_settings'
})
```

If you don't specify an icon, the plugin logo will be displayed if any (see [Logo](#logo)).

#### Tasks parameters

You can add prompts to modify the command arguments. They will be displayed in a 'Parameters' modal.
Expand Down Expand Up @@ -912,4 +928,12 @@ You may need to expose some static files over the cli-ui builtin HTTP server (ty

Any file in an optional `ui-public` folder in the root of the plugin package folder will be exposed to the `/_plugin/:id/*` HTTP route.

For example, if you put a `my-logo.png` file into the `my-package/ui-public/` folder, it will be available with the `http://localhost:8000/_plugin/my-package/my-logo.png` URL when the cli-ui loads the plugin.
For example, if you put a `my-logo.png` file into the `my-package/ui-public/` folder, it will be available with the `/_plugin/my-package/my-logo.png` URL when the cli-ui loads the plugin.

```js
api.describeConfig({
/* ... */
// Custom image
icon: '/_plugin/my-package/my-logo.png'
})
```
2 changes: 0 additions & 2 deletions packages/@vue/cli-plugin-eslint/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = api => {
name: 'ESLint configuration',
description: 'eslint.config.eslint.description',
link: 'https://github.com/vuejs/eslint-plugin-vue',
icon: '.eslintrc.json',
files: {
json: ['.eslintrc', '.eslintrc.json'],
js: ['.eslintrc.js'],
Expand Down Expand Up @@ -181,7 +180,6 @@ module.exports = api => {
name: 'ESLint extra',
description: 'eslint.config.eslint-extra.description',
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint#configuration',
icon: '.eslintrc.json',
files: {
js: ['vue.config.js']
},
Expand Down
1 change: 0 additions & 1 deletion packages/@vue/cli-plugin-pwa/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module.exports = api => {
name: 'PWA',
description: 'pwa.config.pwa.description',
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa#configuration',
icon: 'mobile.xm',
files: {
js: ['vue.config.js']
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/@vue/cli-service/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = api => {
match: /vue-cli-service serve/,
description: 'vue-webpack.tasks.serve.description',
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#serve',
icon: '/_plugin/%40vue%2Fcli-service/webpack-logo.png',
prompts: [
{
name: 'open',
Expand Down Expand Up @@ -120,6 +121,7 @@ module.exports = api => {
match: /vue-cli-service build/,
description: 'vue-webpack.tasks.build.description',
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#build',
icon: '/_plugin/%40vue%2Fcli-service/webpack-logo.png',
prompts: [
{
name: 'mode',
Expand Down Expand Up @@ -210,6 +212,7 @@ module.exports = api => {
command: 'vue-cli-service inspect',
description: 'vue-webpack.tasks.inspect.description',
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md#inspecting-the-projects-webpack-config',
icon: '/_plugin/%40vue%2Fcli-service/webpack-inspect-logo.png',
prompts: [
{
name: 'mode',
Expand Down
1 change: 0 additions & 1 deletion packages/@vue/cli-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"cross-env": "^5.1.5",
"eslint": "^4.16.0",
"eslint-plugin-graphql": "^2.1.1",
"file-icons-js": "^1.0.3",
"lint-staged": "^6.0.0",
"portal-vue": "^1.3.0",
"start-server-and-test": "^1.4.1",
Expand Down
1 change: 0 additions & 1 deletion packages/@vue/cli-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default {

<style lang="stylus">
@import "~@vue/ui/dist/vue-ui.css"
@import "~file-icons-js/css/style.css"
@import "~@/style/main"
</style>

Expand Down
20 changes: 2 additions & 18 deletions packages/@vue/cli-ui/src/components/ConfigurationItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
>
<div class="content">
<ItemLogo
:file-icon="iconClass"
:image="configuration.icon || (configuration.plugin && configuration.plugin.logo)"
fallback-icon="settings_applications"
/>

<ListItemInfo
Expand All @@ -21,8 +22,6 @@
</template>

<script>
import icons from 'file-icons-js'

export default {
props: {
configuration: {
Expand All @@ -34,21 +33,6 @@ export default {
type: Boolean,
default: false
}
},

computed: {
iconClass () {
return icons.getClassWithColor(this.getFileName(this.configuration.icon) || this.configuration.id) || 'gear-icon medium-blue'
}
},

methods: {
getFileName (icon) {
if (icon) {
if (!icon.includes('.')) return `f.${icon}`
return icon
}
}
}
}
</script>
Expand Down
34 changes: 8 additions & 26 deletions packages/@vue/cli-ui/src/components/ItemLogo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@
icon="done"
/>
<img
v-else-if="imageEnabled && !error"
v-else-if="!isMaterialIcon && !error"
class="image"
:src="imageUrl"
:key="imageUrl"
:src="image"
:key="image"
@load="loaded = true"
@error="error = true"
>
<div
v-else-if="fileIcon"
class="dynamic-file-icon"
:class="fileIcon"
/>
<VueIcon
v-else
:icon="icon"
:icon="error || !image ? fallbackIcon : image"
/>
</div>
</div>
Expand All @@ -38,18 +33,13 @@
export default {
props: {
image: {
type: String,
default: null
},

icon: {
type: String,
default: 'widgets'
},

fileIcon: {
fallbackIcon: {
type: String,
default: null
default: 'image'
},

selected: {
Expand All @@ -66,12 +56,8 @@ export default {
},

computed: {
imageEnabled () {
return this.image || (this.icon && this.icon.indexOf('.') !== -1)
},

imageUrl () {
return this.image || this.icon
isMaterialIcon () {
return /^[a-z0-9_]+$/.test(this.image)
}
},

Expand Down Expand Up @@ -112,10 +98,6 @@ export default {
>>> svg
fill rgba($color-text-light, .3)

.dynamic-file-icon
&::before
font-size 24px

&.vuejs
.wrapper
background lighten($vue-ui-color-primary, 70%)
Expand Down
5 changes: 4 additions & 1 deletion packages/@vue/cli-ui/src/components/ProjectPluginItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<div class="project-plugin-item list-item">
<div class="content">
<ItemLogo :image="pluginLogo && pluginLogo.logo"/>
<ItemLogo
:image="pluginLogo && pluginLogo.logo"
fallback-icon="widgets"
/>

<ListItemInfo
:name="plugin.id"
Expand Down
6 changes: 5 additions & 1 deletion packages/@vue/cli-ui/src/components/TaskItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
>
<div class="content">
<ItemLogo
:icon="iconData.icon"
:image="logo ? logo : iconData.icon"
:class="iconData.class"
v-tooltip="status"
/>
Expand Down Expand Up @@ -56,6 +56,10 @@ export default {

iconData () {
return icons[this.task.status]
},

logo () {
return this.task.icon || (this.task.plugin && this.task.plugin.logo)
}
},

Expand Down
25 changes: 20 additions & 5 deletions packages/@vue/cli-ui/src/graphql-api/api/PluginApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class PluginApi {
describeConfig (options) {
try {
validateConfiguration(options)
this.configurations.push(options)
this.configurations.push({
...options,
pluginId: this.pluginId
})
} catch (e) {
logs.add({
type: 'error',
Expand All @@ -79,7 +82,10 @@ class PluginApi {
describeTask (options) {
try {
validateDescribeTask(options)
this.describedTasks.push(options)
this.describedTasks.push({
...options,
pluginId: this.pluginId
})
} catch (e) {
logs.add({
type: 'error',
Expand Down Expand Up @@ -111,7 +117,10 @@ class PluginApi {
addTask (options) {
try {
validateAddTask(options)
this.addedTasks.push(options)
this.addedTasks.push({
...options,
pluginId: this.pluginId
})
} catch (e) {
logs.add({
type: 'error',
Expand Down Expand Up @@ -143,7 +152,10 @@ class PluginApi {
if (options.url && options.path) {
throw new Error(`'url' and 'path' can't be defined at the same time.`)
}
this.clientAddons.push(options)
this.clientAddons.push({
...options,
pluginId: this.pluginId
})
} catch (e) {
logs.add({
type: 'error',
Expand All @@ -164,7 +176,10 @@ class PluginApi {
addView (options) {
try {
validateView(options)
this.views.push(options)
this.views.push({
...options,
pluginId: this.pluginId
})
} catch (e) {
logs.add({
type: 'error',
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli-ui/src/graphql-api/api/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { createSchema, validateSync } = require('@vue/cli-shared-utils')
const schema = joi => ({
description: joi.string(),
link: joi.string().uri(),
icon: joi.string(),
prompts: joi.array(),
views: joi.array().items(joi.object({
id: joi.string().required(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function getUrl (addon, context) {

function serve (req, res) {
const { id, 0: file } = req.params
const addon = findOne(id)
const addon = findOne(decodeURIComponent(id))
if (addon && addon.path) {
const basePath = resolveModuleRoot(require.resolve(addon.path))
if (basePath) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ async function callAction ({ id, params }, context) {

function serve (req, res) {
const { id, 0: file } = req.params
const basePath = id === '.' ? cwd.get() : getPath(id)
const basePath = id === '.' ? cwd.get() : getPath(decodeURIComponent(id))
if (basePath) {
res.sendFile(path.join(basePath, 'ui-public', file))
return
Expand Down
5 changes: 4 additions & 1 deletion packages/@vue/cli-ui/src/graphql-api/schema/configuration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const gql = require('graphql-tag')
// Connectors
const configurations = require('../connectors/configurations')
const plugins = require('../connectors/plugins')

exports.types = gql`
extend type Query {
Expand All @@ -20,12 +21,14 @@ type Configuration implements DescribedEntity {
link: String
icon: String
prompts: [Prompt]
plugin: Plugin
}
`

exports.resolvers = {
Configuration: {
prompts: (configuration, args, context) => configurations.getPrompts(configuration.id, context)
prompts: (configuration, args, context) => configurations.getPrompts(configuration.id, context),
plugin: (configuration, args, context) => plugins.findOne(configuration.pluginId, context)
},

Query: {
Expand Down
Loading