generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jitPluginInstall.ts
54 lines (48 loc) · 1.78 KB
/
jitPluginInstall.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
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { homedir } from 'node:os';
import { Hook } from '@oclif/core';
import { SfError } from '@salesforce/core';
import type { TelemetryGlobal } from '@salesforce/plugin-telemetry/lib/telemetryGlobal.js';
declare const global: TelemetryGlobal;
const hook: Hook<'jit_plugin_not_installed'> = async function (opts) {
try {
global.cliTelemetry?.record({
eventName: 'JIT_INSTALL_STARTED',
type: 'EVENT',
version: opts.pluginVersion,
plugin: opts.command.pluginName,
command: opts.command.id,
});
const jitInstallArgv = [`${opts.command.pluginName}@${opts.pluginVersion}`];
if (opts.argv.includes('--json')) {
// pass along --json arg to plugins:install
jitInstallArgv.push('--json');
}
await opts.config.runCommand('plugins:install', jitInstallArgv);
global.cliTelemetry?.record({
eventName: 'JIT_INSTALL_SUCCESS',
type: 'EVENT',
version: opts.pluginVersion,
plugin: opts.command.pluginName,
command: opts.command.id,
});
} catch (error) {
global.cliTelemetry?.record({
eventName: 'JIT_INSTALL_FAILED',
type: 'EVENT',
message: error instanceof Error ? error.message : 'malformed error',
stackTrace:
error instanceof Error ? error?.stack?.replace(new RegExp(homedir(), 'g'), '<GDPR_HIDDEN>') : undefined,
version: opts.pluginVersion,
plugin: opts.command.pluginName,
command: opts.command.id,
});
throw new SfError(`Could not install ${opts.command.pluginName}`, 'JitPluginInstallError');
}
};
export default hook;