1
- const fs = require ( 'fs' )
1
+ const fs = require ( 'fs-extra ' )
2
2
const os = require ( 'os' )
3
3
const path = require ( 'path' )
4
4
@@ -7,37 +7,41 @@ const xdgConfigPath = file => {
7
7
if ( xdgConfigHome ) {
8
8
const rcDir = path . join ( xdgConfigHome , 'vue' )
9
9
if ( ! fs . existsSync ( rcDir ) ) {
10
- fs . mkdirSync ( rcDir , 0o700 )
10
+ fs . ensureDirSync ( rcDir , 0o700 )
11
11
}
12
12
return path . join ( rcDir , file )
13
13
}
14
14
}
15
15
16
- const windowsConfigPath = file => {
16
+ // migration for 3.0.0-rc.7
17
+ // we introduced a change storing .vuerc in AppData, but the benefit isn't
18
+ // really obvious so we are reverting it to keep consistency across OSes
19
+ const migrateWindowsConfigPath = file => {
17
20
if ( process . platform !== 'win32' ) {
18
21
return
19
22
}
20
23
const appData = process . env . APPDATA
21
24
if ( appData ) {
22
25
const rcDir = path . join ( appData , 'vue' )
23
- if ( ! fs . existsSync ( rcDir ) ) {
24
- fs . mkdirSync ( rcDir )
25
- }
26
- const rcPath = path . join ( rcDir , file )
27
- // migration for < 3.0.0-rc.7
28
- const oldRcFile = path . join ( os . homedir ( ) , file )
29
- if ( fs . existsSync ( oldRcFile ) ) {
30
- fs . writeFileSync ( rcPath , fs . readFileSync ( oldRcFile ) )
31
- const chalk = require ( 'chalk' )
32
- console . log ( `Detected ${ chalk . cyan ( file ) } in ${ chalk . cyan ( path . dirname ( oldRcFile ) ) } ...` )
33
- console . log ( `Migrated to ${ chalk . cyan ( rcPath ) } .` )
26
+ const rcFile = path . join ( rcDir , file )
27
+ const properRcFile = path . join ( os . homedir ( ) , file )
28
+ if ( fs . existsSync ( rcFile ) ) {
29
+ try {
30
+ if ( fs . existsSync ( properRcFile ) ) {
31
+ fs . removeSync ( rcFile )
32
+ } else {
33
+ fs . moveSync ( rcFile , properRcFile )
34
+ }
35
+ } catch ( e ) { }
34
36
}
35
- return rcPath
36
37
}
37
38
}
38
39
39
- exports . getRcPath = file => (
40
- xdgConfigPath ( file ) ||
41
- windowsConfigPath ( file ) ||
42
- path . join ( os . homedir ( ) , file )
43
- )
40
+ exports . getRcPath = file => {
41
+ migrateWindowsConfigPath ( file )
42
+ return (
43
+ process . env . VUE_CLI_CONFIG_PATH ||
44
+ xdgConfigPath ( file ) ||
45
+ path . join ( os . homedir ( ) , file )
46
+ )
47
+ }
0 commit comments