slicejs-cli 2.9.1 → 2.9.2
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.
|
@@ -3,7 +3,7 @@ import fs from 'fs-extra';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { parse } from '@babel/parser';
|
|
5
5
|
import traverse from '@babel/traverse';
|
|
6
|
-
import { getSrcPath, getComponentsJsPath, getProjectRoot } from '../PathHelper.js';
|
|
6
|
+
import { getSrcPath, getComponentsJsPath, getProjectRoot, getConfigPath } from '../PathHelper.js';
|
|
7
7
|
|
|
8
8
|
export default class DependencyAnalyzer {
|
|
9
9
|
constructor(moduleUrl) {
|
|
@@ -64,11 +64,21 @@ export default class DependencyAnalyzer {
|
|
|
64
64
|
*/
|
|
65
65
|
async loadComponentsConfig() {
|
|
66
66
|
const componentsConfigPath = path.join(this.componentsPath, 'components.js');
|
|
67
|
+
const configPath = getConfigPath(this.moduleUrl);
|
|
68
|
+
let sliceConfig = {};
|
|
67
69
|
|
|
68
70
|
if (!await fs.pathExists(componentsConfigPath)) {
|
|
69
71
|
throw new Error('components.js not found');
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
if (await fs.pathExists(configPath)) {
|
|
75
|
+
try {
|
|
76
|
+
sliceConfig = await fs.readJson(configPath);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.warn('Warning: Could not read sliceConfig.json for component paths:', error.message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
72
82
|
// Read and parse components.js
|
|
73
83
|
const content = await fs.readFile(componentsConfigPath, 'utf-8');
|
|
74
84
|
|
|
@@ -87,13 +97,18 @@ export default class DependencyAnalyzer {
|
|
|
87
97
|
|
|
88
98
|
// Process each category
|
|
89
99
|
for (const [categoryName, componentList] of categoryMap) {
|
|
90
|
-
|
|
91
|
-
|
|
100
|
+
const configCategory = sliceConfig?.paths?.components?.[categoryName];
|
|
101
|
+
|
|
102
|
+
// Determine category type based on config or category name
|
|
103
|
+
let categoryType = configCategory?.type || 'Visual';
|
|
92
104
|
if (categoryName === 'Service') categoryType = 'Service';
|
|
93
105
|
if (categoryName === 'AppComponents') categoryType = 'Visual'; // AppComponents are visual
|
|
94
106
|
|
|
95
|
-
//
|
|
96
|
-
|
|
107
|
+
// Resolve category path from config if available
|
|
108
|
+
let categoryPath = path.join(this.componentsPath, categoryName);
|
|
109
|
+
if (configCategory?.path) {
|
|
110
|
+
categoryPath = getSrcPath(this.moduleUrl, configCategory.path);
|
|
111
|
+
}
|
|
97
112
|
|
|
98
113
|
if (await fs.pathExists(categoryPath)) {
|
|
99
114
|
const files = await fs.readdir(categoryPath);
|
|
@@ -330,6 +345,17 @@ export default class DependencyAnalyzer {
|
|
|
330
345
|
return node;
|
|
331
346
|
}
|
|
332
347
|
|
|
348
|
+
if (node.type === 'CallExpression') {
|
|
349
|
+
const calleeName = node.callee?.name || null;
|
|
350
|
+
if (calleeName && node.arguments?.length) {
|
|
351
|
+
const firstArg = node.arguments[0];
|
|
352
|
+
const resolvedObject = resolveObjectExpression(firstArg, scope);
|
|
353
|
+
if (resolvedObject) {
|
|
354
|
+
return resolvedObject;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
333
359
|
if (node.type === 'ObjectExpression') {
|
|
334
360
|
const routesProp = node.properties.find(p => p.key?.name === 'routes');
|
|
335
361
|
if (routesProp?.value) {
|
|
@@ -348,6 +374,10 @@ export default class DependencyAnalyzer {
|
|
|
348
374
|
return init;
|
|
349
375
|
}
|
|
350
376
|
|
|
377
|
+
if (init?.type === 'CallExpression') {
|
|
378
|
+
return resolveRoutesArray(init, binding.path.scope);
|
|
379
|
+
}
|
|
380
|
+
|
|
351
381
|
if (init?.type === 'Identifier') {
|
|
352
382
|
return resolveRoutesArray(init, binding.path.scope);
|
|
353
383
|
}
|
|
@@ -562,8 +592,46 @@ export default class DependencyAnalyzer {
|
|
|
562
592
|
return null;
|
|
563
593
|
};
|
|
564
594
|
|
|
595
|
+
const addRouteConfigDependencies = (routesConfigNode, scope) => {
|
|
596
|
+
if (!routesConfigNode || routesConfigNode.type !== 'ObjectExpression') return;
|
|
597
|
+
|
|
598
|
+
const processObject = (node) => {
|
|
599
|
+
if (!node || node.type !== 'ObjectExpression') return;
|
|
600
|
+
|
|
601
|
+
const componentProp = node.properties.find(p => p.key?.name === 'component');
|
|
602
|
+
if (componentProp?.value) {
|
|
603
|
+
const componentName = resolveStringValue(componentProp.value, scope);
|
|
604
|
+
if (componentName) {
|
|
605
|
+
dependencies.add(componentName);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const itemsProp = node.properties.find(p => p.key?.name === 'items');
|
|
610
|
+
if (itemsProp?.value) {
|
|
611
|
+
const itemsNode = resolveRoutesArray(itemsProp.value, scope);
|
|
612
|
+
addMultiRouteDependencies(itemsNode, scope);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
node.properties.forEach((prop) => {
|
|
616
|
+
const valueNode = prop.value;
|
|
617
|
+
if (valueNode?.type === 'ObjectExpression') {
|
|
618
|
+
processObject(valueNode);
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
processObject(routesConfigNode);
|
|
624
|
+
};
|
|
625
|
+
|
|
565
626
|
const addMultiRouteDependencies = (routesArrayNode, scope) => {
|
|
566
|
-
if (!routesArrayNode
|
|
627
|
+
if (!routesArrayNode) return;
|
|
628
|
+
|
|
629
|
+
if (routesArrayNode.type === 'ObjectExpression') {
|
|
630
|
+
addRouteConfigDependencies(routesArrayNode, scope);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (routesArrayNode.type !== 'ArrayExpression') return;
|
|
567
635
|
|
|
568
636
|
routesArrayNode.elements.forEach(routeElement => {
|
|
569
637
|
if (!routeElement) return;
|
|
@@ -583,6 +651,12 @@ export default class DependencyAnalyzer {
|
|
|
583
651
|
dependencies.add(componentName);
|
|
584
652
|
}
|
|
585
653
|
}
|
|
654
|
+
|
|
655
|
+
const itemsProp = routeObject.properties.find(p => p.key?.name === 'items');
|
|
656
|
+
if (itemsProp?.value) {
|
|
657
|
+
const itemsNode = resolveRoutesArray(itemsProp.value, scope);
|
|
658
|
+
addMultiRouteDependencies(itemsNode, scope);
|
|
659
|
+
}
|
|
586
660
|
}
|
|
587
661
|
});
|
|
588
662
|
};
|