@locofy/mcp 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -34,17 +34,16 @@ export async function runPullComponentsTool(args) {
|
|
|
34
34
|
// Check for code changes and mark changed files
|
|
35
35
|
await checkForCodeChanges(result.data);
|
|
36
36
|
// clean the directory structure
|
|
37
|
-
const cleanedResult =
|
|
38
|
-
const resultJSON = cleanedResult;
|
|
37
|
+
const cleanedResult = processDirectoryStructure(result.data);
|
|
39
38
|
// write resultJSON to a file
|
|
40
39
|
if (process.env.DEBUG_MODE === 'true') {
|
|
41
|
-
fs.writeFileSync('result.json', JSON.stringify(
|
|
40
|
+
fs.writeFileSync('result.json', JSON.stringify(cleanedResult, null, 2));
|
|
42
41
|
}
|
|
43
42
|
return {
|
|
44
43
|
content: [
|
|
45
44
|
{
|
|
46
45
|
type: 'text',
|
|
47
|
-
text: JSON.stringify(
|
|
46
|
+
text: JSON.stringify(cleanedResult, null, 2)
|
|
48
47
|
}
|
|
49
48
|
]
|
|
50
49
|
};
|
|
@@ -77,9 +76,12 @@ export async function runPullComponentsTool(args) {
|
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
78
|
async function fetchDirectoryStructure(componentNames, projectID, personalAccessToken) {
|
|
80
|
-
// TODO: change to PROD url
|
|
81
79
|
const encodedNames = componentNames.map(name => encodeURIComponent(name)).join(',');
|
|
82
|
-
|
|
80
|
+
let baseURL = 'https://codegen-api.locofy.ai/mcp/generators/';
|
|
81
|
+
if (process.env.IS_DEV === 'true') {
|
|
82
|
+
baseURL = 'https://codegen-api.locofy.dev/mcp/generators/';
|
|
83
|
+
}
|
|
84
|
+
const url = baseURL + projectID + '?name=' + encodedNames;
|
|
83
85
|
const headers = {
|
|
84
86
|
'Accept': '*/*',
|
|
85
87
|
'Content-Type': 'application/json',
|
|
@@ -414,7 +416,7 @@ function normalizeForComparison(code) {
|
|
|
414
416
|
* @param directoryStructure The directory structure to clean
|
|
415
417
|
* @returns The cleaned directory structure
|
|
416
418
|
*/
|
|
417
|
-
function
|
|
419
|
+
function processDirectoryStructure(directoryStructure) {
|
|
418
420
|
const propertiesToRemove = [
|
|
419
421
|
'files',
|
|
420
422
|
'component',
|
|
@@ -427,6 +429,40 @@ function cleanDirectoryStructure(directoryStructure) {
|
|
|
427
429
|
'storybookFileName',
|
|
428
430
|
'isAutoSyncNode'
|
|
429
431
|
];
|
|
432
|
+
const componentsToUpdate = [];
|
|
433
|
+
const componentsUnchanged = [];
|
|
434
|
+
function collectChangeStatus(node) {
|
|
435
|
+
// Check if this is a component node with a name and change status
|
|
436
|
+
if (node.name && node.codeChanged !== undefined) {
|
|
437
|
+
if (node.codeChanged) {
|
|
438
|
+
componentsToUpdate.push(node.name);
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
componentsUnchanged.push(node.name);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
// Check dependencies
|
|
445
|
+
if (node.exportData && node.exportData.dependencies) {
|
|
446
|
+
node.exportData.dependencies.forEach((dep) => {
|
|
447
|
+
if (dep.compName && dep.codeChanged !== undefined) {
|
|
448
|
+
if (dep.codeChanged) {
|
|
449
|
+
componentsToUpdate.push(dep.compName);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
componentsUnchanged.push(dep.compName);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
// Check nested dependencies
|
|
456
|
+
if (dep.dependencies && Array.isArray(dep.dependencies)) {
|
|
457
|
+
dep.dependencies.forEach((nestedDep) => collectChangeStatus(nestedDep));
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
// Process children recursively
|
|
462
|
+
if (node.children && Array.isArray(node.children)) {
|
|
463
|
+
node.children.forEach((child) => collectChangeStatus(child));
|
|
464
|
+
}
|
|
465
|
+
}
|
|
430
466
|
function cleanNode(node) {
|
|
431
467
|
// Remove unwanted properties from the current node
|
|
432
468
|
propertiesToRemove.forEach(prop => {
|
|
@@ -449,7 +485,16 @@ function cleanDirectoryStructure(directoryStructure) {
|
|
|
449
485
|
node.children.forEach((child) => cleanNode(child));
|
|
450
486
|
}
|
|
451
487
|
}
|
|
452
|
-
//
|
|
488
|
+
// First collect all change statuses
|
|
489
|
+
collectChangeStatus(directoryStructure);
|
|
490
|
+
// Then clean the structure
|
|
453
491
|
cleanNode(directoryStructure);
|
|
454
|
-
|
|
492
|
+
// Get the first child (the actual component data we want)
|
|
493
|
+
const result = directoryStructure.children && directoryStructure.children.length > 0
|
|
494
|
+
? directoryStructure.children[0]
|
|
495
|
+
: directoryStructure;
|
|
496
|
+
// Add the component lists to the component data
|
|
497
|
+
result.componentsToUpdate = [...new Set(componentsToUpdate)];
|
|
498
|
+
result.componentsUnchanged = [...new Set(componentsUnchanged)];
|
|
499
|
+
return result;
|
|
455
500
|
}
|