@interopio/desktop-cli
Version:
io.Connect Desktop Seed Repository CLI Tools
145 lines • 6.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IocdComponentProcessor = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const glob_1 = require("glob");
const utils_1 = require("../../utils");
const base_component_processor_1 = require("../base/base-component-processor");
const component_1 = require("../../types/component");
/**
* IOCD-specific component processor with comprehensive modification handling
*/
class IocdComponentProcessor extends base_component_processor_1.BaseComponentProcessor {
constructor(config = component_1.DEFAULT_IOCD_CONFIG) {
super(config);
}
// Override the base scanning to use only general modifications
async scanModifications() {
const operations = [];
const modDir = this.getModificationDir();
if (!(await utils_1.FileUtils.exists(modDir))) {
return operations;
}
// Use only general overrides (mirroring component structure)
const generalOps = await this.scanGeneralOverrides();
operations.push(...generalOps);
return operations;
}
/**
* General override scanning (simplified - no reserved directories)
*/
async scanGeneralOverrides() {
const operations = [];
const modDir = this.getModificationDir();
if (!(await utils_1.FileUtils.exists(modDir)))
return operations;
// No reserved directories - everything is treated as direct path mirroring
let topEntries = [];
try {
topEntries = (await fs_extra_1.default.readdir(modDir)).map(e => path_1.default.join(modDir, e));
}
catch {
return operations;
}
for (const entry of topEntries) {
const name = path_1.default.basename(entry);
// Only process explicit delete markers
if (name.endsWith('.delete')) {
const targetDir = path_1.default.join(this.getComponentDir(), name.replace(/\.delete$/, ''));
operations.push({ type: 'delete', source: entry, target: targetDir, isDirectory: true });
continue;
}
}
const pattern = path_1.default.join(modDir, '**', '*').replace(/\\/g, '/');
const files = await (0, glob_1.glob)(pattern, { dot: true, nodir: false });
for (const filePath of files) {
const relative = path_1.default.relative(modDir, filePath);
if (!relative)
continue;
const base = path_1.default.basename(filePath);
const stat = await fs_extra_1.default.stat(filePath);
if (stat.isDirectory())
continue;
// File delete marker: <file>.delete
if (base.endsWith('.delete')) {
const target = path_1.default.join(this.getComponentDir(), relative.replace(/\.delete$/, ''));
operations.push({ type: 'delete', source: filePath, target, isDirectory: false });
continue;
}
// All other files are direct replacements
const target = path_1.default.join(this.getComponentDir(), relative);
operations.push({ type: 'copy', source: filePath, target, isDirectory: false });
}
return operations;
}
// Override apply modifications to use simplified IOCD-specific logic
async applyModifications() {
const operations = await this.scanModifications();
if (operations.length === 0) {
utils_1.Logger.debug(`No modifications found for ${this.config.displayName}`);
return;
}
utils_1.Logger.info(`Applying ${operations.length} modification(s) for ${this.config.displayName}...`);
for (const operation of operations) {
await this.applyIocdOperation(operation);
}
}
// IOCD-specific operation application
async applyIocdOperation(operation) {
try {
switch (operation.type) {
case 'copy':
await this.applyIocdCopy(operation);
break;
case 'delete':
await this.applyIocdDelete(operation);
break;
default:
utils_1.Logger.warning(`Unknown operation type for ${this.config.displayName}: ${operation.type}`);
}
}
catch (error) {
utils_1.Logger.error(`Failed to apply ${operation.type} operation for ${this.config.displayName}: ${error instanceof Error ? error.message : String(error)}`);
throw error;
}
}
// IOCD-specific copy operation
async applyIocdCopy(operation) {
await fs_extra_1.default.ensureDir(path_1.default.dirname(operation.target));
await fs_extra_1.default.copy(operation.source, operation.target);
const fileName = path_1.default.basename(operation.target);
if (fileName.endsWith('.merge.json')) {
utils_1.Logger.info(`IOCD: Applied merge file: ${fileName}`);
}
else {
utils_1.Logger.info(`IOCD: Copied file: ${fileName}`);
}
}
// IOCD-specific delete operation
async applyIocdDelete(operation) {
if (await utils_1.FileUtils.exists(operation.target)) {
await fs_extra_1.default.remove(operation.target);
utils_1.Logger.info(`IOCD: Deleted file: ${path_1.default.basename(operation.target)}`);
}
}
// IOCD-specific validation
async validateModifications() {
const operations = await this.scanModifications();
let isValid = true;
for (const operation of operations) {
if (operation.type === 'copy') {
if (!(await utils_1.FileUtils.exists(operation.source))) {
utils_1.Logger.error(`IOCD: Source file not found: ${operation.source}`);
isValid = false;
}
}
}
return isValid;
}
}
exports.IocdComponentProcessor = IocdComponentProcessor;
//# sourceMappingURL=iocd-component-processor.js.map