Skip to content

Commit

Permalink
fix(ui): PluginApi light mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jul 8, 2018
1 parent 96778b2 commit 9929b70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion packages/@vue/cli-ui/apollo-server/api/PluginApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ const { validateSuggestion } = require('./suggestion')
const { validateProgress } = require('./progress')

class PluginApi {
constructor ({ plugins, file, project }, context) {
constructor ({ plugins, file, project, lightMode = false }, context) {
// Context
this.context = context
this.pluginId = null
this.project = project
this.plugins = plugins
this.cwd = file
this.lightMode = lightMode
// Hooks
this.hooks = {
projectOpen: [],
Expand Down Expand Up @@ -55,6 +56,7 @@ class PluginApi {
* @param {function} cb Handler
*/
onProjectOpen (cb) {
if (this.lightMode) return
if (this.project) {
cb(this.project)
return
Expand All @@ -68,6 +70,7 @@ class PluginApi {
* @param {function} cb Handler
*/
onPluginReload (cb) {
if (this.lightMode) return
this.hooks.pluginReload.push(cb)
}

Expand All @@ -77,6 +80,7 @@ class PluginApi {
* @param {function} cb Handler
*/
onConfigRead (cb) {
if (this.lightMode) return
this.hooks.configRead.push(cb)
}

Expand All @@ -86,6 +90,7 @@ class PluginApi {
* @param {function} cb Handler
*/
onConfigWrite (cb) {
if (this.lightMode) return
this.hooks.configWrite.push(cb)
}

Expand All @@ -95,6 +100,7 @@ class PluginApi {
* @param {function} cb Handler
*/
onTaskRun (cb) {
if (this.lightMode) return
this.hooks.taskRun.push(cb)
}

Expand All @@ -104,6 +110,7 @@ class PluginApi {
* @param {function} cb Handler
*/
onTaskExit (cb) {
if (this.lightMode) return
this.hooks.taskExit.push(cb)
}

Expand All @@ -113,6 +120,7 @@ class PluginApi {
* @param {function} cb Handler
*/
onTaskOpen (cb) {
if (this.lightMode) return
this.hooks.taskOpen.push(cb)
}

Expand All @@ -122,6 +130,7 @@ class PluginApi {
* @param {function} cb Handler
*/
onViewOpen (cb) {
if (this.lightMode) return
this.hooks.viewOpen.push(cb)
}

Expand All @@ -131,6 +140,7 @@ class PluginApi {
* @param {object} options Configuration description
*/
describeConfig (options) {
if (this.lightMode) return
try {
validateConfiguration(options)
this.configurations.push({
Expand Down Expand Up @@ -221,6 +231,7 @@ class PluginApi {
* }
*/
addClientAddon (options) {
if (this.lightMode) return
try {
validateClientAddon(options)
if (options.url && options.path) {
Expand Down Expand Up @@ -248,6 +259,7 @@ class PluginApi {
* @param {object} options ProjectView options
*/
addView (options) {
if (this.lightMode) return
try {
validateView(options)
this.views.push({
Expand All @@ -272,6 +284,7 @@ class PluginApi {
* @param {object} options Badge options
*/
addViewBadge (viewId, options) {
if (this.lightMode) return
try {
validateBadge(options)
views.addBadge({ viewId, badge: options }, this.context)
Expand Down Expand Up @@ -374,6 +387,7 @@ class PluginApi {
* @param {object} options Progress options
*/
setProgress (options) {
if (this.lightMode) return
try {
validateProgress(options)
progress.set({
Expand Down Expand Up @@ -524,6 +538,7 @@ class PluginApi {
* @param {object} options Suggestion
*/
addSuggestion (options) {
if (this.lightMode) return
try {
validateSuggestion(options)
suggestions.add(options, this.context)
Expand Down
3 changes: 2 additions & 1 deletion packages/@vue/cli-ui/apollo-server/connectors/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ function resetPluginApi ({ file, lightApi }, context) {
pluginApi = new PluginApi({
plugins,
file,
project
project,
lightMode: lightApi
}, context)
pluginApiInstances.set(file, pluginApi)

Expand Down

0 comments on commit 9929b70

Please sign in to comment.