forked from yarnpkg/yarn
/
config.js
107 lines (91 loc) 路 2.69 KB
/
config.js
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
/* @flow */
/* eslint object-shorthand: 0 */
import type {Reporter} from '../../reporters/index.js';
import type Config from '../../config.js';
import buildSubCommands from './_build-sub-commands.js';
const CONFIG_KEYS = [
// 'reporter',
'registryFolders',
'linkedModules',
// 'registries',
'cache',
'cwd',
'looseSemver',
'commandName',
'preferOffline',
'modulesFolder',
'globalFolder',
'linkFolder',
'offline',
'binLinks',
'ignorePlatform',
'ignoreScripts',
'disablePrepublish',
'nonInteractive',
'workspaceRootFolder',
'lockfileFolder',
'networkConcurrency',
'childConcurrency',
'networkTimeout',
'workspacesEnabled',
'workspacesNohoistEnabled',
'pruneOfflineMirror',
'enableMetaFolder',
'enableLockfileVersions',
'linkFileDependencies',
'cacheFolder',
'tempFolder',
'production',
];
export function hasWrapper(flags: Object, args: Array<string>): boolean {
return args[0] !== 'get';
}
export function setFlags(commander: Object) {
commander.description('Manages the yarn configuration files.');
}
export const {run, examples} = buildSubCommands('config', {
async set(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<boolean> {
if (args.length === 0 || args.length > 2) {
return false;
}
const [key, val = true] = args;
const yarnConfig = config.registries.yarn;
await yarnConfig.saveHomeConfig({[key]: val});
reporter.success(reporter.lang('configSet', key, val));
return true;
},
get(config: Config, reporter: Reporter, flags: Object, args: Array<string>): boolean {
if (args.length !== 1) {
return false;
}
reporter.log(String(config.getOption(args[0])), {force: true});
return true;
},
delete: async function(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<boolean> {
if (args.length !== 1) {
return false;
}
const key = args[0];
const yarnConfig = config.registries.yarn;
await yarnConfig.saveHomeConfig({[key]: undefined});
reporter.success(reporter.lang('configDelete', key));
return true;
},
list(config: Config, reporter: Reporter, flags: Object, args: Array<string>): boolean {
if (args.length) {
return false;
}
reporter.info(reporter.lang('configYarn'));
reporter.inspect(config.registries.yarn.config);
reporter.info(reporter.lang('configNpm'));
reporter.inspect(config.registries.npm.config);
return true;
},
current(config: Config, reporter: Reporter, flags: Object, args: Array<string>): boolean {
if (args.length) {
return false;
}
reporter.log(JSON.stringify(config, CONFIG_KEYS, 2), {force: true});
return true;
},
});