ovm
Version:
OVM is a CLI application for managing Obsidian vaults.
59 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.asyncExecCustomCommand = exports.handlerCommandError = exports.flagsInterceptor = void 0;
const core_1 = require("@inquirer/core");
const core_2 = require("@oclif/core");
const child_process_1 = require("child_process");
const constants_1 = require("./constants");
const env_1 = require("./env");
const logger_1 = require("./logger");
const flagsInterceptor = (flags) => {
const { debug, timestamp } = flags;
(0, logger_1.enableLoggingTimestamp)(timestamp);
(0, logger_1.enableDebugLogLevel)(debug, flags);
return flags;
};
exports.flagsInterceptor = flagsInterceptor;
const handlerCommandError = (error) => {
const ci = process.env.CI?.toLowerCase();
if (ci === 'true' || ci === 'yes' || ci === '1') {
throw error;
}
if (error instanceof core_1.ExitPromptError ||
(error instanceof Error && error.name === 'ExitPromptError')) {
logger_1.logger.debug('Exit prompt error:', { error });
console.log('Selection canceled.');
if (!(0, env_1.isTestEnv)()) {
process.exit(0);
}
}
else {
logger_1.logger.debug('An error occurred while installation:', { error });
return (0, core_2.handle)(error);
}
};
exports.handlerCommandError = handlerCommandError;
const commandInterpolation = (vault, command) => {
const variableRegex = /\{(\d*?)}/g;
const replacer = (match, variable) => {
const variableFunction = constants_1.RESERVED_VARIABLES[variable];
if (variableFunction) {
return variableFunction(vault);
}
else {
return match;
}
};
const interpolatedCommand = command.replace(variableRegex, replacer);
return interpolatedCommand;
};
const asyncExecCustomCommand = async (vault, command, cwd) => new Promise((resolve, reject) => {
(0, child_process_1.exec)(commandInterpolation(vault, command), { cwd }, (error, stdout, stderr) => {
if (error) {
reject(error);
}
resolve(`${stderr}\n${stdout}`);
});
});
exports.asyncExecCustomCommand = asyncExecCustomCommand;
//# sourceMappingURL=command.js.map