@flisk/analyze-tracking 0.2.4 → 0.2.6
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 -1
- package/bin/cli.js +30 -2
- package/package.json +2 -1
- package/src/index.js +2 -2
- package/src/repoDetails.js +32 -15
package/README.md
CHANGED
|
@@ -12,7 +12,10 @@ npx @flisk/analyze-tracking /path/to/project [options]
|
|
|
12
12
|
|
|
13
13
|
Optional arguments:
|
|
14
14
|
- `-o, --output <output_file>`: Name of the output file (default: `tracking-schema.yaml`)
|
|
15
|
-
- `-c, --customFunction <
|
|
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
|
|
16
19
|
|
|
17
20
|
Note: Custom Functions only support the following format:
|
|
18
21
|
```js
|
package/bin/cli.js
CHANGED
|
@@ -22,13 +22,41 @@ const optionDefinitions = [
|
|
|
22
22
|
alias: 'c',
|
|
23
23
|
type: String,
|
|
24
24
|
},
|
|
25
|
+
{
|
|
26
|
+
name: 'repositoryUrl',
|
|
27
|
+
alias: 'u',
|
|
28
|
+
type: String,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'commitHash',
|
|
32
|
+
alias: 'h',
|
|
33
|
+
type: String,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'commitTimestamp',
|
|
37
|
+
alias: 't',
|
|
38
|
+
type: String,
|
|
39
|
+
},
|
|
25
40
|
]
|
|
26
41
|
const options = commandLineArgs(optionDefinitions);
|
|
27
|
-
const {
|
|
42
|
+
const {
|
|
43
|
+
targetDir,
|
|
44
|
+
output,
|
|
45
|
+
customFunction,
|
|
46
|
+
repositoryUrl,
|
|
47
|
+
commitHash,
|
|
48
|
+
commitTimestamp,
|
|
49
|
+
} = options;
|
|
50
|
+
|
|
51
|
+
const customSourceDetails = {
|
|
52
|
+
repositoryUrl,
|
|
53
|
+
commitHash,
|
|
54
|
+
commitTimestamp,
|
|
55
|
+
};
|
|
28
56
|
|
|
29
57
|
if (!targetDir) {
|
|
30
58
|
console.error('Please provide the path to the repository.');
|
|
31
59
|
process.exit(1);
|
|
32
60
|
}
|
|
33
61
|
|
|
34
|
-
run(path.resolve(targetDir), output, customFunction);
|
|
62
|
+
run(path.resolve(targetDir), output, customFunction, customSourceDetails);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flisk/analyze-tracking",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
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
|
+
"isomorphic-git": "^1.27.1",
|
|
29
30
|
"js-yaml": "^4.1.0",
|
|
30
31
|
"typescript": "^5.5.4"
|
|
31
32
|
},
|
package/src/index.js
CHANGED
|
@@ -2,9 +2,9 @@ const { analyzeDirectory } = require('./analyze');
|
|
|
2
2
|
const { getRepoDetails } = require('./repoDetails');
|
|
3
3
|
const { generateYamlSchema } = require('./yamlGenerator');
|
|
4
4
|
|
|
5
|
-
function run(targetDir, outputPath, customFunction) {
|
|
5
|
+
async function run(targetDir, outputPath, customFunction, customSourceDetails) {
|
|
6
6
|
const events = analyzeDirectory(targetDir, customFunction);
|
|
7
|
-
const repoDetails = getRepoDetails(targetDir);
|
|
7
|
+
const repoDetails = await getRepoDetails(targetDir, customSourceDetails);
|
|
8
8
|
generateYamlSchema(events, repoDetails, outputPath);
|
|
9
9
|
}
|
|
10
10
|
|
package/src/repoDetails.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const git = require('isomorphic-git');
|
|
2
3
|
|
|
3
|
-
function getRepositoryUrl(targetDir) {
|
|
4
|
+
async function getRepositoryUrl(targetDir) {
|
|
4
5
|
try {
|
|
5
|
-
const repoUrl =
|
|
6
|
+
const repoUrl = await git.getConfig({
|
|
7
|
+
fs,
|
|
8
|
+
dir: targetDir,
|
|
9
|
+
path: 'remote.origin.url',
|
|
10
|
+
});
|
|
6
11
|
return repoUrl.trim();
|
|
7
12
|
} catch (error) {
|
|
8
13
|
console.warn('Could not determine repository URL. Will exclude.');
|
|
@@ -10,9 +15,13 @@ function getRepositoryUrl(targetDir) {
|
|
|
10
15
|
}
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
function getCommitHash(targetDir) {
|
|
18
|
+
async function getCommitHash(targetDir) {
|
|
14
19
|
try {
|
|
15
|
-
const commitHash =
|
|
20
|
+
const commitHash = await git.resolveRef({
|
|
21
|
+
fs,
|
|
22
|
+
dir: targetDir,
|
|
23
|
+
ref: 'HEAD',
|
|
24
|
+
});
|
|
16
25
|
return commitHash.trim();
|
|
17
26
|
} catch (error) {
|
|
18
27
|
console.warn('Could not determine latest commit hash. Will exclude.');
|
|
@@ -20,13 +29,17 @@ function getCommitHash(targetDir) {
|
|
|
20
29
|
}
|
|
21
30
|
}
|
|
22
31
|
|
|
23
|
-
function getCommitTimestamp(targetDir, commitHash) {
|
|
32
|
+
async function getCommitTimestamp(targetDir, commitHash) {
|
|
24
33
|
try {
|
|
25
|
-
const
|
|
26
|
-
|
|
34
|
+
const { commit } = await git.readCommit({
|
|
35
|
+
fs,
|
|
36
|
+
dir: targetDir,
|
|
37
|
+
oid: commitHash,
|
|
38
|
+
});
|
|
39
|
+
const unixTimeSeconds = commit.committer.timestamp;
|
|
27
40
|
return new Date(unixTimeSeconds * 1000);
|
|
28
41
|
} catch (error) {
|
|
29
|
-
console.warn('Could not retrieve commit timestamp. Using current timestamp as default.')
|
|
42
|
+
console.warn('Could not retrieve commit timestamp. Using current timestamp as default.');
|
|
30
43
|
return new Date();
|
|
31
44
|
}
|
|
32
45
|
}
|
|
@@ -41,19 +54,23 @@ function toISODateString(date) {
|
|
|
41
54
|
+ pad(date.getUTCDate())+'T'
|
|
42
55
|
+ pad(date.getUTCHours())+':'
|
|
43
56
|
+ pad(date.getUTCMinutes())+':'
|
|
44
|
-
+ pad(date.getUTCSeconds())+'Z'
|
|
57
|
+
+ pad(date.getUTCSeconds())+'Z';
|
|
45
58
|
}
|
|
46
59
|
|
|
47
|
-
function getRepoDetails(targetDir) {
|
|
48
|
-
const repoUrl = getRepositoryUrl(targetDir);
|
|
49
|
-
const commitHash = getCommitHash(targetDir);
|
|
50
|
-
const commitEpochTime = getCommitTimestamp(targetDir, commitHash);
|
|
60
|
+
async function getRepoDetails(targetDir, customSourceDetails) {
|
|
61
|
+
const repoUrl = await getRepositoryUrl(targetDir);
|
|
62
|
+
const commitHash = await getCommitHash(targetDir);
|
|
63
|
+
const commitEpochTime = await getCommitTimestamp(targetDir, commitHash);
|
|
51
64
|
const commitTimestamp = toISODateString(commitEpochTime);
|
|
52
65
|
|
|
53
66
|
const repoDetails = {};
|
|
54
67
|
if (!!repoUrl) repoDetails.repository = repoUrl;
|
|
55
68
|
if (!!commitHash) repoDetails.commit = commitHash;
|
|
56
|
-
repoDetails.timestamp = commitTimestamp
|
|
69
|
+
repoDetails.timestamp = commitTimestamp;
|
|
70
|
+
|
|
71
|
+
if (!!customSourceDetails?.repositoryUrl) repoDetails.repository = customSourceDetails.repositoryUrl;
|
|
72
|
+
if (!!customSourceDetails?.commitHash) repoDetails.commit = customSourceDetails.commitHash;
|
|
73
|
+
if (!!customSourceDetails?.commitTimestamp) repoDetails.timestamp = customSourceDetails.commitTimestamp;
|
|
57
74
|
|
|
58
75
|
return repoDetails;
|
|
59
76
|
}
|