diff --git a/packages/@vue/cli-ui/src/graphql-api/connectors/projects.js b/packages/@vue/cli-ui/src/graphql-api/connectors/projects.js index faccd3996e..ae7916a87f 100644 --- a/packages/@vue/cli-ui/src/graphql-api/connectors/projects.js +++ b/packages/@vue/cli-ui/src/graphql-api/connectors/projects.js @@ -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' @@ -295,7 +297,8 @@ 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 @@ -303,6 +306,9 @@ async function open (id, context) { // Load plugins plugins.list(project.path, context) + // Save for next time + context.db.set('config.lastOpenProject', id).write() + return project } @@ -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, diff --git a/packages/@vue/cli-ui/src/graphql-api/context.js b/packages/@vue/cli-ui/src/graphql-api/context.js index b586ab691d..c14b35fce8 100644 --- a/packages/@vue/cli-ui/src/graphql-api/context.js +++ b/packages/@vue/cli-ui/src/graphql-api/context.js @@ -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 } } diff --git a/packages/@vue/cli-ui/src/graphql-api/pubsub.js b/packages/@vue/cli-ui/src/graphql-api/pubsub.js new file mode 100644 index 0000000000..1fea486a15 --- /dev/null +++ b/packages/@vue/cli-ui/src/graphql-api/pubsub.js @@ -0,0 +1,4 @@ +const { PubSub } = require('graphql-subscriptions') + +const pubsub = new PubSub() +module.exports = pubsub diff --git a/packages/@vue/cli-ui/src/graphql-api/utils/db.js b/packages/@vue/cli-ui/src/graphql-api/utils/db.js index 226e70f220..7929a1ae00 100644 --- a/packages/@vue/cli-ui/src/graphql-api/utils/db.js +++ b/packages/@vue/cli-ui/src/graphql-api/utils/db.js @@ -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 = {