@percy/cli-command 1.0.0-beta.70 → 1.0.0-beta.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -31
- package/bin/readme +51 -0
- package/dist/command.js +203 -76
- package/dist/flags.js +88 -54
- package/dist/help.js +262 -0
- package/dist/index.js +18 -4
- package/dist/legacy.js +176 -0
- package/dist/parse.js +426 -0
- package/package.json +18 -20
- package/types/index.d.ts +0 -45
package/dist/flags.js
CHANGED
|
@@ -3,63 +3,97 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.verbose = exports.silent = exports.quiet = exports.networkIdleTimeout = exports.dryRun = exports.disableCache = exports.debug = exports.config = exports.allowedHostnames = exports.PERCY = exports.GLOBAL = exports.DISCOVERY = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _logger = _interopRequireDefault(require("@percy/logger"));
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
const logging = {
|
|
12
|
-
verbose: _command.flags.boolean({
|
|
13
|
-
char: 'v',
|
|
14
|
-
description: 'log everything',
|
|
15
|
-
exclusive: ['quiet', 'silent']
|
|
16
|
-
}),
|
|
17
|
-
quiet: _command.flags.boolean({
|
|
18
|
-
char: 'q',
|
|
19
|
-
description: 'log errors only',
|
|
20
|
-
exclusive: ['verbose', 'silent']
|
|
21
|
-
}),
|
|
22
|
-
silent: _command.flags.boolean({
|
|
23
|
-
description: 'log nothing',
|
|
24
|
-
exclusive: ['verbose', 'quiet']
|
|
25
|
-
})
|
|
26
|
-
}; // Common asset discovery flags.
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
11
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
'
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
'
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
12
|
+
// Global CLI flags
|
|
13
|
+
const verbose = {
|
|
14
|
+
name: 'verbose',
|
|
15
|
+
description: 'Log everything',
|
|
16
|
+
exclusive: ['quiet', 'silent'],
|
|
17
|
+
parse: () => !!_logger.default.loglevel('debug'),
|
|
18
|
+
group: 'Global',
|
|
19
|
+
short: 'v'
|
|
20
|
+
};
|
|
21
|
+
exports.verbose = verbose;
|
|
22
|
+
const quiet = {
|
|
23
|
+
name: 'quiet',
|
|
24
|
+
description: 'Log errors only',
|
|
25
|
+
exclusive: ['verbose', 'silent'],
|
|
26
|
+
parse: () => !!_logger.default.loglevel('warn'),
|
|
27
|
+
group: 'Global',
|
|
28
|
+
short: 'q'
|
|
29
|
+
};
|
|
30
|
+
exports.quiet = quiet;
|
|
31
|
+
const silent = {
|
|
32
|
+
name: 'silent',
|
|
33
|
+
description: 'Log nothing',
|
|
34
|
+
exclusive: ['verbose', 'quiet'],
|
|
35
|
+
parse: () => !!_logger.default.loglevel('silent'),
|
|
36
|
+
group: 'Global',
|
|
37
|
+
short: 's'
|
|
38
|
+
}; // Common percy and asset discovery flags
|
|
52
39
|
|
|
40
|
+
exports.silent = silent;
|
|
53
41
|
const config = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
42
|
+
name: 'config',
|
|
43
|
+
description: 'Config file path',
|
|
44
|
+
percyrc: 'config',
|
|
45
|
+
type: 'file',
|
|
46
|
+
group: 'Percy',
|
|
47
|
+
short: 'c'
|
|
48
|
+
};
|
|
49
|
+
exports.config = config;
|
|
50
|
+
const dryRun = {
|
|
51
|
+
name: 'dry-run',
|
|
52
|
+
description: 'Print snapshot names only',
|
|
53
|
+
percyrc: 'dryRun',
|
|
54
|
+
group: 'Percy',
|
|
55
|
+
short: 'd'
|
|
64
56
|
};
|
|
65
|
-
exports.
|
|
57
|
+
exports.dryRun = dryRun;
|
|
58
|
+
const allowedHostnames = {
|
|
59
|
+
name: 'allowed-hostname',
|
|
60
|
+
description: 'Allowed hostnames to capture in asset discovery',
|
|
61
|
+
percyrc: 'discovery.allowedHostnames',
|
|
62
|
+
type: 'hostname',
|
|
63
|
+
multiple: true,
|
|
64
|
+
group: 'Percy',
|
|
65
|
+
short: 'h'
|
|
66
|
+
};
|
|
67
|
+
exports.allowedHostnames = allowedHostnames;
|
|
68
|
+
const networkIdleTimeout = {
|
|
69
|
+
name: 'network-idle-timeout',
|
|
70
|
+
description: 'Asset discovery network idle timeout',
|
|
71
|
+
percyrc: 'discovery.networkIdleTimeout',
|
|
72
|
+
type: 'ms',
|
|
73
|
+
parse: Number,
|
|
74
|
+
group: 'Percy',
|
|
75
|
+
short: 't'
|
|
76
|
+
};
|
|
77
|
+
exports.networkIdleTimeout = networkIdleTimeout;
|
|
78
|
+
const disableCache = {
|
|
79
|
+
name: 'disable-cache',
|
|
80
|
+
description: 'Disable asset discovery caches',
|
|
81
|
+
percyrc: 'discovery.disableCache',
|
|
82
|
+
group: 'Percy'
|
|
83
|
+
};
|
|
84
|
+
exports.disableCache = disableCache;
|
|
85
|
+
const debug = {
|
|
86
|
+
name: 'debug',
|
|
87
|
+
description: 'Debug asset discovery and do not upload snapshots',
|
|
88
|
+
parse: () => !!_logger.default.loglevel('debug'),
|
|
89
|
+
percyrc: 'skipUploads',
|
|
90
|
+
group: 'Percy'
|
|
91
|
+
}; // Group constants
|
|
92
|
+
|
|
93
|
+
exports.debug = debug;
|
|
94
|
+
const GLOBAL = [verbose, quiet, silent];
|
|
95
|
+
exports.GLOBAL = GLOBAL;
|
|
96
|
+
const PERCY = [config, dryRun];
|
|
97
|
+
exports.PERCY = PERCY;
|
|
98
|
+
const DISCOVERY = [allowedHostnames, networkIdleTimeout, disableCache, debug];
|
|
99
|
+
exports.DISCOVERY = DISCOVERY;
|
package/dist/help.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.flagUsage = flagUsage;
|
|
8
|
+
exports.formatHelp = formatHelp;
|
|
9
|
+
|
|
10
|
+
var _logger = _interopRequireDefault(require("@percy/logger"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
// Helper to return an argument's description including it's default value.
|
|
15
|
+
function argumentDescription(arg) {
|
|
16
|
+
let desc = arg.description || '';
|
|
17
|
+
|
|
18
|
+
if (arg.default != null) {
|
|
19
|
+
desc += ` (default: ${JSON.stringify(arg.default)})`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return desc.trim();
|
|
23
|
+
} // Helper to return an array of visible argument usage-description pairs.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async function visibleArguments(command) {
|
|
27
|
+
var _command$definition$a;
|
|
28
|
+
|
|
29
|
+
let args = (_command$definition$a = command.definition.args) !== null && _command$definition$a !== void 0 ? _command$definition$a : []; // not hidden and not deprecated
|
|
30
|
+
|
|
31
|
+
let visible = args.reduce((visible, arg) => {
|
|
32
|
+
if (arg.hidden || arg.deprecated) return visible;
|
|
33
|
+
visible.push([arg.name, argumentDescription(arg)]);
|
|
34
|
+
return visible;
|
|
35
|
+
}, []); // do not return any arguments if none have descriptions
|
|
36
|
+
|
|
37
|
+
if (!visible.some(([, desc]) => !!desc)) return [];
|
|
38
|
+
return visible;
|
|
39
|
+
} // Helper to return a command's usage string.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
function commandUsage(command) {
|
|
43
|
+
let {
|
|
44
|
+
name,
|
|
45
|
+
definition
|
|
46
|
+
} = command;
|
|
47
|
+
let {
|
|
48
|
+
usage,
|
|
49
|
+
args,
|
|
50
|
+
commands
|
|
51
|
+
} = definition;
|
|
52
|
+
|
|
53
|
+
if (!command.callback && commands !== null && commands !== void 0 && commands.length) {
|
|
54
|
+
// if there are subcommands but no callback show subcommand usage
|
|
55
|
+
usage || (usage = '<command>');
|
|
56
|
+
} else {
|
|
57
|
+
var _args, _args2;
|
|
58
|
+
|
|
59
|
+
// show options followed by arguments
|
|
60
|
+
args = (_args = args) === null || _args === void 0 ? void 0 : _args.filter(a => !a.hidden && !a.deprecated).map(a => a.required ? `<${a.name}>` : `[${a.name}]`);
|
|
61
|
+
usage || (usage = `[options] ${((_args2 = args) === null || _args2 === void 0 ? void 0 : _args2.join(' ')) || ''}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return `${name} ${usage}`.trim();
|
|
65
|
+
} // Helper to return an array of visible command usage-description pairs.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
async function visibleCommands(command, help) {
|
|
69
|
+
var _command$definition$c;
|
|
70
|
+
|
|
71
|
+
let commands = (_command$definition$c = command.definition.commands) !== null && _command$definition$c !== void 0 ? _command$definition$c : [];
|
|
72
|
+
if (typeof commands === 'function') commands = await commands();
|
|
73
|
+
let visible = [];
|
|
74
|
+
|
|
75
|
+
for (let cmd of commands) {
|
|
76
|
+
// create parent references and format subcommand names
|
|
77
|
+
let name = command.parent ? `${command.name}:${cmd.name}` : cmd.name;
|
|
78
|
+
cmd = { ...cmd,
|
|
79
|
+
name,
|
|
80
|
+
parent: command
|
|
81
|
+
}; // commands without callbacks are not visible themselves
|
|
82
|
+
|
|
83
|
+
if (cmd.callback) {
|
|
84
|
+
let {
|
|
85
|
+
description
|
|
86
|
+
} = cmd.definition;
|
|
87
|
+
visible.push([commandUsage(cmd), description]);
|
|
88
|
+
} // include visible subcommands without their implicit help
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (cmd.definition.commands) {
|
|
92
|
+
visible.push(...(await visibleCommands(cmd, false)));
|
|
93
|
+
}
|
|
94
|
+
} // include implicit help if there are visible commands
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if (help !== false && visible.length) {
|
|
98
|
+
visible.push(['help [command]', 'Display command help']);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return visible;
|
|
102
|
+
} // Helper to return an flags's description including it's default value.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
function flagDescription(flag) {
|
|
106
|
+
let desc = flag.description || ''; // a boolean that defaults to false will be displayed with a --no prefix
|
|
107
|
+
|
|
108
|
+
if (flag.type && flag.type !== 'boolean' && flag.default != null) {
|
|
109
|
+
desc += ` (default: ${JSON.stringify(flag.default)})`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return desc.trim();
|
|
113
|
+
} // Helper to return a flag's usage string.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
function flagUsage(flag) {
|
|
117
|
+
let {
|
|
118
|
+
short,
|
|
119
|
+
usage,
|
|
120
|
+
type
|
|
121
|
+
} = flag;
|
|
122
|
+
let term = flag.name ? `--${flag.name}` : '';
|
|
123
|
+
|
|
124
|
+
if (type && type !== 'boolean') {
|
|
125
|
+
// if there is a default it is not required
|
|
126
|
+
usage || (usage = flag.default != null ? `[${type}]` : `<${type}>`);
|
|
127
|
+
} else if (flag.default === true) {
|
|
128
|
+
// negated booleans have a prefix
|
|
129
|
+
term && (term = `--no-${flag.name}`);
|
|
130
|
+
} // add short flag usage
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if (short) term = `-${short}${term ? `, ${term}` : ''}`;
|
|
134
|
+
return `${term} ${usage || ''}`.trim();
|
|
135
|
+
} // Helper to return an array of visible flag usage-description pairs. A third entry is also included
|
|
136
|
+
// with the returned pair representing any group the flag should belong to.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
async function visibleFlags(command) {
|
|
140
|
+
let flags = command.definition.flags; // not hidden and not deprecated
|
|
141
|
+
|
|
142
|
+
let visible = flags.reduce((visible, flag) => {
|
|
143
|
+
if (flag.hidden || flag.deprecated) return visible;
|
|
144
|
+
visible.push([flagUsage(flag), flagDescription(flag), flag.group]);
|
|
145
|
+
return visible;
|
|
146
|
+
}, []); // maybe hide the implicit help long or short flag (or both)
|
|
147
|
+
|
|
148
|
+
let showLongHelpFlag = !flags.some(f => f.name === 'help');
|
|
149
|
+
let showShortHelpFlag = !flags.some(f => f.short === 'h');
|
|
150
|
+
|
|
151
|
+
if (showLongHelpFlag || showShortHelpFlag) {
|
|
152
|
+
let help = {
|
|
153
|
+
name: 'help',
|
|
154
|
+
short: 'h'
|
|
155
|
+
};
|
|
156
|
+
if (!showLongHelpFlag) delete help.name;
|
|
157
|
+
if (!showShortHelpFlag) delete help.short;
|
|
158
|
+
visible.push([flagUsage(help), 'Display command help', 'Global']);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (command.definition.version) {
|
|
162
|
+
// maybe hide the implicit version long or short flag (or both)
|
|
163
|
+
let showLongVerFlag = !flags.some(f => f.name === 'version');
|
|
164
|
+
let showShortVerFlag = !flags.some(f => f.short === 'V');
|
|
165
|
+
|
|
166
|
+
if (showLongVerFlag || showShortVerFlag) {
|
|
167
|
+
let ver = {
|
|
168
|
+
name: 'version',
|
|
169
|
+
short: 'V'
|
|
170
|
+
};
|
|
171
|
+
if (!showLongVerFlag) delete ver.name;
|
|
172
|
+
if (!showShortVerFlag) delete ver.short;
|
|
173
|
+
visible.push([flagUsage(ver), 'Display version', 'Global']);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return visible;
|
|
178
|
+
} // Helper to wrap a string at a length by inserting a newline between every segment.
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
function wrapString(str, len) {
|
|
182
|
+
let regex = new RegExp(`.{1,${len - 1}}(\\s|$)|\\S+?(\\s|$)`, 'g');
|
|
183
|
+
return str.replace(regex, s => s.replace(/\s*\n?$/, str.endsWith(s) ? '' : '\n'));
|
|
184
|
+
} // Helper to format an option usage-description pair into a single string where the description
|
|
185
|
+
// wraps within the available space beside the usage string.
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
function formatOptionHelp(option, usageWidth, maxWidth) {
|
|
189
|
+
if (!option[1]) return option[0]; // calculate the available description width, at minimum 40
|
|
190
|
+
|
|
191
|
+
let descWidth = Math.max(maxWidth - usageWidth, 40); // pad usage up to the description and indent the description
|
|
192
|
+
|
|
193
|
+
return option[0].padEnd(usageWidth) + wrapString(option[1], descWidth).replace(/\n+/gm, `$&${' '.repeat(usageWidth)}`);
|
|
194
|
+
} // Returns a formatted string displaying help output for the specified command. The help output
|
|
195
|
+
// total width is determined by the logger's stdout TTY columns. Help output includes the command
|
|
196
|
+
// description, usage, arguments, subcommand usage and descriptions, flag and flag group usage and
|
|
197
|
+
// descriptions, and any command examples.
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
async function formatHelp(command) {
|
|
201
|
+
var _examples, _examples2;
|
|
202
|
+
|
|
203
|
+
let {
|
|
204
|
+
name,
|
|
205
|
+
parent: top,
|
|
206
|
+
definition
|
|
207
|
+
} = command;
|
|
208
|
+
let {
|
|
209
|
+
description,
|
|
210
|
+
examples
|
|
211
|
+
} = definition;
|
|
212
|
+
let output = []; // collect visible items first to determine max usage width
|
|
213
|
+
|
|
214
|
+
let args = await visibleArguments(command);
|
|
215
|
+
let commands = await visibleCommands(command);
|
|
216
|
+
let flags = await visibleFlags(command); // maximum help output total width
|
|
217
|
+
|
|
218
|
+
let maxWidth = _logger.default.stdout.columns || 100; // calculate the longest usage width
|
|
219
|
+
|
|
220
|
+
let usageWidth = Math.max(args.reduce((max, [usage]) => Math.max(max, usage.length), 0), commands.reduce((max, [usage]) => Math.max(max, usage.length), 0), flags.reduce((max, [usage]) => Math.max(max, usage.length), 0)); // format lists of options and add appropriate indentation
|
|
221
|
+
|
|
222
|
+
let formatList = items => items.map(item => Array.isArray(item) ? // indent items and separate columns by 2 spaces each
|
|
223
|
+
formatOptionHelp(item, usageWidth + 2, maxWidth - 2) : item).join('\n').replace(/^(?!$)/gm, ' '.repeat(2)); // format the command name to include the topmost command name
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
while ((_top = top) !== null && _top !== void 0 && _top.parent) {
|
|
227
|
+
var _top;
|
|
228
|
+
|
|
229
|
+
top = top.parent;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (top) name = `${top.name} ${name}`;
|
|
233
|
+
command = { ...command,
|
|
234
|
+
name
|
|
235
|
+
}; // include command description and own usage
|
|
236
|
+
|
|
237
|
+
if (description) output.push(wrapString(description, maxWidth), '');
|
|
238
|
+
output.push('Usage:', formatList([`$ ${commandUsage(command)}`]), ''); // include command arguments
|
|
239
|
+
|
|
240
|
+
if (args.length) output.push('Arguments:', formatList(args), ''); // include command subcommands
|
|
241
|
+
|
|
242
|
+
let commandGroupName = command.parent ? 'Subcommands:' : 'Commands:';
|
|
243
|
+
if (commands.length) output.push(commandGroupName, formatList(commands), ''); // separate flags into groups
|
|
244
|
+
|
|
245
|
+
let groups = flags.reduce((all, option) => {
|
|
246
|
+
let group = option[2] ? `${option[2]} options` : 'Options';
|
|
247
|
+
return all.set(group, [...(all.get(group) || []), option]);
|
|
248
|
+
}, new Map([['Options', []]])); // include each group of command flags
|
|
249
|
+
|
|
250
|
+
for (let [group, flags] of groups.entries()) {
|
|
251
|
+
if (flags.length) output.push(`${group}:`, formatList(flags), '');
|
|
252
|
+
} // include command examples and replace '$0' with the command name
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
examples = (_examples = examples) === null || _examples === void 0 ? void 0 : _examples.map(ex => ex.replace('$0', `$ ${name}`));
|
|
256
|
+
if ((_examples2 = examples) !== null && _examples2 !== void 0 && _examples2.length) output.push('Examples:', formatList(examples), ''); // join each line of output
|
|
257
|
+
|
|
258
|
+
return output.join('\n');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
var _default = formatHelp;
|
|
262
|
+
exports.default = _default;
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "command", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _command.command;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "default", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -12,12 +18,20 @@ Object.defineProperty(exports, "default", {
|
|
|
12
18
|
Object.defineProperty(exports, "flags", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function () {
|
|
15
|
-
return
|
|
21
|
+
return _legacy.legacyFlags;
|
|
16
22
|
}
|
|
17
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "legacyCommand", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _legacy.legacyCommand;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
var _command = _interopRequireWildcard(require("./command"));
|
|
18
32
|
|
|
19
|
-
var
|
|
33
|
+
var _legacy = require("./legacy");
|
|
20
34
|
|
|
21
|
-
var
|
|
35
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
36
|
|
|
23
|
-
function
|
|
37
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/dist/legacy.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.legacyCommand = legacyCommand;
|
|
8
|
+
exports.legacyFlags = void 0;
|
|
9
|
+
|
|
10
|
+
var _command = require("./command");
|
|
11
|
+
|
|
12
|
+
var _utils = require("@percy/config/dist/utils");
|
|
13
|
+
|
|
14
|
+
// Legacy flags for older commands that inadvertently import a newer @percy/cli-command
|
|
15
|
+
const legacyFlags = {
|
|
16
|
+
config: {},
|
|
17
|
+
logging: {},
|
|
18
|
+
discovery: {
|
|
19
|
+
__percy__: {}
|
|
20
|
+
},
|
|
21
|
+
string: def => ({
|
|
22
|
+
type: 'string',
|
|
23
|
+
...def
|
|
24
|
+
}),
|
|
25
|
+
boolean: def => ({
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
...def
|
|
28
|
+
}),
|
|
29
|
+
integer: def => ({
|
|
30
|
+
type: 'integer',
|
|
31
|
+
...def
|
|
32
|
+
})
|
|
33
|
+
}; // Maps a legacy arg that might have alternate properties
|
|
34
|
+
|
|
35
|
+
exports.legacyFlags = legacyFlags;
|
|
36
|
+
|
|
37
|
+
function legacyArg(legacy) {
|
|
38
|
+
let {
|
|
39
|
+
name,
|
|
40
|
+
...def
|
|
41
|
+
} = legacy; // do not camelcase legacy attribute names
|
|
42
|
+
|
|
43
|
+
def.attribute = name; // add name back to mapped options
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
...def
|
|
48
|
+
};
|
|
49
|
+
} // Maps a legacy flag that might have alternate properties
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
function legacyFlag(name, legacy) {
|
|
53
|
+
let {
|
|
54
|
+
char: short,
|
|
55
|
+
deprecated,
|
|
56
|
+
...def
|
|
57
|
+
} = legacy; // generic legacy type looks odd in help output
|
|
58
|
+
|
|
59
|
+
if (def.type === 'option') def.type = 'value'; // do not camelcase legacy attribute names
|
|
60
|
+
|
|
61
|
+
def.attribute = name; // transform legacy deprecated syntax
|
|
62
|
+
|
|
63
|
+
if (deprecated) {
|
|
64
|
+
let {
|
|
65
|
+
until,
|
|
66
|
+
map,
|
|
67
|
+
alt
|
|
68
|
+
} = deprecated !== true ? deprecated : {};
|
|
69
|
+
def.deprecated = [until, map ? `--${map}` : alt];
|
|
70
|
+
} // add name and mapped short option
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
name,
|
|
75
|
+
short,
|
|
76
|
+
...def
|
|
77
|
+
};
|
|
78
|
+
} // Maps a legacy class-based command to the new functional syntax
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
function legacyCommand(name, constructor) {
|
|
82
|
+
var _constructor$args, _constructor$flags, _constructor$flags$__, _constructor$flags2;
|
|
83
|
+
|
|
84
|
+
let runner = (0, _command.command)(name, {
|
|
85
|
+
description: constructor.description,
|
|
86
|
+
examples: constructor.examples,
|
|
87
|
+
// map legacy args and flags
|
|
88
|
+
args: (_constructor$args = constructor.args) === null || _constructor$args === void 0 ? void 0 : _constructor$args.map(legacyArg),
|
|
89
|
+
flags: Object.entries((_constructor$flags = constructor.flags) !== null && _constructor$flags !== void 0 ? _constructor$flags : []).map(([name, def]) => legacyFlag(name, def)).filter(({
|
|
90
|
+
name
|
|
91
|
+
}) => name !== '__percy__'),
|
|
92
|
+
percy: (_constructor$flags$__ = (_constructor$flags2 = constructor.flags) === null || _constructor$flags2 === void 0 ? void 0 : _constructor$flags2.__percy__) !== null && _constructor$flags$__ !== void 0 ? _constructor$flags$__ : true,
|
|
93
|
+
loose: constructor.strict === false,
|
|
94
|
+
legacy: true
|
|
95
|
+
}, async function* (ctx) {
|
|
96
|
+
let instance = new constructor();
|
|
97
|
+
let error; // not an instance of the constructor, create one ourself
|
|
98
|
+
|
|
99
|
+
if (!(instance instanceof constructor)) {
|
|
100
|
+
instance = Object.create(constructor.prototype);
|
|
101
|
+
} // alias legacy global flags attribute names when necessary
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if (ctx.flags.dryRun) ctx.flags['dry-run'] = ctx.flags.dryRun; // legacy percyrc value
|
|
105
|
+
|
|
106
|
+
let percyrc = overrides => (0, _utils.merge)([ctx.percy.config, overrides, {
|
|
107
|
+
skipUploads: ctx.flags.debug,
|
|
108
|
+
dryRun: ctx.flags['dry-run'],
|
|
109
|
+
config: false
|
|
110
|
+
}], (path, prev, next) => // do not merge arrays
|
|
111
|
+
Array.isArray(next) && [path, next]); // augment legacy instance properties
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
Object.defineProperties(instance, {
|
|
115
|
+
isPercyEnabled: {
|
|
116
|
+
value: () => !!ctx.percy
|
|
117
|
+
},
|
|
118
|
+
error: {
|
|
119
|
+
value: msg => ctx.exit(1, msg)
|
|
120
|
+
},
|
|
121
|
+
parse: {
|
|
122
|
+
value: () => ctx
|
|
123
|
+
},
|
|
124
|
+
percyrc: {
|
|
125
|
+
value: percyrc
|
|
126
|
+
},
|
|
127
|
+
flags: {
|
|
128
|
+
value: ctx.flags
|
|
129
|
+
},
|
|
130
|
+
args: {
|
|
131
|
+
value: ctx.args
|
|
132
|
+
},
|
|
133
|
+
exit: {
|
|
134
|
+
value: ctx.exit
|
|
135
|
+
},
|
|
136
|
+
log: {
|
|
137
|
+
value: ctx.log
|
|
138
|
+
}
|
|
139
|
+
}); // legacy signal handling
|
|
140
|
+
|
|
141
|
+
let signals = ['SIGHUP', 'SIGINT', 'SIGTERM'];
|
|
142
|
+
|
|
143
|
+
let cleanup = () => {
|
|
144
|
+
var _instance$finally, _instance;
|
|
145
|
+
|
|
146
|
+
return (_instance$finally = (_instance = instance).finally) === null || _instance$finally === void 0 ? void 0 : _instance$finally.call(_instance, new Error('SIGTERM'));
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
for (let e of signals) process.on(e, cleanup); // run and handle legacy command
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
yield instance.run();
|
|
154
|
+
} catch (err) {
|
|
155
|
+
throw error = err;
|
|
156
|
+
} finally {
|
|
157
|
+
var _instance$finally2, _instance2;
|
|
158
|
+
|
|
159
|
+
await ((_instance$finally2 = (_instance2 = instance).finally) === null || _instance$finally2 === void 0 ? void 0 : _instance$finally2.call(_instance2, error));
|
|
160
|
+
|
|
161
|
+
for (let e of signals) process.off(e, cleanup);
|
|
162
|
+
}
|
|
163
|
+
}); // throw legacy errors for test compatibility
|
|
164
|
+
|
|
165
|
+
return Object.defineProperties(args => runner(args).catch(e => {
|
|
166
|
+
throw new Error(`EEXIT: ${e.exitCode}`);
|
|
167
|
+
}), Object.getOwnPropertyDescriptors(runner));
|
|
168
|
+
} // Support the legacy static run method
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
_command.command.run = function run(args) {
|
|
172
|
+
return legacyCommand('legacy', this)(args);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
var _default = legacyCommand;
|
|
176
|
+
exports.default = _default;
|