Skip to content

Commit f79cb6e

Browse files
author
Guillaume Chau
committed
feat(ui): open last project
1 parent 9320f5f commit f79cb6e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const cwd = require('./cwd')
1313
const prompts = require('./prompts')
1414
const folders = require('./folders')
1515
const plugins = require('./plugins')
16+
// Context
17+
const getContext = require('../context')
1618

1719
const PROGRESS_ID = 'project-create'
1820

@@ -295,14 +297,18 @@ async function open (id, context) {
295297
}).value()
296298

297299
if (!project) {
298-
throw new Error(`Project '${id}' not found`)
300+
console.warn(`Project '${id}' not found`)
301+
return null
299302
}
300303

301304
currentProject = project
302305
cwd.set(project.path, context)
303306
// Load plugins
304307
plugins.list(project.path, context)
305308

309+
// Save for next time
310+
context.db.set('config.lastOpenProject', id).write()
311+
306312
return project
307313
}
308314

@@ -329,6 +335,15 @@ function setFavorite ({ id, favorite }, context) {
329335
return findOne(id, context)
330336
}
331337

338+
// Open last project
339+
{
340+
const context = getContext(null)
341+
const id = context.db.get('config.lastOpenProject').value()
342+
if (id) {
343+
open(id, context)
344+
}
345+
}
346+
332347
module.exports = {
333348
list,
334349
getCurrent,
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const { db } = require('./utils/db')
2+
const pubsub = require('./pubsub')
23

34
// Context passed to all resolvers (third argument)
45
// eslint-disable-next-line no-unused-vars
56
module.exports = req => {
67
return {
7-
db
8+
db,
9+
pubsub
810
}
911
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const { PubSub } = require('graphql-subscriptions')
2+
3+
const pubsub = new PubSub()
4+
module.exports = pubsub

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const db = new Lowdb(new FileSync(resolve(__dirname, '../../../live/db.json')))
1111
db.defaults({
1212
projects: [],
1313
foldersFavorite: [],
14-
tasks: []
14+
tasks: [],
15+
config: {}
1516
}).write()
1617

1718
module.exports = {

0 commit comments

Comments
 (0)