Skip to content

Commit

Permalink
feat(ui): open last project
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Apr 17, 2018
1 parent 9320f5f commit f79cb6e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
17 changes: 16 additions & 1 deletion packages/@vue/cli-ui/src/graphql-api/connectors/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const cwd = require('./cwd')
const prompts = require('./prompts')
const folders = require('./folders')
const plugins = require('./plugins')
// Context
const getContext = require('../context')

const PROGRESS_ID = 'project-create'

Expand Down Expand Up @@ -295,14 +297,18 @@ async function open (id, context) {
}).value()

if (!project) {
throw new Error(`Project '${id}' not found`)
console.warn(`Project '${id}' not found`)
return null
}

currentProject = project
cwd.set(project.path, context)
// Load plugins
plugins.list(project.path, context)

// Save for next time
context.db.set('config.lastOpenProject', id).write()

return project
}

Expand All @@ -329,6 +335,15 @@ function setFavorite ({ id, favorite }, context) {
return findOne(id, context)
}

// Open last project
{
const context = getContext(null)
const id = context.db.get('config.lastOpenProject').value()
if (id) {
open(id, context)
}
}

module.exports = {
list,
getCurrent,
Expand Down
4 changes: 3 additions & 1 deletion packages/@vue/cli-ui/src/graphql-api/context.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { db } = require('./utils/db')
const pubsub = require('./pubsub')

// Context passed to all resolvers (third argument)
// eslint-disable-next-line no-unused-vars
module.exports = req => {
return {
db
db,
pubsub
}
}
4 changes: 4 additions & 0 deletions packages/@vue/cli-ui/src/graphql-api/pubsub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { PubSub } = require('graphql-subscriptions')

const pubsub = new PubSub()
module.exports = pubsub
3 changes: 2 additions & 1 deletion packages/@vue/cli-ui/src/graphql-api/utils/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const db = new Lowdb(new FileSync(resolve(__dirname, '../../../live/db.json')))
db.defaults({
projects: [],
foldersFavorite: [],
tasks: []
tasks: [],
config: {}
}).write()

module.exports = {
Expand Down

0 comments on commit f79cb6e

Please sign in to comment.