From 6e1f7357a36dd4c179309cb7afa11eb0d3b6e3f4 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Sun, 10 Jun 2018 17:59:45 +0200 Subject: [PATCH] fix(ui): save db in user home --- packages/@vue/cli-ui/src/graphql-api/utils/db.js | 16 +++++++++++----- packages/@vue/cli/lib/options.js | 16 ++-------------- packages/@vue/cli/lib/util/xdgConfig.js | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 packages/@vue/cli/lib/util/xdgConfig.js 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 10a7e8ee13..d0424b5b54 100644 --- a/packages/@vue/cli-ui/src/graphql-api/utils/db.js +++ b/packages/@vue/cli-ui/src/graphql-api/utils/db.js @@ -1,19 +1,25 @@ const Lowdb = require('lowdb') const FileSync = require('lowdb/adapters/FileSync') const fs = require('fs-extra') -const { resolve } = require('path') +const path = require('path') +const os = require('os') +const { xdgConfigPath } = require('@vue/cli/lib/util/xdgConfig') -let folder = '../../../live' +let folder if (process.env.VUE_CLI_UI_TEST) { folder = '../../../live-test' // Clean DB - fs.removeSync(resolve(__dirname, folder)) + fs.removeSync(path.resolve(__dirname, folder)) +} else { + folder = process.env.VUE_CLI_UI_DB_PATH || + xdgConfigPath('.vue-cli-ui') || + path.join(os.homedir(), '.vue-cli-ui') } -fs.ensureDirSync(resolve(__dirname, folder)) +fs.ensureDirSync(path.resolve(__dirname, folder)) -const db = new Lowdb(new FileSync(resolve(__dirname, folder, 'db.json'))) +const db = new Lowdb(new FileSync(path.resolve(__dirname, folder, 'db.json'))) // Seed an empty DB db.defaults({ diff --git a/packages/@vue/cli/lib/options.js b/packages/@vue/cli/lib/options.js index 94f41a7bf3..1bccda95b5 100644 --- a/packages/@vue/cli/lib/options.js +++ b/packages/@vue/cli/lib/options.js @@ -5,23 +5,11 @@ const cloneDeep = require('lodash.clonedeep') const { error } = require('@vue/cli-shared-utils/lib/logger') const { createSchema, validate } = require('@vue/cli-shared-utils/lib/validate') const { exit } = require('@vue/cli-shared-utils/lib/exit') - -const xdgConfigPath = () => { - const xdgConfigHome = process.env.XDG_CONFIG_HOME - if (xdgConfigHome) { - const rcDir = path.join(xdgConfigHome, 'vue') - if (!fs.existsSync(rcDir)) { - fs.mkdirSync(rcDir, 0o700) - } - return path.join(rcDir, '.vuerc') - } - - return undefined -} +const { xdgConfigPath } = require('./util/xdgConfig') const rcPath = exports.rcPath = ( process.env.VUE_CLI_CONFIG_PATH || - xdgConfigPath() || + xdgConfigPath('.vuerc') || path.join(os.homedir(), '.vuerc') ) diff --git a/packages/@vue/cli/lib/util/xdgConfig.js b/packages/@vue/cli/lib/util/xdgConfig.js new file mode 100644 index 0000000000..dfd2cccefa --- /dev/null +++ b/packages/@vue/cli/lib/util/xdgConfig.js @@ -0,0 +1,15 @@ +const fs = require('fs') +const path = require('path') + +exports.xdgConfigPath = (file) => { + const xdgConfigHome = process.env.XDG_CONFIG_HOME + if (xdgConfigHome) { + const rcDir = path.join(xdgConfigHome, 'vue') + if (!fs.existsSync(rcDir)) { + fs.mkdirSync(rcDir, 0o700) + } + return path.join(rcDir, file) + } + + return undefined +}