@@ -4,6 +4,7 @@ import { oneLine } from 'common-tags';
4
4
import * as chalk from 'chalk' ;
5
5
import * as fs from 'fs' ;
6
6
import * as path from 'path' ;
7
+ import { homedir } from 'os' ;
7
8
8
9
import { findUp } from '../utilities/find-up' ;
9
10
@@ -12,16 +13,6 @@ export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
12
13
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json' ;
13
14
14
15
15
- function getUserHome ( ) {
16
- const envHomeName = ( process . platform . startsWith ( 'win' ) ) ? 'USERPROFILE' : 'HOME' ;
17
- const env = process . env [ envHomeName ] ;
18
- if ( env == null ) {
19
- throw new Error ( 'Missing environment variable ' + envHomeName ) ;
20
- }
21
- return env ;
22
- }
23
-
24
-
25
16
const configCacheMap = new Map < string , CliConfigBase < ConfigInterface > > ( ) ;
26
17
27
18
@@ -52,11 +43,16 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
52
43
}
53
44
54
45
static globalConfigFilePath ( ) : string {
55
- let globalConfigPath = path . join ( getUserHome ( ) , CLI_CONFIG_FILE_NAME ) ;
56
- const altGlobalConfigPath = path . join ( getUserHome ( ) , CLI_CONFIG_FILE_NAME_ALT ) ;
57
- if ( ! fs . existsSync ( globalConfigPath ) && fs . existsSync ( altGlobalConfigPath ) ) {
46
+ const globalConfigPath = path . join ( homedir ( ) , CLI_CONFIG_FILE_NAME ) ;
47
+ if ( fs . existsSync ( globalConfigPath ) ) {
48
+ return globalConfigPath ;
49
+ }
50
+
51
+ const altGlobalConfigPath = path . join ( homedir ( ) , CLI_CONFIG_FILE_NAME_ALT ) ;
52
+ if ( fs . existsSync ( altGlobalConfigPath ) ) {
58
53
return altGlobalConfigPath ;
59
54
}
55
+
60
56
return globalConfigPath ;
61
57
}
62
58
@@ -109,12 +105,7 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
109
105
return configCacheMap . get ( configPath ) ;
110
106
}
111
107
112
- let globalConfigPath = path . join ( getUserHome ( ) , CLI_CONFIG_FILE_NAME ) ;
113
- const altGlobalConfigPath = path . join ( getUserHome ( ) , CLI_CONFIG_FILE_NAME_ALT ) ;
114
- if ( ! fs . existsSync ( globalConfigPath ) && fs . existsSync ( altGlobalConfigPath ) ) {
115
- globalConfigPath = altGlobalConfigPath ;
116
- }
117
-
108
+ const globalConfigPath = CliConfig . globalConfigFilePath ( ) ;
118
109
const cliConfig = CliConfigBase . fromConfigPath < ConfigInterface > ( configPath , [ globalConfigPath ] ) ;
119
110
120
111
const aliases = [
0 commit comments