@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
46 lines • 1.75 kB
JavaScript
import { postrun as deprecationsHook } from './deprecations.js';
import { reportAnalyticsEvent } from '../analytics.js';
import { outputDebug } from '../../../public/node/output.js';
import * as metadata from '../../../public/node/metadata.js';
let postRunHookCompleted = false;
/**
* Check if post run hook has completed.
*
* @returns Whether post run hook has completed.
*/
export function postRunHookHasCompleted() {
return postRunHookCompleted;
}
// This hook is called after each successful command run. More info: https://oclif.io/docs/hooks
export const hook = async ({ config, Command }) => {
await detectStopCommand(Command);
await reportAnalyticsEvent({ config, exitMode: 'ok' });
deprecationsHook(Command);
const command = Command.id.replace(/:/g, ' ');
outputDebug(`Completed command ${command}`);
postRunHookCompleted = true;
};
/**
* Override the command name with the stop one for analytics purposes.
*
* @param commandClass - Oclif command class.
*/
async function detectStopCommand(commandClass) {
const currentTime = new Date().getTime();
if (commandClass && Object.prototype.hasOwnProperty.call(commandClass, 'analyticsStopCommand')) {
const stopCommand = commandClass.analyticsStopCommand();
if (stopCommand) {
const { commandStartOptions } = metadata.getAllSensitiveMetadata();
if (!commandStartOptions)
return;
await metadata.addSensitiveMetadata(() => ({
commandStartOptions: {
...commandStartOptions,
startTime: currentTime,
startCommand: stopCommand,
},
}));
}
}
}
//# sourceMappingURL=postrun.js.map