@flisk/analyze-tracking 0.7.2 → 0.7.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.
- package/README.md +4 -0
- package/bin/cli.js +30 -2
- package/package.json +12 -8
- package/src/analyze/go/astTraversal.js +121 -0
- package/src/analyze/go/constants.js +20 -0
- package/src/analyze/go/eventDeduplicator.js +47 -0
- package/src/analyze/go/eventExtractor.js +156 -0
- package/src/analyze/go/goAstParser/constants.js +39 -0
- package/src/analyze/go/goAstParser/expressionParser.js +281 -0
- package/src/analyze/go/goAstParser/index.js +52 -0
- package/src/analyze/go/goAstParser/statementParser.js +387 -0
- package/src/analyze/go/goAstParser/tokenizer.js +196 -0
- package/src/analyze/go/goAstParser/typeParser.js +202 -0
- package/src/analyze/go/goAstParser/utils.js +99 -0
- package/src/analyze/go/index.js +55 -0
- package/src/analyze/go/propertyExtractor.js +670 -0
- package/src/analyze/go/trackingDetector.js +71 -0
- package/src/analyze/go/trackingExtractor.js +54 -0
- package/src/analyze/go/typeContext.js +88 -0
- package/src/analyze/go/utils.js +215 -0
- package/src/analyze/index.js +11 -6
- package/src/analyze/javascript/constants.js +115 -0
- package/src/analyze/javascript/detectors/analytics-source.js +119 -0
- package/src/analyze/javascript/detectors/index.js +10 -0
- package/src/analyze/javascript/extractors/event-extractor.js +179 -0
- package/src/analyze/javascript/extractors/index.js +13 -0
- package/src/analyze/javascript/extractors/property-extractor.js +172 -0
- package/src/analyze/javascript/index.js +38 -0
- package/src/analyze/javascript/parser.js +126 -0
- package/src/analyze/javascript/utils/function-finder.js +123 -0
- package/src/analyze/python/index.js +111 -0
- package/src/analyze/python/pythonTrackingAnalyzer.py +814 -0
- package/src/analyze/ruby/detectors.js +46 -0
- package/src/analyze/ruby/extractors.js +258 -0
- package/src/analyze/ruby/index.js +51 -0
- package/src/analyze/ruby/traversal.js +123 -0
- package/src/analyze/ruby/types.js +30 -0
- package/src/analyze/ruby/visitor.js +66 -0
- package/src/analyze/typescript/constants.js +109 -0
- package/src/analyze/typescript/detectors/analytics-source.js +125 -0
- package/src/analyze/typescript/detectors/index.js +10 -0
- package/src/analyze/typescript/extractors/event-extractor.js +269 -0
- package/src/analyze/typescript/extractors/index.js +14 -0
- package/src/analyze/typescript/extractors/property-extractor.js +427 -0
- package/src/analyze/typescript/index.js +48 -0
- package/src/analyze/typescript/parser.js +131 -0
- package/src/analyze/typescript/utils/function-finder.js +139 -0
- package/src/analyze/typescript/utils/type-resolver.js +208 -0
- package/src/generateDescriptions/index.js +81 -0
- package/src/generateDescriptions/llmUtils.js +33 -0
- package/src/generateDescriptions/promptUtils.js +62 -0
- package/src/generateDescriptions/schemaUtils.js +61 -0
- package/src/index.js +13 -4
- package/src/{fileProcessor.js → utils/fileProcessor.js} +5 -0
- package/src/{repoDetails.js → utils/repoDetails.js} +5 -0
- package/src/utils/yamlGenerator.js +47 -0
- package/src/analyze/analyzeGoFile.js +0 -1164
- package/src/analyze/analyzeJsFile.js +0 -87
- package/src/analyze/analyzePythonFile.js +0 -42
- package/src/analyze/analyzeRubyFile.js +0 -419
- package/src/analyze/analyzeTsFile.js +0 -192
- package/src/analyze/go2json.js +0 -1069
- package/src/analyze/helpers.js +0 -656
- package/src/analyze/pythonTrackingAnalyzer.py +0 -541
- package/src/generateDescriptions.js +0 -196
- package/src/yamlGenerator.js +0 -23
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Python analytics tracking analyzer - main entry point
|
|
3
|
+
* @module analyze/python
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
// Singleton instance of Pyodide
|
|
10
|
+
let pyodide = null;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Initialize Pyodide runtime lazily
|
|
14
|
+
*
|
|
15
|
+
* This function loads Pyodide and required Python packages only when needed,
|
|
16
|
+
* improving startup performance when Python analysis is not immediately required.
|
|
17
|
+
*
|
|
18
|
+
* @returns {Promise<Object>} The initialized Pyodide instance
|
|
19
|
+
* @throws {Error} If Pyodide fails to load
|
|
20
|
+
*/
|
|
21
|
+
async function initPyodide() {
|
|
22
|
+
if (!pyodide) {
|
|
23
|
+
try {
|
|
24
|
+
const { loadPyodide } = await import('pyodide');
|
|
25
|
+
pyodide = await loadPyodide();
|
|
26
|
+
|
|
27
|
+
// Pre-load required Python packages
|
|
28
|
+
await pyodide.loadPackagesFromImports('import ast, json');
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(`Failed to initialize Pyodide: ${error.message}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return pyodide;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Analyze a Python file for analytics tracking calls
|
|
38
|
+
*
|
|
39
|
+
* This function parses Python code and identifies analytics tracking calls from various
|
|
40
|
+
* libraries, extracting event names, properties, and metadata.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} filePath - Path to the Python file to analyze
|
|
43
|
+
* @param {string} [customFunction=null] - Name of a custom tracking function to detect
|
|
44
|
+
* @returns {Promise<Array<Object>>} Array of tracking events found in the file
|
|
45
|
+
* @returns {Promise<Array>} Empty array if an error occurs
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const events = await analyzePythonFile('./app.py');
|
|
49
|
+
* // Returns: [{ eventName: 'User Signup', source: 'segment', properties: {...}, ... }]
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // With custom tracking function
|
|
53
|
+
* const events = await analyzePythonFile('./app.py', 'track_event');
|
|
54
|
+
*/
|
|
55
|
+
async function analyzePythonFile(filePath, customFunction = null) {
|
|
56
|
+
// Validate inputs
|
|
57
|
+
if (!filePath || typeof filePath !== 'string') {
|
|
58
|
+
console.error('Invalid file path provided');
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
// Check if file exists before reading
|
|
64
|
+
if (!fs.existsSync(filePath)) {
|
|
65
|
+
console.error(`File not found: ${filePath}`);
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Read the Python file
|
|
70
|
+
const code = fs.readFileSync(filePath, 'utf8');
|
|
71
|
+
|
|
72
|
+
// Initialize Pyodide if not already done
|
|
73
|
+
const py = await initPyodide();
|
|
74
|
+
|
|
75
|
+
// Load the Python analyzer code
|
|
76
|
+
const analyzerPath = path.join(__dirname, 'pythonTrackingAnalyzer.py');
|
|
77
|
+
if (!fs.existsSync(analyzerPath)) {
|
|
78
|
+
throw new Error(`Python analyzer not found at: ${analyzerPath}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const analyzerCode = fs.readFileSync(analyzerPath, 'utf8');
|
|
82
|
+
|
|
83
|
+
// Set up Python environment with necessary variables
|
|
84
|
+
py.globals.set('code', code);
|
|
85
|
+
py.globals.set('filepath', filePath);
|
|
86
|
+
py.globals.set('custom_function', customFunction);
|
|
87
|
+
// Set __name__ to null to prevent execution of main block
|
|
88
|
+
py.globals.set('__name__', null);
|
|
89
|
+
|
|
90
|
+
// Load and run the analyzer
|
|
91
|
+
py.runPython(analyzerCode);
|
|
92
|
+
|
|
93
|
+
// Execute the analysis and parse results
|
|
94
|
+
const result = py.runPython('analyze_python_code(code, filepath, custom_function)');
|
|
95
|
+
const events = JSON.parse(result);
|
|
96
|
+
|
|
97
|
+
return events;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
// Log detailed error information for debugging
|
|
100
|
+
console.error(`Error analyzing Python file ${filePath}:`, error);
|
|
101
|
+
console.error('Stack trace:', error.stack);
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Export the public API
|
|
107
|
+
module.exports = {
|
|
108
|
+
analyzePythonFile,
|
|
109
|
+
// Export for testing purposes
|
|
110
|
+
_initPyodide: initPyodide
|
|
111
|
+
};
|