feat(ui): PluginApi: resolve + getProject

This commit is contained in:
Guillaume Chau
2018-06-20 16:12:09 +02:00
parent 9d798fbef0
commit eca54fc461
3 changed files with 35 additions and 1 deletions
+16
View File
@@ -1236,6 +1236,22 @@ Retrieve the current working directory.
api.getCwd()
```
### resolve
Resolves a file within the current project.
```js
api.resolve('src/main.js')
```
### getProject
Get currently open project.
```js
api.getProject()
```
## Public static files
You may need to expose some static files over the cli-ui builtin HTTP server (typically if you want to specify an icon to a custom view).
@@ -1,3 +1,4 @@
const path = require('path')
// Connectors
const logs = require('../connectors/logs')
const sharedData = require('../connectors/shared-data')
@@ -10,6 +11,7 @@ const progress = require('../connectors/progress')
const ipc = require('../utils/ipc')
const { notify } = require('../utils/notification')
const { matchesPluginId } = require('@vue/cli-shared-utils')
const { log } = require('../utils/logger')
// Validators
const { validateConfiguration } = require('./configuration')
const { validateDescribeTask, validateAddTask } = require('./task')
@@ -403,6 +405,21 @@ class PluginApi {
return cwd.get()
}
/**
* Resolves a file relative to current working directory
* @param {string} file Path to file relative to project
*/
resolve (file) {
return path.resolve(cwd.get(), file)
}
/**
* Get currently open project
*/
getProject () {
return this.project
}
/* Namespaced */
/**
@@ -498,6 +515,7 @@ class PluginApi {
* @param {any} value Value to be stored (must be serializable in JSON)
*/
storageSet (id, value) {
log('Storage set', id, value)
this.db.set(id, value).write()
}
@@ -122,8 +122,8 @@ function resetPluginApi (context) {
if (!project) return
if (projectId !== project.id) {
projectId = project.id
callHook('projectOpen', [project, projects.getLast(context)], context)
pluginApi.project = project
callHook('projectOpen', [project, projects.getLast(context)], context)
} else {
callHook('pluginReload', [project], context)