-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateFootprintPathInNode.js
More file actions
28 lines (22 loc) · 991 Bytes
/
updateFootprintPathInNode.js
File metadata and controls
28 lines (22 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function updateFootprintPathInNode(node, projectName) {
if (node.type === 'list') {
// Check if this is a Footprint property
if (node.items.length >= 3 &&
node.items[0].type === 'atom' && node.items[0].value === 'property' &&
node.items[1].type === 'atom' && node.items[1].value === '"Footprint"' &&
node.items[2].type === 'atom') {
// Extract the current footprint path
let footprintPath = node.items[2].value.replace(/^"|"$/g, ''); // Remove quotes
// If path already has a prefix, remove it
if (footprintPath.includes(':')) {
footprintPath = footprintPath.split(':')[1];
}
// Update the footprint path with new prefix
node.items[2].value = `"${projectName}:${footprintPath}"`;
}
// Recursively process all items in the list
node.items.forEach(item => updateFootprintPathInNode(item, projectName));
}
return node;
}
module.exports = updateFootprintPathInNode;