@flisk/analyze-tracking 0.2.7 → 0.2.9

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 CHANGED
@@ -1,32 +1,49 @@
1
1
  # @flisk/analyze-tracking
2
2
 
3
- Analyzes tracking code in a project and generates data schemas
3
+ Automatically document your analytics setup by analyzing tracking code and generating data schemas from tools like Segment, Amplitude, Mixpanel, and more 🚀.
4
4
 
5
5
  [![NPM version](https://img.shields.io/npm/v/@flisk/analyze-tracking.svg)](https://www.npmjs.com/package/@flisk/analyze-tracking)
6
6
 
7
7
 
8
- ## Usage
8
+ ## Why Use @flisk/analyze-tracking?
9
+ 📊 **Understand Your Tracking** – Effortlessly analyze your codebase for `track` calls so you can see all your analytics events, properties, and triggers in one place. No more guessing what’s being tracked!
10
+
11
+ 🔍 **Auto-Document Events** – Generates a complete YAML schema that captures all events and properties, including where they’re implemented in your codebase.
12
+
13
+ 🕵️‍♂️ **Track Changes Over Time** – Easily spot unintended changes or ensure your analytics setup remains consistent across updates.
14
+
15
+ 📚 **Populate Data Catalogs** – Automatically generate structured documentation that can help feed into your data catalog, making it easier for everyone to understand your events.
16
+
17
+
18
+ ## Quick Start
19
+
20
+ Run without installation! Just use:
21
+
9
22
  ```sh
10
23
  npx @flisk/analyze-tracking /path/to/project [options]
11
24
  ```
12
25
 
13
- Optional arguments:
26
+ ### Key Options:
14
27
  - `-o, --output <output_file>`: Name of the output file (default: `tracking-schema.yaml`)
15
- - `-c, --customFunction <function_name>`: Name of your custom tracking function
16
- - `-u, --repositoryUrl <git_url>`: URL to your repository
17
- - `-h, --commitHash <commit_sha>`: Latest commit hash
18
- - `-t, --commitTimestamp <iso_timestamp>`: Timestamp of latest commit
19
-
20
- Note: Custom Functions only support the following format:
21
- ```js
22
- yourCustomTrackFunctionName('<event_name>', {
23
- <event_parameters>
24
- });
25
- ```
28
+ - `-c, --customFunction <function_name>`: Specify a custom tracking function
29
+
30
+ <details>
31
+ <summary>Note on Custom Functions 💡</summary>
26
32
 
33
+ Use this if you have your own in-house tracker or a wrapper function that calls other tracking libraries.
27
34
 
28
- ## Output Schema
29
- A YAML file with the following structure is generated:
35
+ We currently only support functions that follow the following format:
36
+ ```js
37
+ yourCustomTrackFunctionName('<event_name>', {
38
+ <event_parameters>
39
+ });
40
+ ```
41
+ </details>
42
+
43
+
44
+ ## What’s Generated?
45
+ A clear YAML schema that shows where your events are tracked, their properties, and more.
46
+ Here’s an example:
30
47
 
31
48
  ```yaml
32
49
  version: 1
@@ -44,116 +61,141 @@ events:
44
61
  properties:
45
62
  <property_name>:
46
63
  type: <property_type>
47
- required: <property_required>
48
- description: <property_description>
49
64
  ```
50
65
 
51
- See [schema.json](schema.json) for the output schema.
66
+ Use this to understand where your events live in the code and how they’re being tracked.
52
67
 
68
+ See [schema.json](schema.json) for a JSON Schema of the output.
53
69
 
54
- ## Supported tracking libraries
55
-
56
- #### Google Analytics
57
- ```js
58
- gtag('event', '<event_name>', {
59
- <event_parameters>
60
- });
61
- ```
62
-
63
-
64
- #### Segment
65
- ```js
66
- analytics.track('<event_name>', {
67
- <event_parameters>
68
- });
69
- ```
70
-
71
-
72
- #### Mixpanel
73
- ```js
74
- mixpanel.track('<event_name>', {
75
- <event_parameters>
76
- });
77
- ```
78
-
79
-
80
- #### Amplitude
81
- ```js
82
- amplitude.logEvent('<event_name>', {
83
- <event_parameters>
84
- });
85
- ```
86
70
 
71
+ ## Supported tracking libraries
87
72
 
88
- #### Rudderstack
89
- ```js
90
- rudderanalytics.track('<event_name>', {
91
- <event_parameters>
92
- });
93
- ```
94
-
95
-
96
- #### mParticle
97
- ```js
98
- mParticle.logEvent('<event_name>', {
99
- <event_parameters>
100
- });
101
- ```
102
-
103
-
104
- #### PostHog
105
- ```js
106
- posthog.capture('<event_name>', {
107
- <event_parameters>
108
- });
109
- ```
110
-
111
-
112
- #### Pendo
113
- ```js
114
- pendo.track('<event_name>', {
115
- <event_parameters>
116
- });
117
- ```
118
-
119
-
120
- #### Heap
121
- ```js
122
- heap.track('<event_name>', {
123
- <event_parameters>
124
- });
125
- ```
126
-
127
-
128
- #### Snowplow
129
- ```js
130
- snowplow('trackStructEvent', {
131
- category: '<category>',
132
- action: '<action>',
133
- label: '<label>',
134
- property: '<property>',
135
- value: '<value> '
136
- });
137
- ```
138
-
139
- ```js
140
- trackStructEvent({
141
- category: '<category>',
142
- action: '<action>',
143
- label: '<label>',
144
- property: '<property>',
145
- value: '<value>'
146
- });
147
- ```
148
-
149
- ```js
150
- buildStructEvent({
151
- category: '<category>',
152
- action: '<action>',
153
- label: '<label>',
154
- property: '<property>',
155
- value: '<value>'
156
- });
157
- ```
158
-
159
- _Note: Snowplow Self Describing Events are not supported yet._
73
+ <details>
74
+ <summary>Google Analytics</summary>
75
+
76
+ ```js
77
+ gtag('event', '<event_name>', {
78
+ <event_parameters>
79
+ });
80
+ ```
81
+ </details>
82
+
83
+ <details>
84
+ <summary>Segment</summary>
85
+
86
+ ```js
87
+ analytics.track('<event_name>', {
88
+ <event_parameters>
89
+ });
90
+ ```
91
+ </details>
92
+
93
+ <details>
94
+ <summary>Mixpanel</summary>
95
+
96
+ ```js
97
+ mixpanel.track('<event_name>', {
98
+ <event_parameters>
99
+ });
100
+ ```
101
+ </details>
102
+
103
+ <details>
104
+ <summary>Amplitude</summary>
105
+
106
+ ```js
107
+ amplitude.logEvent('<event_name>', {
108
+ <event_parameters>
109
+ });
110
+ ```
111
+ </details>
112
+
113
+ <details>
114
+ <summary>Rudderstack</summary>
115
+
116
+ ```js
117
+ rudderanalytics.track('<event_name>', {
118
+ <event_parameters>
119
+ });
120
+ ```
121
+ </details>
122
+
123
+ <details>
124
+ <summary>mParticle</summary>
125
+
126
+ ```js
127
+ mParticle.logEvent('<event_name>', {
128
+ <event_parameters>
129
+ });
130
+ ```
131
+ </details>
132
+
133
+ <details>
134
+ <summary>PostHog</summary>
135
+
136
+ ```js
137
+ posthog.capture('<event_name>', {
138
+ <event_parameters>
139
+ });
140
+ ```
141
+ </details>
142
+
143
+ <details>
144
+ <summary>Pendo</summary>
145
+
146
+ ```js
147
+ pendo.track('<event_name>', {
148
+ <event_parameters>
149
+ });
150
+ ```
151
+ </details>
152
+
153
+ <details>
154
+ <summary>Heap</summary>
155
+
156
+ ```js
157
+ heap.track('<event_name>', {
158
+ <event_parameters>
159
+ });
160
+ ```
161
+ </details>
162
+
163
+ <details>
164
+ <summary>Snowplow (struct events)</summary>
165
+
166
+ ```js
167
+ snowplow('trackStructEvent', {
168
+ category: '<category>',
169
+ action: '<action>',
170
+ label: '<label>',
171
+ property: '<property>',
172
+ value: '<value> '
173
+ });
174
+ ```
175
+
176
+ ```js
177
+ trackStructEvent({
178
+ category: '<category>',
179
+ action: '<action>',
180
+ label: '<label>',
181
+ property: '<property>',
182
+ value: '<value>'
183
+ });
184
+ ```
185
+
186
+ ```js
187
+ buildStructEvent({
188
+ category: '<category>',
189
+ action: '<action>',
190
+ label: '<label>',
191
+ property: '<property>',
192
+ value: '<value>'
193
+ });
194
+ ```
195
+
196
+ _Note: Snowplow Self Describing Events are coming soon!_
197
+ </details>
198
+
199
+
200
+ ## Contribute
201
+ We’re actively improving this package. Found a bug? Want to request a feature? Open an issue or contribute directly!
package/bin/cli.js CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const path = require('path');
4
- const commandLineArgs = require('command-line-args')
4
+ const commandLineArgs = require('command-line-args');
5
+ const commandLineUsage = require('command-line-usage');
5
6
  const { run } = require('../src/index');
7
+ const { helpContent } = require('./help');
6
8
 
7
9
  // Parse command-line arguments
8
10
  const optionDefinitions = [
@@ -29,7 +31,7 @@ const optionDefinitions = [
29
31
  },
30
32
  {
31
33
  name: 'commitHash',
32
- alias: 'h',
34
+ alias: 's',
33
35
  type: String,
34
36
  },
35
37
  {
@@ -37,6 +39,11 @@ const optionDefinitions = [
37
39
  alias: 't',
38
40
  type: String,
39
41
  },
42
+ {
43
+ name: 'help',
44
+ alias: 'h',
45
+ type: Boolean,
46
+ },
40
47
  ]
41
48
  const options = commandLineArgs(optionDefinitions);
42
49
  const {
@@ -46,8 +53,14 @@ const {
46
53
  repositoryUrl,
47
54
  commitHash,
48
55
  commitTimestamp,
56
+ help,
49
57
  } = options;
50
58
 
59
+ if (help) {
60
+ console.log(commandLineUsage(helpContent));
61
+ process.exit(0);
62
+ }
63
+
51
64
  const customSourceDetails = {
52
65
  repositoryUrl,
53
66
  commitHash,
@@ -56,6 +69,7 @@ const customSourceDetails = {
56
69
 
57
70
  if (!targetDir) {
58
71
  console.error('Please provide the path to the repository.');
72
+ console.log(commandLineUsage(helpContent));
59
73
  process.exit(1);
60
74
  }
61
75
 
package/bin/help.js ADDED
@@ -0,0 +1,64 @@
1
+ const header =
2
+ `
3
+ \u001b[38;5;2m ▒▒ \u001b[39m
4
+ \u001b[38;5;2m ▒▒▒▒ \u001b[39m
5
+ \u001b[38;5;2m ▒▒▒▒ \u001b[39m ████████ ██████ ██████ ██████
6
+ \u001b[38;5;2m ▒▒▒▒ \u001b[39m ██████████ ██████ ██████ ██████
7
+ \u001b[38;5;2m ▒▒▒▒▒▒ \u001b[39m ███████████ ██████ ██████ ██████
8
+ \u001b[38;5;2m ▒▒▒▒▒▒ \u001b[39m ██████ ██████ ██████
9
+ \u001b[38;5;2m ▒▒▒▒▒▒▒▒ \u001b[39m ██████████████ ██████ ██████ █████████ ██████ ██████
10
+ \u001b[38;5;2m ▒▒▒▒▒▒▒▒▒▒ \u001b[39m ██████████████ ██████ ██████ █████████████ ██████ ███████
11
+ \u001b[38;5;2m ▒▒▒▒▒▒▒▒▒▒▒▒ \u001b[39m ██████████████ ██████ ██████ ███████ ████ ██████ ████████
12
+ \u001b[38;5;2m ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ \u001b[39m ██████ ██████ ██████ ████████ █████████████
13
+ \u001b[38;5;2m ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ \u001b[39m ██████ ██████ ██████ ███████████ ████████████
14
+ \u001b[38;5;2m ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ \u001b[39m ██████ ██████ ██████ ███████████ █████████████
15
+ \u001b[38;5;2m ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ \u001b[39m ██████ ██████ ██████ ██████ ███████ ██████
16
+ \u001b[38;5;2m ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ \u001b[39m ██████ ██████ ██████ ████ ██████ ██████ ██████
17
+ \u001b[38;5;2m ▓▓▓▓▓▓▓▓▓▓▓▓ \u001b[39m ██████ ██████ ██████ ██████████████ ██████ ███████
18
+ \u001b[38;5;2m ▓▓▓▓▓▓▓▓▓▓ \u001b[39m ██████ ██████ ██████ ██████████ ██████ ███████
19
+ \u001b[38;5;2m ▓▓▓▓▓▓▓▓ \u001b[39m
20
+ \u001b[38;5;2m ▓▓▓▓▓▓ \u001b[39m
21
+ `;
22
+
23
+ const helpContent = [
24
+ {
25
+ content: header,
26
+ raw: true
27
+ },
28
+ {
29
+ header: '@flisk/analyze-tracking',
30
+ content: 'Automatically document your analytics setup by analyzing tracking code and generating data schemas from tools like Segment, Amplitude, Mixpanel, and more 🚀'
31
+ },
32
+ {
33
+ header: 'Options',
34
+ optionList: [
35
+ {
36
+ name: 'help',
37
+ alias: 'h',
38
+ description: 'Display this usage guide.',
39
+ type: Boolean
40
+ },
41
+ {
42
+ name: 'output',
43
+ alias: 'o',
44
+ description: 'Name of the output file.',
45
+ type: String,
46
+ defaultOption: true,
47
+ typeLabel: '{underline tracking-schema.yaml}'
48
+ },
49
+ {
50
+ name: 'customFunction',
51
+ alias: 'c',
52
+ description: 'Specify a custom tracking function.',
53
+ type: String,
54
+ typeLabel: '{underline yourCustomFunctionName}'
55
+ }
56
+ ]
57
+ },
58
+ {
59
+ header: 'Project Home',
60
+ content: '{underline https://github.com/fliskdata/analyze-tracking}'
61
+ }
62
+ ];
63
+
64
+ module.exports = { helpContent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flisk/analyze-tracking",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Analyzes tracking code in a project and generates data schemas",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -26,6 +26,7 @@
26
26
  "acorn-jsx-walk": "^2.0.0",
27
27
  "acorn-walk": "^8.3.3",
28
28
  "command-line-args": "^6.0.0",
29
+ "command-line-usage": "^7.0.3",
29
30
  "isomorphic-git": "^1.27.1",
30
31
  "js-yaml": "^4.1.0",
31
32
  "typescript": "^5.5.4"
@@ -10,47 +10,61 @@ const parserOptions = { ecmaVersion: 'latest', sourceType: 'module', locations:
10
10
  extend(walk.base);
11
11
 
12
12
  function analyzeJsFile(filePath, customFunction) {
13
- const code = fs.readFileSync(filePath, 'utf8');
14
- const ast = parser.parse(code, parserOptions);
15
- const events = [];
16
-
17
- walk.ancestor(ast, {
18
- CallExpression(node, ancestors) {
19
- const source = detectSourceJs(node, customFunction);
20
- if (source === 'unknown') return;
21
-
22
- let eventName = null;
23
- let propertiesNode = null;
24
-
25
- if (source === 'googleanalytics' && node.arguments.length >= 3) {
26
- eventName = node.arguments[1]?.value || null;
27
- propertiesNode = node.arguments[2];
28
- } else if (source === 'snowplow' && node.arguments.length >= 2) {
29
- const actionProperty = node.arguments[1].properties.find(prop => prop.key.name === 'action');
30
- eventName = actionProperty ? actionProperty.value.value : null;
31
- propertiesNode = node.arguments[1];
32
- } else if (node.arguments.length >= 2) {
33
- eventName = node.arguments[0]?.value || null;
34
- propertiesNode = node.arguments[1];
35
- }
36
-
37
- const line = node.loc.start.line;
38
- const functionName = findWrappingFunctionJs(node, ancestors);
39
-
40
- if (eventName && propertiesNode && propertiesNode.type === 'ObjectExpression') {
41
- const properties = extractJsProperties(propertiesNode);
42
-
43
- events.push({
44
- eventName,
45
- source,
46
- properties,
47
- filePath,
48
- line,
49
- functionName
50
- });
51
- }
52
- },
53
- });
13
+ let events = [];
14
+ try {
15
+ const code = fs.readFileSync(filePath, 'utf8');
16
+ let ast;
17
+ try {
18
+ ast = parser.parse(code, parserOptions);
19
+ } catch (parseError) {
20
+ console.error(`Error parsing file ${filePath}`);
21
+ return events; // Return empty events array if parsing fails
22
+ }
23
+
24
+ walk.ancestor(ast, {
25
+ CallExpression(node, ancestors) {
26
+ try {
27
+ const source = detectSourceJs(node, customFunction);
28
+ if (source === 'unknown') return;
29
+
30
+ let eventName = null;
31
+ let propertiesNode = null;
32
+
33
+ if (source === 'googleanalytics' && node.arguments.length >= 3) {
34
+ eventName = node.arguments[1]?.value || null;
35
+ propertiesNode = node.arguments[2];
36
+ } else if (source === 'snowplow' && node.arguments.length >= 2) {
37
+ const actionProperty = node.arguments[1].properties.find(prop => prop.key.name === 'action');
38
+ eventName = actionProperty ? actionProperty.value.value : null;
39
+ propertiesNode = node.arguments[1];
40
+ } else if (node.arguments.length >= 2) {
41
+ eventName = node.arguments[0]?.value || null;
42
+ propertiesNode = node.arguments[1];
43
+ }
44
+
45
+ const line = node.loc.start.line;
46
+ const functionName = findWrappingFunctionJs(node, ancestors);
47
+
48
+ if (eventName && propertiesNode && propertiesNode.type === 'ObjectExpression') {
49
+ const properties = extractJsProperties(propertiesNode);
50
+
51
+ events.push({
52
+ eventName,
53
+ source,
54
+ properties,
55
+ filePath,
56
+ line,
57
+ functionName
58
+ });
59
+ }
60
+ } catch (nodeError) {
61
+ console.error(`Error processing node in ${filePath}`);
62
+ }
63
+ },
64
+ });
65
+ } catch (fileError) {
66
+ console.error(`Error reading or processing file ${filePath}`);
67
+ }
54
68
 
55
69
  return events;
56
70
  }
@@ -2,49 +2,66 @@ const ts = require('typescript');
2
2
  const { detectSourceTs, findWrappingFunctionTs, extractTsProperties } = require('./helpers');
3
3
 
4
4
  function analyzeTsFile(filePath, program, customFunction) {
5
- const sourceFile = program.getSourceFile(filePath);
6
- const checker = program.getTypeChecker();
7
- const events = [];
8
-
9
- function visit(node) {
10
- if (ts.isCallExpression(node)) {
11
- const source = detectSourceTs(node, customFunction);
12
- if (source === 'unknown') return;
13
-
14
- let eventName = null;
15
- let propertiesNode = null;
16
-
17
- if (source === 'googleanalytics' && node.arguments.length >= 3) {
18
- eventName = node.arguments[1]?.text || null;
19
- propertiesNode = node.arguments[2];
20
- } else if (source === 'snowplow' && node.arguments.length >= 2) {
21
- const actionProperty = node.arguments[1].properties.find(prop => prop.name.escapedText === 'action');
22
- eventName = actionProperty ? actionProperty.initializer.text : null;
23
- propertiesNode = node.arguments[1];
24
- } else if (node.arguments.length >= 2) {
25
- eventName = node.arguments[0]?.text || null;
26
- propertiesNode = node.arguments[1];
27
- }
5
+ let events = [];
6
+ try {
7
+ const sourceFile = program.getSourceFile(filePath);
8
+ if (!sourceFile) {
9
+ console.error(`Error: Unable to get source file for ${filePath}`);
10
+ return events;
11
+ }
12
+
13
+ const checker = program.getTypeChecker();
14
+
15
+ function visit(node) {
16
+ try {
17
+ if (ts.isCallExpression(node)) {
18
+ const source = detectSourceTs(node, customFunction);
19
+ if (source === 'unknown') return;
20
+
21
+ let eventName = null;
22
+ let propertiesNode = null;
28
23
 
29
- const line = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
30
- const functionName = findWrappingFunctionTs(node);
31
-
32
- if (eventName && propertiesNode && ts.isObjectLiteralExpression(propertiesNode)) {
33
- const properties = extractTsProperties(checker, propertiesNode);
34
- events.push({
35
- eventName,
36
- source,
37
- properties,
38
- filePath,
39
- line,
40
- functionName
41
- });
24
+ if (source === 'googleanalytics' && node.arguments.length >= 3) {
25
+ eventName = node.arguments[1]?.text || null;
26
+ propertiesNode = node.arguments[2];
27
+ } else if (source === 'snowplow' && node.arguments.length >= 2) {
28
+ const actionProperty = node.arguments[1].properties.find(prop => prop.name.escapedText === 'action');
29
+ eventName = actionProperty ? actionProperty.initializer.text : null;
30
+ propertiesNode = node.arguments[1];
31
+ } else if (node.arguments.length >= 2) {
32
+ eventName = node.arguments[0]?.text || null;
33
+ propertiesNode = node.arguments[1];
34
+ }
35
+
36
+ const line = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
37
+ const functionName = findWrappingFunctionTs(node);
38
+
39
+ if (eventName && propertiesNode && ts.isObjectLiteralExpression(propertiesNode)) {
40
+ try {
41
+ const properties = extractTsProperties(checker, propertiesNode);
42
+ events.push({
43
+ eventName,
44
+ source,
45
+ properties,
46
+ filePath,
47
+ line,
48
+ functionName
49
+ });
50
+ } catch (propertyError) {
51
+ console.error(`Error extracting properties in ${filePath} at line ${line}`);
52
+ }
53
+ }
54
+ }
55
+ ts.forEachChild(node, visit);
56
+ } catch (nodeError) {
57
+ console.error(`Error processing node in ${filePath}`);
42
58
  }
43
59
  }
44
- ts.forEachChild(node, visit);
45
- }
46
60
 
47
- ts.forEachChild(sourceFile, visit);
61
+ ts.forEachChild(sourceFile, visit);
62
+ } catch (fileError) {
63
+ console.error(`Error analyzing TypeScript file ${filePath}`);
64
+ }
48
65
 
49
66
  return events;
50
67
  }
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const git = require('isomorphic-git');
3
+ const { execSync } = require('child_process');
3
4
 
4
5
  async function getRepositoryUrl(targetDir) {
5
6
  try {
@@ -10,8 +11,13 @@ async function getRepositoryUrl(targetDir) {
10
11
  });
11
12
  return repoUrl.trim();
12
13
  } catch (error) {
13
- console.warn('Could not determine repository URL. Will exclude.');
14
- return null;
14
+ try {
15
+ const repoUrl = execSync('git config --get remote.origin.url', { cwd: targetDir, encoding: 'utf8' });
16
+ return repoUrl.trim();
17
+ } catch (error) {
18
+ console.warn('Could not determine repository URL. Will exclude.');
19
+ return null;
20
+ }
15
21
  }
16
22
  }
17
23
 
@@ -24,8 +30,13 @@ async function getCommitHash(targetDir) {
24
30
  });
25
31
  return commitHash.trim();
26
32
  } catch (error) {
27
- console.warn('Could not determine latest commit hash. Will exclude.');
28
- return null;
33
+ try {
34
+ const commitHash = execSync('git rev-parse HEAD', { cwd: targetDir, encoding: 'utf8' });
35
+ return commitHash.trim();
36
+ } catch (error) {
37
+ console.warn('Could not determine latest commit hash. Will exclude.');
38
+ return null;
39
+ }
29
40
  }
30
41
  }
31
42
 
@@ -39,8 +50,14 @@ async function getCommitTimestamp(targetDir, commitHash) {
39
50
  const unixTimeSeconds = commit.committer.timestamp;
40
51
  return new Date(unixTimeSeconds * 1000);
41
52
  } catch (error) {
42
- console.warn('Could not retrieve commit timestamp. Using current timestamp as default.');
43
- return new Date();
53
+ try {
54
+ const commitTimestamp = execSync(`git --no-pager show -s --format=%ct ${commitHash}`, { cwd: targetDir, encoding: 'utf8' });
55
+ const unixTimeSeconds = commitTimestamp.trim();
56
+ return new Date(unixTimeSeconds * 1000);
57
+ } catch (error) {
58
+ console.warn('Could not retrieve commit timestamp. Using current timestamp as default.');
59
+ return new Date();
60
+ }
44
61
  }
45
62
  }
46
63