Skip to content

Commit eca54fc

Browse files
author
Guillaume Chau
committed
feat(ui): PluginApi: resolve + getProject
1 parent 9d798fb commit eca54fc

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

docs/dev-guide/ui-api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,22 @@ Retrieve the current working directory.
12361236
api.getCwd()
12371237
```
12381238

1239+
### resolve
1240+
1241+
Resolves a file within the current project.
1242+
1243+
```js
1244+
api.resolve('src/main.js')
1245+
```
1246+
1247+
### getProject
1248+
1249+
Get currently open project.
1250+
1251+
```js
1252+
api.getProject()
1253+
```
1254+
12391255
## Public static files
12401256

12411257
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).

packages/@vue/cli-ui/src/graphql-api/api/PluginApi.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path')
12
// Connectors
23
const logs = require('../connectors/logs')
34
const sharedData = require('../connectors/shared-data')
@@ -10,6 +11,7 @@ const progress = require('../connectors/progress')
1011
const ipc = require('../utils/ipc')
1112
const { notify } = require('../utils/notification')
1213
const { matchesPluginId } = require('@vue/cli-shared-utils')
14+
const { log } = require('../utils/logger')
1315
// Validators
1416
const { validateConfiguration } = require('./configuration')
1517
const { validateDescribeTask, validateAddTask } = require('./task')
@@ -403,6 +405,21 @@ class PluginApi {
403405
return cwd.get()
404406
}
405407

408+
/**
409+
* Resolves a file relative to current working directory
410+
* @param {string} file Path to file relative to project
411+
*/
412+
resolve (file) {
413+
return path.resolve(cwd.get(), file)
414+
}
415+
416+
/**
417+
* Get currently open project
418+
*/
419+
getProject () {
420+
return this.project
421+
}
422+
406423
/* Namespaced */
407424

408425
/**
@@ -498,6 +515,7 @@ class PluginApi {
498515
* @param {any} value Value to be stored (must be serializable in JSON)
499516
*/
500517
storageSet (id, value) {
518+
log('Storage set', id, value)
501519
this.db.set(id, value).write()
502520
}
503521

packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ function resetPluginApi (context) {
122122
if (!project) return
123123
if (projectId !== project.id) {
124124
projectId = project.id
125-
callHook('projectOpen', [project, projects.getLast(context)], context)
126125
pluginApi.project = project
126+
callHook('projectOpen', [project, projects.getLast(context)], context)
127127
} else {
128128
callHook('pluginReload', [project], context)
129129

0 commit comments

Comments
 (0)