-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathe-show.js
executable file
·170 lines (155 loc) · 4.46 KB
/
e-show.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env node
const childProcess = require('child_process');
const open = require('open');
const os = require('os');
const path = require('path');
const program = require('commander');
const evmConfig = require('./evm-config');
const { color, fatal } = require('./utils/logging');
const depot = require('./utils/depot-tools');
function gitStatus(config) {
const exec = 'git';
const opts = {
cwd: path.resolve(config.root, 'src', 'electron'),
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
};
const switches = [
['describe', '--tags', '--exact-match'], // tag
['symbolic-ref', '-q', '--short', 'HEAD'], // branch
['rev-parse', '--short', 'HEAD'], // commit
];
const outs = [];
for (const args of switches) {
try {
outs.push(childProcess.execFileSync(exec, args, opts));
} catch {}
}
return outs
.map((out) => out.trim())
.filter((out) => out)
.join(' ');
}
program.description('Show information about the current build config');
program
.command('current')
.description('Show the current build config')
.option('-n, --no-name', "Don't show config name")
.option('-g, --git', 'Human-readable git status (tag, branch, commit)', false)
.option('-f, --filepath', 'Config filepath', false)
.action((options) => {
try {
const name = evmConfig.currentName();
const parts = [];
if (options.name) parts.push(color.config(name));
if (options.git) parts.push(color.git(gitStatus(evmConfig.current())));
if (options.filepath) parts.push(color.path(evmConfig.pathOf(name)));
const txt = parts.join(', ');
if (txt) console.log(txt);
} catch (e) {
fatal(e);
}
});
program
.command('configs')
.alias('ls')
.description('Show installed build config')
.action(() => {
let current;
try {
current = evmConfig.currentName();
} catch {
// maybe there is no current config
}
try {
const names = evmConfig.names();
if (names.length === 0) {
console.log('No build configs found. (You can create one with `e init`)');
} else {
names
.sort()
.map((name) => `${name === current ? '*' : ' '} ${color.config(name)}`)
.forEach((name) => console.log(name));
}
} catch (e) {
fatal(e);
}
});
program
.command('depotdir')
.description('Show path of the depot-tools directory')
.action(() => console.log(depot.path));
program
.command('env')
.description('Show environment variables set when building Electron')
.option('--json', 'Output as JSON')
.action((options) => {
try {
const { env } = depot.opts(evmConfig.current());
// This command shows the difference between the current
// process.env and the env that is needed for running commands
for (const key of Object.keys(env)) {
if (process.env[key] === env[key]) {
delete env[key];
}
}
if (options.json) {
console.log(JSON.stringify(env, null, 2));
} else {
const exportKeyword = os.platform() === 'win32' ? 'set' : 'export';
const logger = ([key, val]) => console.log(`${exportKeyword} ${key}=${val}`);
Object.entries(env).forEach(logger);
}
} catch (e) {
fatal(e);
}
});
program
.command('exe')
.alias('exec')
.description(`Show the Electron executable's path`)
.action(() => {
try {
console.log(color.path(evmConfig.execOf(evmConfig.current())));
} catch (e) {
fatal(e);
}
});
program
.command('root')
.description('Show path of the top directory - home of the .gclient file')
.action(() => {
try {
console.log(color.path(evmConfig.current().root));
} catch (e) {
fatal(e);
}
});
program
.command('src [name]')
.description('Show path of the named (default:electron) src directory e.g. "/$root/src/electron"')
.action((name) => {
try {
const { root } = evmConfig.current();
name = name || 'electron';
console.log(color.path(path.resolve(root, 'src', name)));
} catch (e) {
fatal(e);
}
});
program
.command('out')
.description('Show outdir name, e.g. "Testing"')
.option('--path', 'Output absolute path to outdir')
.action((options) => {
try {
if (options.path) {
console.log(color.path(evmConfig.outDir(evmConfig.current())));
} else {
console.log(evmConfig.current().gen.out);
}
} catch (e) {
fatal(e);
}
});
program.parse(process.argv);