Ignore context words in artifact names
This commit is contained in:
@ -8,15 +8,12 @@ const ArtifactExporter = {
|
|||||||
lines.forEach(line => {
|
lines.forEach(line => {
|
||||||
const trimmedLine = line.trim();
|
const trimmedLine = line.trim();
|
||||||
|
|
||||||
// Check if this is a directory (ends with /)
|
|
||||||
if (trimmedLine.endsWith('/')) {
|
if (trimmedLine.endsWith('/')) {
|
||||||
currentPath = trimmedLine;
|
currentPath = trimmedLine;
|
||||||
} else if (trimmedLine && !trimmedLine.startsWith('/')) {
|
} else if (trimmedLine && !trimmedLine.startsWith('/')) {
|
||||||
if (line.startsWith(' ')) {
|
if (line.startsWith(' ')) {
|
||||||
// File is indented, so it's in the current directory
|
|
||||||
pathMapping[trimmedLine] = currentPath + trimmedLine;
|
pathMapping[trimmedLine] = currentPath + trimmedLine;
|
||||||
} else {
|
} else {
|
||||||
// File is at root level
|
|
||||||
pathMapping[trimmedLine] = trimmedLine;
|
pathMapping[trimmedLine] = trimmedLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -25,12 +22,57 @@ const ArtifactExporter = {
|
|||||||
return pathMapping;
|
return pathMapping;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
extractFilenamesFromFileMap(fileMap) {
|
||||||
|
const lines = fileMap.split('\n').filter(line => line.trim());
|
||||||
|
const filenames = [];
|
||||||
|
|
||||||
|
lines.forEach(line => {
|
||||||
|
const trimmedLine = line.trim();
|
||||||
|
|
||||||
|
if (trimmedLine.endsWith('/') || !trimmedLine || trimmedLine.startsWith('/')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filename = trimmedLine.replace(/^\s+/, '');
|
||||||
|
if (filename) {
|
||||||
|
filenames.push(filename);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return filenames.sort((a, b) => b.length - a.length);
|
||||||
|
},
|
||||||
|
|
||||||
|
extractFilenameFromArtifactName(artifactName, sortedFilenames) {
|
||||||
|
for (const filename of sortedFilenames) {
|
||||||
|
const lowerArtifactName = artifactName.toLowerCase();
|
||||||
|
const lowerFilename = filename.toLowerCase();
|
||||||
|
|
||||||
|
if (lowerArtifactName.includes(lowerFilename)) {
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return artifactName;
|
||||||
|
},
|
||||||
|
|
||||||
createFinalMapping(artifactCollection, pathMapping) {
|
createFinalMapping(artifactCollection, pathMapping) {
|
||||||
const finalMap = {};
|
const finalMap = {};
|
||||||
Object.entries(artifactCollection).forEach(([filename, content]) => {
|
|
||||||
const fullPath = pathMapping[filename] || filename; // Use filename as-is if not in mapping
|
const sortedFilenames = this.extractFilenamesFromFileMap(Object.keys(pathMapping).join('\n'));
|
||||||
|
|
||||||
|
Object.entries(artifactCollection).forEach(([artifactName, content]) => {
|
||||||
|
const extractedFilename = this.extractFilenameFromArtifactName(artifactName, sortedFilenames);
|
||||||
|
const fullPath = pathMapping[extractedFilename] || extractedFilename;
|
||||||
|
|
||||||
|
if (artifactName !== extractedFilename) {
|
||||||
|
console.log(`Mapped artifact "${artifactName}" -> found filename "${extractedFilename}" -> "${fullPath}"`);
|
||||||
|
} else {
|
||||||
|
console.log(`Mapped artifact "${artifactName}" -> "${fullPath}"`);
|
||||||
|
}
|
||||||
|
|
||||||
finalMap[fullPath] = content;
|
finalMap[fullPath] = content;
|
||||||
});
|
});
|
||||||
|
|
||||||
return finalMap;
|
return finalMap;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -44,17 +86,14 @@ const ArtifactExporter = {
|
|||||||
|
|
||||||
addFilesToZip(zip, finalMap) {
|
addFilesToZip(zip, finalMap) {
|
||||||
Object.entries(finalMap).forEach(([fullPath, content]) => {
|
Object.entries(finalMap).forEach(([fullPath, content]) => {
|
||||||
// Handle directory structure
|
|
||||||
const pathParts = fullPath.split('/');
|
const pathParts = fullPath.split('/');
|
||||||
|
|
||||||
if (pathParts.length > 1) {
|
if (pathParts.length > 1) {
|
||||||
// File is in a directory
|
|
||||||
const filename = pathParts.pop();
|
const filename = pathParts.pop();
|
||||||
const folderPath = pathParts.join('/');
|
const folderPath = pathParts.join('/');
|
||||||
const folder = zip.folder(folderPath);
|
const folder = zip.folder(folderPath);
|
||||||
folder.file(filename, content);
|
folder.file(filename, content);
|
||||||
} else {
|
} else {
|
||||||
// File is at root level
|
|
||||||
zip.file(fullPath, content);
|
zip.file(fullPath, content);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user