UNPKG

ovm

Version:

Obsidian Vaults Manager

84 lines 2.97 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FactoryCommandWithVaults = exports.FactoryCommand = exports.commandInterpolation = exports.asyncExecCustomCommand = void 0; const core_1 = require("@oclif/core"); const child_process_1 = require("child_process"); const os_1 = require("os"); const path_1 = __importDefault(require("path")); const command_1 = require("../utils/command"); const constants_1 = require("../utils/constants"); const DEFAULT_CONFIG_PATH = path_1.default.join((0, os_1.homedir)(), constants_1.OVM_CONFIG_FILENAME); const commonFlags = { debug: core_1.Flags.boolean({ char: 'd', default: false, description: 'Enable debugging mode.', }), timestamp: core_1.Flags.boolean({ char: 't', default: false, description: 'Enable timestamp in logs.', }), config: core_1.Flags.file({ char: 'c', description: `Path to the config file.`, default: DEFAULT_CONFIG_PATH, required: false, }), }; class FactoryCommand extends core_1.Command { static commonFlags = commonFlags; run() { throw new Error('Method not implemented.'); } handleError(error) { (0, command_1.handlerCommandError)(error); } } exports.FactoryCommand = FactoryCommand; class FactoryCommandWithVaults extends core_1.Command { static commonFlagsWithPath = { ...FactoryCommand.commonFlags, path: core_1.Flags.string({ char: 'p', description: constants_1.VAULTS_PATH_FLAG_DESCRIPTION, default: '', }), }; static commonFlags = FactoryCommandWithVaults.commonFlagsWithPath; run() { throw new Error('Method not implemented.'); } handleError(error) { (0, command_1.handlerCommandError)(error); } } exports.FactoryCommandWithVaults = FactoryCommandWithVaults; 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; }; exports.commandInterpolation = commandInterpolation; 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