Skip to content

Commit 6e1f735

Browse files
committed
fix(ui): save db in user home
1 parent a938008 commit 6e1f735

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
const Lowdb = require('lowdb')
22
const FileSync = require('lowdb/adapters/FileSync')
33
const fs = require('fs-extra')
4-
const { resolve } = require('path')
4+
const path = require('path')
5+
const os = require('os')
6+
const { xdgConfigPath } = require('@vue/cli/lib/util/xdgConfig')
57

6-
let folder = '../../../live'
8+
let folder
79

810
if (process.env.VUE_CLI_UI_TEST) {
911
folder = '../../../live-test'
1012
// Clean DB
11-
fs.removeSync(resolve(__dirname, folder))
13+
fs.removeSync(path.resolve(__dirname, folder))
14+
} else {
15+
folder = process.env.VUE_CLI_UI_DB_PATH ||
16+
xdgConfigPath('.vue-cli-ui') ||
17+
path.join(os.homedir(), '.vue-cli-ui')
1218
}
1319

14-
fs.ensureDirSync(resolve(__dirname, folder))
20+
fs.ensureDirSync(path.resolve(__dirname, folder))
1521

16-
const db = new Lowdb(new FileSync(resolve(__dirname, folder, 'db.json')))
22+
const db = new Lowdb(new FileSync(path.resolve(__dirname, folder, 'db.json')))
1723

1824
// Seed an empty DB
1925
db.defaults({

packages/@vue/cli/lib/options.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,11 @@ const cloneDeep = require('lodash.clonedeep')
55
const { error } = require('@vue/cli-shared-utils/lib/logger')
66
const { createSchema, validate } = require('@vue/cli-shared-utils/lib/validate')
77
const { exit } = require('@vue/cli-shared-utils/lib/exit')
8-
9-
const xdgConfigPath = () => {
10-
const xdgConfigHome = process.env.XDG_CONFIG_HOME
11-
if (xdgConfigHome) {
12-
const rcDir = path.join(xdgConfigHome, 'vue')
13-
if (!fs.existsSync(rcDir)) {
14-
fs.mkdirSync(rcDir, 0o700)
15-
}
16-
return path.join(rcDir, '.vuerc')
17-
}
18-
19-
return undefined
20-
}
8+
const { xdgConfigPath } = require('./util/xdgConfig')
219

2210
const rcPath = exports.rcPath = (
2311
process.env.VUE_CLI_CONFIG_PATH ||
24-
xdgConfigPath() ||
12+
xdgConfigPath('.vuerc') ||
2513
path.join(os.homedir(), '.vuerc')
2614
)
2715

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
exports.xdgConfigPath = (file) => {
5+
const xdgConfigHome = process.env.XDG_CONFIG_HOME
6+
if (xdgConfigHome) {
7+
const rcDir = path.join(xdgConfigHome, 'vue')
8+
if (!fs.existsSync(rcDir)) {
9+
fs.mkdirSync(rcDir, 0o700)
10+
}
11+
return path.join(rcDir, file)
12+
}
13+
14+
return undefined
15+
}

0 commit comments

Comments
 (0)