@flisk/analyze-tracking 0.2.0 → 0.2.1
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/package.json +3 -1
- package/src/analyze/analyzeJsFile.js +7 -1
- package/src/analyze/index.js +2 -2
- package/src/fileProcessor.js +17 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flisk/analyze-tracking",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Analyzes tracking code in a project and generates data schemas",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@typescript-eslint/parser": "^8.1.0",
|
|
24
24
|
"acorn": "^8.12.1",
|
|
25
|
+
"acorn-jsx": "^5.3.2",
|
|
26
|
+
"acorn-jsx-walk": "^2.0.0",
|
|
25
27
|
"acorn-walk": "^8.3.3",
|
|
26
28
|
"command-line-args": "^6.0.0",
|
|
27
29
|
"js-yaml": "^4.1.0",
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const acorn = require('acorn');
|
|
3
|
+
const jsx = require('acorn-jsx');
|
|
3
4
|
const walk = require('acorn-walk');
|
|
5
|
+
const { extend } = require('acorn-jsx-walk');
|
|
4
6
|
const { detectSourceJs, findWrappingFunctionJs, extractJsProperties } = require('./helpers');
|
|
5
7
|
|
|
8
|
+
const parser = acorn.Parser.extend(jsx());
|
|
9
|
+
const parserOptions = { ecmaVersion: 'latest', sourceType: 'module', locations: true };
|
|
10
|
+
extend(walk.base);
|
|
11
|
+
|
|
6
12
|
function analyzeJsFile(filePath) {
|
|
7
13
|
const code = fs.readFileSync(filePath, 'utf8');
|
|
8
|
-
const ast =
|
|
14
|
+
const ast = parser.parse(code, parserOptions);
|
|
9
15
|
const events = [];
|
|
10
16
|
|
|
11
17
|
walk.ancestor(ast, {
|
package/src/analyze/index.js
CHANGED
|
@@ -8,14 +8,14 @@ function analyzeDirectory(dirPath) {
|
|
|
8
8
|
const files = getAllFiles(dirPath);
|
|
9
9
|
const allEvents = {};
|
|
10
10
|
|
|
11
|
-
const tsFiles = files.filter(file =>
|
|
11
|
+
const tsFiles = files.filter(file => /\.(tsx?)$/.test(file));
|
|
12
12
|
const program = ts.createProgram(tsFiles, {
|
|
13
13
|
target: ts.ScriptTarget.ESNext,
|
|
14
14
|
module: ts.ModuleKind.CommonJS,
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
files.forEach((file) => {
|
|
18
|
-
const isTsFile =
|
|
18
|
+
const isTsFile = /\.(tsx?)$/.test(file);
|
|
19
19
|
const events = isTsFile ? analyzeTsFile(file, program) : analyzeJsFile(file);
|
|
20
20
|
|
|
21
21
|
events.forEach((event) => {
|
package/src/fileProcessor.js
CHANGED
|
@@ -6,9 +6,24 @@ function getAllFiles(dirPath, arrayOfFiles = []) {
|
|
|
6
6
|
|
|
7
7
|
files.forEach((file) => {
|
|
8
8
|
const fullPath = path.join(dirPath, file);
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
let stats;
|
|
11
|
+
try {
|
|
12
|
+
stats = fs.statSync(fullPath);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error.code === 'ENOENT') {
|
|
15
|
+
return; // Skip this file or directory if it does not exist
|
|
16
|
+
} else {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (stats.isDirectory()) {
|
|
22
|
+
if (file === 'node_modules') {
|
|
23
|
+
return; // Ignore the node_modules directory
|
|
24
|
+
}
|
|
10
25
|
arrayOfFiles = getAllFiles(fullPath, arrayOfFiles);
|
|
11
|
-
} else if (
|
|
26
|
+
} else if (/\.((j|t)sx?)$/.test(file)) {
|
|
12
27
|
arrayOfFiles.push(fullPath);
|
|
13
28
|
}
|
|
14
29
|
});
|