UNPKG

@teambit/workspace

Version:
61 lines (58 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CompFiles = void 0; function _component() { const data = require("@teambit/component.sources"); _component = function () { return data; }; return data; } // ts fails when importing it from @teambit/legacy/dist/utils/path. class CompFiles { constructor(id, repository, currentFiles, compDir, modelFiles = []) { this.id = id; this.repository = repository; this.currentFiles = currentFiles; this.compDir = compDir; this.modelFiles = modelFiles; } isModified() { if (!this.modelFiles.length) return false; if (this.currentFiles.length !== this.modelFiles.length) return true; return this.currentFiles.some(file => { const headFile = this.modelFiles.find(h => h.relativePath === file.relative); if (!headFile) return true; return !headFile.file.isEqual(file.toSourceAsLinuxEOL().hash()); }); } getCurrentFiles() { return this.currentFiles; } async getHeadFiles() { return Promise.all(this.modelFiles.map(file => _component().SourceFile.loadFromSourceFileModel(file, this.repository))); } getFilesStatus() { const result = this.currentFiles.reduce((acc, file) => { const headFile = this.modelFiles.find(h => h.relativePath === file.relative); const getType = () => { if (!headFile) return 'new'; if (headFile.file.isEqual(file.toSourceAsLinuxEOL().hash())) return 'unchanged'; return 'modified'; }; acc[file.relative] = getType(); return acc; }, {}); this.modelFiles.forEach(headFile => { const currentFile = this.currentFiles.find(c => c.relative === headFile.relativePath); if (!currentFile) { result[headFile.relativePath] = 'deleted'; } }); return result; } } exports.CompFiles = CompFiles; //# sourceMappingURL=comp-files.js.map