-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathconfig.ts
More file actions
144 lines (127 loc) · 3.82 KB
/
config.ts
File metadata and controls
144 lines (127 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { BaseConfig, BaseConfigOptions, MetadataGroup, ParsedArgs, metadataOptionsToParseArgsOptions, parseArgs } from '@ionic/cli-framework';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';
import { CommandMetadataOption, ConfigFile, CreateRequestOptions, IConfig, OAuthServerConfig } from '../definitions';
export const GLOBAL_OPTIONS: readonly CommandMetadataOption[] = [
{
name: 'help',
summary: 'Display help for commands',
aliases: ['h'],
type: Boolean,
groups: [MetadataGroup.HIDDEN],
},
{
name: 'verbose',
summary: 'Print debug log messages',
type: Boolean,
},
{
name: 'quiet',
summary: 'Only print warning and error log messages',
type: Boolean,
},
{
name: 'interactive',
summary: 'Disable interactivity such as progress indicators and prompts',
type: Boolean,
default: true,
},
{
name: 'color',
summary: 'Disable colors in stdout',
type: Boolean,
default: true,
},
{
name: 'confirm',
summary: 'Automatically answer YES to confirmation prompts',
type: Boolean,
},
{
name: 'project',
summary: 'The project ID to use in a multi-app configuration setup',
groups: [MetadataGroup.HIDDEN],
},
{
name: 'json',
summary: 'Use JSON when operating with stdout, if possible',
type: Boolean,
groups: [MetadataGroup.HIDDEN],
},
];
export const CONFIG_FILE = 'config.json';
export const DEFAULT_CONFIG_DIRECTORY = findDefaultConfigDir();
function findDefaultConfigDir() {
const fallback = path.resolve(os.homedir(), '.ionic');
if (fs.existsSync(fallback)) return fallback;
if (process.env.XDG_CONFIG_HOME) {
return path.resolve(process.env.XDG_CONFIG_HOME, 'ionic');
} else {
return fallback;
}
}
export class Config extends BaseConfig<ConfigFile> implements IConfig {
constructor(p: string, options?: BaseConfigOptions) {
super(p, options);
const c = this.c as any;
// <4.0.0 config migration
if (c.state) {
// start fresh
this.c = {
'version': '4.0.0',
'telemetry': c.telemetry,
'npmClient': c.npmClient,
'interactive': c.interactive,
'user.id': c.user && c.user.id,
'user.email': c.user && c.user.email,
'git.setup': c.git && c.git.setup,
'tokens.user': c.tokens && c.tokens.user,
'tokens.telemetry': c.tokens && c.tokens.telemetry,
'features.ssl-commands': c.features && c.features['ssl-commands'],
};
}
}
provideDefaults(config: Partial<ConfigFile>): ConfigFile {
return {
'version': '4.0.0',
'telemetry': true,
'npmClient': 'npm',
};
}
getAPIUrl(): string {
return this.get('urls.api', 'https://api.ionicjs.com');
}
getDashUrl(): string {
return this.get('urls.dash', 'https://dashboard.ionicframework.com');
}
getGitHost(): string {
return this.get('git.host', 'git.ionicjs.com');
}
getGitPort(): number {
return this.get('git.port', 22);
}
getHTTPConfig(): CreateRequestOptions {
const { c } = this;
return {
userAgent: `node/superagent/Ionic CLI ${c.version}`,
ssl: {
cafile: c['ssl.cafile'],
certfile: c['ssl.certfile'],
keyfile: c['ssl.keyfile'],
},
proxy: c['proxy'],
};
}
getOpenIDOAuthConfig(): OAuthServerConfig {
return {
authorizationUrl: this.get('oauth.openid.authorization_url', 'https://ionicframework.com/oauth/authorize'),
tokenUrl: this.get('oauth.openid.token_url', 'https://api.ionicjs.com/oauth/token'),
clientId: this.get('oauth.openid.client_id', 'cli'),
apiAudience: this.get('oauth.openid.api_audience', 'https://api.ionicjs.com'),
};
}
}
export function parseGlobalOptions(pargv: string[]): ParsedArgs {
return parseArgs(pargv, metadataOptionsToParseArgsOptions(GLOBAL_OPTIONS));
}