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).

115 lines (114 loc) 4.77 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.handleListOperation = handleListOperation; const fs = __importStar(require("fs/promises")); const path = __importStar(require("path")); const constants_1 = require("../constants"); async function printDirectoryTree(dir, prefix) { let entries; try { entries = await fs.readdir(dir, { withFileTypes: true }); } catch (error) { if (error.code === 'ENOENT') { return false; } console.error(`CRITICAL ERROR: Could not read directory '${dir}'. Details: ${error.message}`); throw error; } const dirs = entries .filter((e) => e.isDirectory()) .sort((a, b) => a.name.localeCompare(b.name)); const files = entries .filter((e) => e.isFile() && e.name.endsWith(constants_1.TAYLORED_FILE_EXTENSION)) .sort((a, b) => a.name.localeCompare(b.name)); const sortedEntries = [...dirs, ...files]; let foundTayloredFiles = false; for (let i = 0; i < sortedEntries.length; i++) { const entry = sortedEntries[i]; const isLastEntry = i === sortedEntries.length - 1; const connector = isLastEntry ? '└── ' : '├── '; const entryPath = path.join(dir, entry.name); if (entry.isDirectory()) { console.log(`${prefix}${connector}📁 ${entry.name}/`); const subDirPrefix = prefix + (isLastEntry ? ' ' : '│ '); if (await printDirectoryTree(entryPath, subDirPrefix)) { foundTayloredFiles = true; } } else if (entry.isFile() && entry.name.endsWith(constants_1.TAYLORED_FILE_EXTENSION)) { console.log(`${prefix}${connector}📄 ${entry.name}`); foundTayloredFiles = true; } } return foundTayloredFiles; } async function handleListOperation(CWD) { const tayloredDirPath = path.join(CWD, constants_1.TAYLORED_DIR_NAME); console.log(`INFO: Listing contents of '${tayloredDirPath}'...\n`); try { const stats = await fs.stat(tayloredDirPath); if (!stats.isDirectory()) { console.log(`INFO: Expected '${constants_1.TAYLORED_DIR_NAME}' to be a directory, but it's not (found at '${tayloredDirPath}').`); console.log('No taylored files or directories to list.'); return; } } catch (statError) { if (statError.code === 'ENOENT') { console.log(`INFO: Directory '${constants_1.TAYLORED_DIR_NAME}' not found at '${tayloredDirPath}'.`); console.log('No taylored files or directories to list.'); return; } console.error(`CRITICAL ERROR: Could not access directory '${tayloredDirPath}'. Details: ${statError.message}`); throw statError; } console.log(`📁 ${constants_1.TAYLORED_DIR_NAME}/`); const foundAnyTayloredFiles = await printDirectoryTree(tayloredDirPath, ''); if (!foundAnyTayloredFiles) { try { const entries = await fs.readdir(tayloredDirPath); if (entries.length === 0) { console.log(' └── (empty)'); } } catch (e) { } } if (!foundAnyTayloredFiles) { console.log(`\nINFO: No ${constants_1.TAYLORED_FILE_EXTENSION} files found in '${tayloredDirPath}' or its subdirectories.`); } }