UNPKG

taylo

Version:

Make changes to a branch a plugin. A command-line tool to manage and apply plugins '.taylored'. Supports applying, removing, verifying plugins, and generating them from branch (GIT).

78 lines (77 loc) 3.21 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.handleApplyOperation = handleApplyOperation; const fs = __importStar(require("fs/promises")); const path = __importStar(require("path")); const child_process_1 = require("child_process"); const constants_1 = require("./constants"); async function handleApplyOperation(tayloredFileNameWithExt, isVerify, isReverse, modeName, CWD) { const tayloredDir = path.join(CWD, constants_1.TAYLORED_DIR_NAME); const actualTayloredFilePath = path.join(tayloredDir, tayloredFileNameWithExt); try { await fs.access(actualTayloredFilePath); } catch (e) { console.error(`CRITICAL ERROR: Taylored file '${actualTayloredFilePath}' not found or not accessible in '${constants_1.TAYLORED_DIR_NAME}/' directory.`); throw e; } let gitApplyCommand = `git apply --verbose`; if (isVerify) { gitApplyCommand += ' --check'; } else { gitApplyCommand += ' --whitespace=fix'; } gitApplyCommand += ' --reject'; if (isReverse) { gitApplyCommand += ' --reverse'; } gitApplyCommand += ` "${actualTayloredFilePath.replace(/"/g, '\\"')}"`; try { (0, child_process_1.execSync)(gitApplyCommand, { cwd: CWD, stdio: 'inherit' }); } catch (error) { console.error(`\nCRITICAL ERROR: 'git apply' failed during ${modeName} operation.`); if (isVerify) { console.error(' Verification failed. The patch may not apply/revert cleanly (atomicity check failed).'); } else { console.error(' Execution failed. The current directory might be in an inconsistent or partially modified state.'); console.error(' Please check git status and any .rej files created for conflict details.'); } throw error; } }