forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.ts
94 lines (73 loc) · 2.94 KB
/
config.ts
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
import {CliConfig as CliConfigBase} from './config/config';
import {CliConfig as ConfigInterface} from '../lib/config/schema';
import { oneLine } from 'common-tags';
import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';
export const CLI_CONFIG_FILE_NAME = 'angular-cli.json';
function _findUp(name: string, from: string) {
let currentDir = from;
while (currentDir && currentDir !== path.parse(currentDir).root) {
const p = path.join(currentDir, name);
if (fs.existsSync(p)) {
return p;
}
const nodeModuleP = path.join(currentDir, 'node_modules');
if (fs.existsSync(nodeModuleP)) {
return null;
}
currentDir = path.dirname(currentDir);
}
return null;
}
function getUserHome() {
return process.env[(process.platform.startsWith('win')) ? 'USERPROFILE' : 'HOME'];
}
export class CliConfig extends CliConfigBase<ConfigInterface> {
static configFilePath(projectPath?: string): string {
// Find the configuration, either where specified, in the angular-cli project
// (if it's in node_modules) or from the current process.
return (projectPath && _findUp(CLI_CONFIG_FILE_NAME, projectPath))
|| _findUp(CLI_CONFIG_FILE_NAME, process.cwd())
|| _findUp(CLI_CONFIG_FILE_NAME, __dirname);
}
static fromGlobal(): CliConfig {
const globalConfigPath = path.join(getUserHome(), CLI_CONFIG_FILE_NAME);
const cliConfig = CliConfigBase.fromConfigPath<ConfigInterface>(globalConfigPath);
const aliases = [
cliConfig.alias('apps.0.root', 'defaults.sourceDir'),
cliConfig.alias('apps.0.prefix', 'defaults.prefix')
];
// If any of them returned true, output a deprecation warning.
if (aliases.some(x => !!x)) {
console.error(chalk.yellow(oneLine`
The "defaults.prefix" and "defaults.sourceDir" properties of angular-cli.json
are deprecated in favor of "apps[0].root" and "apps[0].prefix".\n
Please update in order to avoid errors in future versions of angular-cli.
`));
}
return cliConfig;
}
static fromProject(): CliConfig {
const configPath = this.configFilePath();
const globalConfigPath = path.join(getUserHome(), CLI_CONFIG_FILE_NAME);
if (!configPath) {
return null;
}
const cliConfig = CliConfigBase.fromConfigPath<ConfigInterface>(
CliConfig.configFilePath(), [globalConfigPath]);
const aliases = [
cliConfig.alias('apps.0.root', 'defaults.sourceDir'),
cliConfig.alias('apps.0.prefix', 'defaults.prefix')
];
// If any of them returned true, output a deprecation warning.
if (aliases.some(x => !!x)) {
console.error(chalk.yellow(oneLine`
The "defaults.prefix" and "defaults.sourceDir" properties of angular-cli.json
are deprecated in favor of "apps[0].root" and "apps[0].prefix".\n
Please update in order to avoid errors in future versions of angular-cli.
`));
}
return cliConfig as CliConfig;
}
}