Skip to content

Commit

Permalink
fix(ui): save db in user home
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jun 10, 2018
1 parent a938008 commit 6e1f735
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
16 changes: 11 additions & 5 deletions packages/@vue/cli-ui/src/graphql-api/utils/db.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
16 changes: 2 additions & 14 deletions packages/@vue/cli/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)

Expand Down
15 changes: 15 additions & 0 deletions packages/@vue/cli/lib/util/xdgConfig.js
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6e1f735

Please sign in to comment.